Infrastructure as Code
Modular monorepo architecture combining microservices, CQRS, event sourcing, and serverless patterns with shared SDKs and orchestrated CI/CD pipelines.
Infrastructure as Code
Infrastructure as Code (IaC) Monorepo Architecture combines all architectural patterns (microservices, CQRS, event sourcing, serverless, hexagonal) into a unified, modular codebase. Services share common SDKs published as npm packages, with CI/CD pipelines that orchestrate deployments across the entire organization.
This architecture enables teams to deploy services independently while sharing core business logic through internal SDKs, ensuring consistency and reducing duplication across the organization.
Architecture Overview
Core Principles
Shared SDKs
Internal npm packages for business logic, types, and utilities shared across all services
Monorepo Structure
Turborepo/Nx workspace with apps, packages, and infrastructure in one repository
Pipeline Orchestration
CI/CD pipelines that detect changes and trigger dependent deployments
Composable Deployments
Deploy as microservices, serverless, or combined based on requirements
Why This Architecture?
High-Level Structure
Quick Start Example
// Core SDK - shared business logic
export * from './domain/entities';
export * from './domain/value-objects';
export * from './domain/events';
export * from './application/use-cases';
export * from './ports/repositories';
export * from './ports/services';// Order service using shared SDKs
import { Order, OrderCreated, CreateOrderUseCase } from '@org/core-sdk';
import { EventBus, PostgresEventStore } from '@org/events-sdk';
import { createDatabase, OrderRepository } from '@org/database-sdk';
import { verifyToken, requireRole } from '@org/auth-sdk';
// Compose the service using SDK modules
const eventStore = new PostgresEventStore(config.database);
const eventBus = new EventBus(config.rabbitmq);
const orderRepo = new OrderRepository(createDatabase(config.database));
const createOrder = CreateOrderUseCase({
orderRepository: orderRepo,
eventBus,
eventStore,
});
// API routes
app.post('/orders', verifyToken, requireRole('user'), async (c) => {
const result = await createOrder.execute(c.req.json());
return c.json(result, 201);
});Documentation Structure
| Document | Description |
|---|---|
| Monorepo Structure | Turborepo/Nx setup, workspace configuration, dependency management |
| SDK Modules | Creating internal packages, versioning, publishing strategies |
| Pipeline Orchestration | CI/CD workflows, change detection, cascading deployments |
| Deployment Strategies | Kubernetes, serverless, hybrid deployments |
| Composable Architecture | Combining CQRS, event sourcing, microservices patterns |
When to Use This Architecture
✅ Good Fit
- Multiple services sharing business logic
- Teams that need deployment flexibility
- Organizations with many repositories to consolidate
- Projects requiring infrastructure versioning
- Need for atomic cross-service changes
❌ Poor Fit
- Single small application
- Teams unfamiliar with monorepo tooling
- Strict service isolation requirements
- Very different tech stacks across services
- Limited CI/CD infrastructure
Related Patterns
- Microservices - Service decomposition patterns
- CQRS - Command/Query separation in SDKs
- Event Sourcing - Event store SDKs
- Hexagonal - Ports and adapters in SDK design