Modular Monolithic Architecture — Project Scaffolder
Generate production-ready Modular Monolith projects with proper module boundaries, internal APIs, shared kernel, and infrastructure following industry best practices.
Overview
A Modular Monolith is a single deployable application organized into loosely coupled, highly cohesive modules — each representing a bounded context. It combines monolithic simplicity (single deployment, ACID transactions, in-process calls) with microservices-style modularity (clear boundaries, team autonomy, independent development).
This skill scaffolds complete projects with:
- Module isolation: Each module owns its domain, data access, and API surface
- Inter-module communication: Via public contracts/interfaces, never internal details
- Shared kernel: Cross-cutting concerns (auth, logging, events) in a shared layer
- Database-per-module schema: Logical isolation within a single RDBMS
- Migration-ready boundaries: Modules can be extracted to microservices later
Workflow
Step 1: Gather Requirements
If the user hasn't specified, ask for:
- Language/Framework (e.g., C#/ASP.NET Core, Java/Spring Boot, TypeScript/NestJS, Python/Django, Go)
- Project name
- Business modules (e.g., Product, Order, Payment, Shipping, Notification)
- Database preference (PostgreSQL, MySQL, SQL Server, SQLite for dev)
- Additional features: Event bus, API gateway, Docker, CI/CD
If the user provides $ARGUMENTS, parse them: $ARGUMENTS[0] = language/framework, $ARGUMENTS[1] = project name, remaining = module names.
Step 2: Generate Project Structure
Read the architecture references for the chosen framework:
- For detailed structure patterns, see references/project-structures.md
- For module design patterns, see references/module-design.md
- For comparison and decision guide, see references/architecture-guide.md
- For event-driven patterns and event bus design, see references/event-driven-patterns.md
- For inter-module communication and contract versioning, see references/api-versioning-communication.md
- For concrete scaffold examples, see examples/dotnet-scaffold.md and examples/nestjs-scaffold.md
Generate the project following these critical rules:
Module Rules
- Each module gets its own directory with internal layers (Domain/Application/Infrastructure/API)
- Modules communicate ONLY through public contracts (interfaces/DTOs) — never reference another module's internal types
- Each module has its own database schema or migration folder
- Each module registers its own services/dependencies
- No circular dependencies between modules
Shared Kernel Rules
- Contains ONLY cross-cutting concerns: base entities, common value objects, event bus interfaces, auth abstractions
- Must be thin — if it grows large, something belongs in a module
- Never contains business logic specific to any module
Infrastructure Rules
- Single entry point (Program.cs / main.ts / main.py / main.go)
- Composition root wires all modules together
- Database context/session is shared but schemas are isolated
- Event bus for async inter-module communication (in-process, upgradeable to message broker)
Step 3: Generate Code
For each module, generate:
- Domain layer: Entities, value objects, domain events, repository interfaces
- Application layer: Use cases/commands/queries, DTOs, validation
- Infrastructure layer: Repository implementations, database configuration, migrations
- API layer: Controllers/handlers, request/response models, module registration
Also generate:
- Shared kernel: Base classes, event bus, common abstractions
- Host/entry point: Composition root, middleware, configuration
- Tests: Module unit tests, integration tests, contract tests, and architecture boundary tests — see references/testing-strategies.md
- Observability: Module-scoped logging, health checks, and tracing setup — see references/observability.md
- Docker (if requested): Dockerfile + docker-compose with database
- README.md: Architecture overview, how to run, how to add modules (use examples/README-template.md)
Step 4: Validate
After generation:
- Verify no module directly references another module's internal types
- Confirm each module has its own schema/migration folder
- Check that the shared kernel contains no business logic
- Ensure the project builds/compiles successfully
- Run any generated tests
Validation scripts are available in scripts/ for CI integration:
scripts/validate-boundaries.sh <modules-dir> — detects cross-module boundary violations
scripts/validate-shared-kernel.sh <shared-dir> <modules-dir> — ensures shared kernel doesn't reference modules
scripts/check-circular-deps.sh <modules-dir> — detects circular dependencies between modules
Step 5: Migration Guidance
If the user asks about extracting modules to microservices, see references/migration-to-microservices.md for a detailed step-by-step guide covering:
- When to extract (evidence-based signals)
- Pre-extraction checklist
- Creating the service, swapping the implementation, adding resilience
- Rollback strategy
Key Principles to Enforce
| Principle |
What It Means |
How to Enforce |
| High Cohesion |
Module contains everything for its domain |
Domain + Application + Infrastructure + API per module |
| Low Coupling |
Modules don't depend on each other's internals |
Communication only via shared contracts/interfaces |
| Single Responsibility |
Each module has one bounded context |
One business domain per module directory |
| Encapsulated Data |
Module owns its data |
Separate DB schema per module, no cross-module queries |
| Explicit Dependencies |
All module dependencies are visible |
Module registration file listing required contracts |
| Domain-Driven Design |
Modules align with business domains |
Named after business capabilities, not technical layers |
Example Invocations
/modular-monolith dotnet ECommerceApp Product Order Payment Shipping
/modular-monolith spring-boot MyShop catalog basket checkout
/modular-monolith nestjs SaasApp tenant billing notification
/modular-monolith go FinanceApp accounts transactions reporting
When NOT to Use This
Suggest microservices instead if the user describes:
- Teams needing completely independent deployment cadences
- Requirements for polyglot tech stacks (Python ML + Go APIs + Java enterprise)
- Extreme per-service scaling requirements
- Already having Kubernetes infrastructure and DevOps maturity
Suggest a simple monolith if:
- Solo developer or very small team (1-3 devs)
- Prototype/MVP with unclear domain boundaries
- Application with fewer than 3 distinct business domains
1---2name: modular-monolith-architecture3description: Scaffold and create a Modular Monolithic Architecture project. Use when the user wants to create a new modular monolith, restructure a monolith into modules, design module boundaries, or set up a project following modular monolith best practices. Supports multiple languages and frameworks.4---56# Modular Monolithic Architecture — Project Scaffolder78Generate production-ready Modular Monolith projects with proper module boundaries, internal APIs, shared kernel, and infrastructure following industry best practices.910## Overview1112A Modular Monolith is a single deployable application organized into loosely coupled, highly cohesive modules — each representing a bounded context. It combines monolithic simplicity (single deployment, ACID transactions, in-process calls) with microservices-style modularity (clear boundaries, team autonomy, independent development).1314This skill scaffolds complete projects with:15- **Module isolation**: Each module owns its domain, data access, and API surface16- **Inter-module communication**: Via public contracts/interfaces, never internal details17- **Shared kernel**: Cross-cutting concerns (auth, logging, events) in a shared layer18- **Database-per-module schema**: Logical isolation within a single RDBMS19- **Migration-ready boundaries**: Modules can be extracted to microservices later2021## Workflow2223### Step 1: Gather Requirements2425If the user hasn't specified, ask for:261. **Language/Framework** (e.g., C#/ASP.NET Core, Java/Spring Boot, TypeScript/NestJS, Python/Django, Go)272. **Project name**283. **Business modules** (e.g., Product, Order, Payment, Shipping, Notification)294. **Database** preference (PostgreSQL, MySQL, SQL Server, SQLite for dev)305. **Additional features**: Event bus, API gateway, Docker, CI/CD3132If the user provides `$ARGUMENTS`, parse them: `$ARGUMENTS[0]` = language/framework, `$ARGUMENTS[1]` = project name, remaining = module names.3334### Step 2: Generate Project Structure3536Read the architecture references for the chosen framework:37- For detailed structure patterns, see [references/project-structures.md](references/project-structures.md)38- For module design patterns, see [references/module-design.md](references/module-design.md)39- For comparison and decision guide, see [references/architecture-guide.md](references/architecture-guide.md)40- For event-driven patterns and event bus design, see [references/event-driven-patterns.md](references/event-driven-patterns.md)41- For inter-module communication and contract versioning, see [references/api-versioning-communication.md](references/api-versioning-communication.md)42- For concrete scaffold examples, see [examples/dotnet-scaffold.md](examples/dotnet-scaffold.md) and [examples/nestjs-scaffold.md](examples/nestjs-scaffold.md)4344Generate the project following these **critical rules**:4546#### Module Rules471. Each module gets its own directory with internal layers (Domain/Application/Infrastructure/API)482. Modules communicate ONLY through public contracts (interfaces/DTOs) — never reference another module's internal types493. Each module has its own database schema or migration folder504. Each module registers its own services/dependencies515. No circular dependencies between modules5253#### Shared Kernel Rules541. Contains ONLY cross-cutting concerns: base entities, common value objects, event bus interfaces, auth abstractions552. Must be thin — if it grows large, something belongs in a module563. Never contains business logic specific to any module5758#### Infrastructure Rules591. Single entry point (Program.cs / main.ts / main.py / main.go)602. Composition root wires all modules together613. Database context/session is shared but schemas are isolated624. Event bus for async inter-module communication (in-process, upgradeable to message broker)6364### Step 3: Generate Code6566For each module, generate:67- **Domain layer**: Entities, value objects, domain events, repository interfaces68- **Application layer**: Use cases/commands/queries, DTOs, validation69- **Infrastructure layer**: Repository implementations, database configuration, migrations70- **API layer**: Controllers/handlers, request/response models, module registration7172Also generate:73- **Shared kernel**: Base classes, event bus, common abstractions74- **Host/entry point**: Composition root, middleware, configuration75- **Tests**: Module unit tests, integration tests, contract tests, and architecture boundary tests — see [references/testing-strategies.md](references/testing-strategies.md)76- **Observability**: Module-scoped logging, health checks, and tracing setup — see [references/observability.md](references/observability.md)77- **Docker** (if requested): Dockerfile + docker-compose with database78- **README.md**: Architecture overview, how to run, how to add modules (use [examples/README-template.md](examples/README-template.md))7980### Step 4: Validate8182After generation:831. Verify no module directly references another module's internal types842. Confirm each module has its own schema/migration folder853. Check that the shared kernel contains no business logic864. Ensure the project builds/compiles successfully875. Run any generated tests8889Validation scripts are available in [scripts/](scripts/) for CI integration:90- `scripts/validate-boundaries.sh <modules-dir>` — detects cross-module boundary violations91- `scripts/validate-shared-kernel.sh <shared-dir> <modules-dir>` — ensures shared kernel doesn't reference modules92- `scripts/check-circular-deps.sh <modules-dir>` — detects circular dependencies between modules9394### Step 5: Migration Guidance9596If the user asks about extracting modules to microservices, see [references/migration-to-microservices.md](references/migration-to-microservices.md) for a detailed step-by-step guide covering:97- When to extract (evidence-based signals)98- Pre-extraction checklist99- Creating the service, swapping the implementation, adding resilience100- Rollback strategy101102## Key Principles to Enforce103104| Principle | What It Means | How to Enforce |105|-----------|---------------|----------------|106| High Cohesion | Module contains everything for its domain | Domain + Application + Infrastructure + API per module |107| Low Coupling | Modules don't depend on each other's internals | Communication only via shared contracts/interfaces |108| Single Responsibility | Each module has one bounded context | One business domain per module directory |109| Encapsulated Data | Module owns its data | Separate DB schema per module, no cross-module queries |110| Explicit Dependencies | All module dependencies are visible | Module registration file listing required contracts |111| Domain-Driven Design | Modules align with business domains | Named after business capabilities, not technical layers |112113## Example Invocations114115```116/modular-monolith dotnet ECommerceApp Product Order Payment Shipping117/modular-monolith spring-boot MyShop catalog basket checkout118/modular-monolith nestjs SaasApp tenant billing notification119/modular-monolith go FinanceApp accounts transactions reporting120```121122## When NOT to Use This123124Suggest microservices instead if the user describes:125- Teams needing completely independent deployment cadences126- Requirements for polyglot tech stacks (Python ML + Go APIs + Java enterprise)127- Extreme per-service scaling requirements128- Already having Kubernetes infrastructure and DevOps maturity129130Suggest a simple monolith if:131- Solo developer or very small team (1-3 devs)132- Prototype/MVP with unclear domain boundaries133- Application with fewer than 3 distinct business domains