DevDocsDev Docs
Software ArchitectureInfrastructure as Code

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

Why This Architecture?

High-Level Structure

package.json
turbo.json
pnpm-workspace.yaml

Quick Start Example

packages/core-sdk/src/index.ts
// 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';
apps/order-service/src/index.ts
// 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

DocumentDescription
Monorepo StructureTurborepo/Nx setup, workspace configuration, dependency management
SDK ModulesCreating internal packages, versioning, publishing strategies
Pipeline OrchestrationCI/CD workflows, change detection, cascading deployments
Deployment StrategiesKubernetes, serverless, hybrid deployments
Composable ArchitectureCombining 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

On this page