Skip to content

cloud-adapters — Architecture

The @mnemose/cloud-adapters package defines typed port interfaces for all cloud provider operations and provides the GCP v1 implementation. No service imports the GCP SDK directly — all cloud calls go through these adapters.

Design

Mnemose uses the Ports and Adapters (Hexagonal Architecture) pattern for cloud operations:

  • Ports — TypeScript interfaces in src/ports/ describing what the platform needs from a cloud provider (IAM, resource management, storage, KMS, etc.)
  • Adapters — Implementations in src/gcp/ that satisfy those ports using the Google Cloud Node.js SDK

This separation means:

  1. The domain and command handlers are cloud-agnostic — they depend only on port interfaces
  2. A new cloud provider (AWS, Azure) can be added by implementing the ports without touching command handlers
  3. Unit tests mock the ports; no real cloud credentials needed

Port Interfaces

PortDescription
IamPortRole binding management, IAM policy get/set
ResourcePortCompute, storage, network resource inventory and provisioning
StoragePortObject storage read/write/sign operations
KmsPortKey management (create, rotate, destroy key versions)
MonitoringPortMetrics query and alert policy management
SecurityPortSecurity findings read and mute operations

GCP Implementation

src/gcp/ contains the GCP v1 adapters using @google-cloud/iam, @google-cloud/compute, @google-cloud/storage, @google-cloud/kms, and @google-cloud/monitoring.

The createGcpPlatform(config) factory wires all adapters into a single CloudPlatform object that is injected into the gateway Context per request.

Local Dev

resolveLocalInfraConfig() reads MNEMOSE_INFRA_CONFIG (a JSON blob written by the bootstrap script) to configure the adapters for the local emulator stack.