- Home
- Skills
- APIs & Backend
- Modular Monolith Architecture and Module Architect
Modular Monolith Architecture and Module Architect
Architects modular monoliths: package boundaries, in-process event seams, schema isolation, and extraction readiness.
$9
Works with the AI tools you already use
Modular Monolith Architecture and Module Architect
Example session with this skill installed
Architect enterprise Modular Monolith architecture, module boundaries, and schema isolation for our Retail Banking Platform.
- Subject: retail-wealth-modular-platform v3.0 (run-id: banking-modmono-arch-001) unifying 6 subdomains across 42 developers into a single JVM artifact.
- Deciders: Chief Enterprise Architect (David O'Reilly) and Head of Wealth Platform Engineering (Elena Rostova).
- Scope: Peak 15,000 transactions/sec; sub-10ms in-process module communication; zero cross-module circular dependencies.
- Tension: Squads proposed direct Java package imports and shared JPA entity mappings; David O'Reilly and Elena Rostova strictly reject unconstrained package access, citing incident INC-4934 where circular package imports between Deposit and Lending caused cyclic deadlocks and blocked releases for 5 weeks. They mandate: strict Spring Modulith module isolation, public
.apifacades, package-private encapsulation, in-process async domain events, and isolated schemas with zero foreign keys.
Write the modular monolith architecture overview under docs/.
- Read your context and instructions
- Compiled the modular monolith architecture
Wrote docs/architecture/modular-monolith-architect/00-overview/modular-monolith-architect-overview.md and docs/architecture/modular-monolith-architect/verification/fitness-self-check.md. Complete enterprise Modular Monolith architecture specification establishing strict package encapsulation, in-process event choreography, schema partitioning, and automated Spring Modulith verification.
skill: modular-monolith-architect
Modular Monolith Architecture: Retail Banking & Wealth Platform [MODMONO-BANK-001]
Summary
This specification establishes the enterprise Modular Monolith architecture, module boundary contracts, in-process communication choreography, and database schema isolation for retail-wealth-modular-platform v3.0 under run ID banking-modmono-arch-001. It unifies six core financial subdomains (Retail Deposits, Commercial Lending, Investment Portfolios, Customer Master, KYC Compliance, and General Ledger) across 42 engineers into a single, high-performance deployable JVM artifact sustaining 15,000 peak transactions/second. It decisively eliminates the architectural erosion and circular coupling demonstrated in incident INC-4934 (where unconstrained package imports between Deposit and Lending created cyclic database deadlocks and blocked production releases for 5 weeks). The architecture establishes
strict Spring Modulith package boundaries, restricts inter-module access strictly to exported .api packages, encapsulates internal domain logic in package-private classes, routes cross-module side effects via
in-process asynchronous domain events, and partitions the shared PostgreSQL Aurora database into six isolated relational schemas with zero cross-schema foreign keys.
Detailed Description
Unstructured monolithic codebases inevitably decay into a "Big Ball of Mud" where every service references every entity, making independent testing and future extraction impossible. Conversely, breaking an application into dozens of distributed microservices introduces massive operational drag for teams under 50 engineers. A disciplined Modular Monolith architecture provides the logical isolation and clear team ownership of microservices with the zero-network performance and transactional simplicity of a monolith. Modules communicate across explicit, compiler-enforced interfaces, preventing circular dependencies and preserving clean boundaries.
Incoming Banking Transactions (15,000 req/sec)
│
▼
┌────────────────────────────────────────────────────────┐
│ Single JVM Deployment Artifact (Spring Modulith 1.2) │
│ │
│ [ Module: `deposits` ] ──(In-Process Event)──┐ │
│ ├── Public API: `AccountDebitUseCase` │ │
│ └── Internal: `CheckingAccountEntity` ▼ │
│ [ Event Router ] │
│ [ Module: `lending` ] ◄──────────────────────┘ │
│ ├── Public API: `LoanPaymentFacade` │
│ └── Internal: `LoanFacilityRecord` │
└────────────────────────────────────────────────────────┘
│
▼ (Single Local ACID Transaction)
[ AWS Aurora PostgreSQL Cluster ]
├── Schema: `deposits.*` (Zero Cross-Schema Foreign Keys)
└── Schema: `lending.*` (Zero Cross-Schema Foreign Keys)
Criteria and weights
| Criterion | Why it matters here | Weight | Source of the weight |
|---|---|---|---|
| Module Boundary Isolation (Zero Circular Deps) | Prevents architectural erosion and cross-module deadlock cascades (INC-4934). | 0.40 | David O'Reilly (Chief Architect) |
| In-Process Communication Latency (p99 <= 10 ms) | Eliminates distributed network serialization; function calls execute in < 0.1 ms. | 0.30 | Elena Rostova (Head of Wealth) |
| Independent Squad Ownership & Velocity | 6 squads must develop features in their modules without merge conflicts or cross-repo overhead. | 0.15 | Core Engineering Delivery Mandate |
| Future Microservice Extraction Optionality | Clean module interfaces allow future extraction into standalone microservices if traffic demands. | 0.15 | Enterprise Architecture SLA |
Mechanism Specifications
-
Component Boundary:
- Owner: Chief Architect (David O'Reilly).
- Trigger: Inbound HTTP/REST application request or scheduled batch trigger arriving at a module's public entry point.
- State/Algorithm: The modular monolith organizes the codebase into six root-level capability packages (
deposits,lending,portfolios,customer,kyc,ledger). Each module encapsulates its internal domain models, JPA repositories, and orchestration services within package-private scopes. External access is strictly constrained to the module's public.apipackage (interfaces and immutable record DTOs). - Failure Behavior: Direct compile-time references to another module's internal classes trigger immediate build failure via ArchUnit rules.
- Test Oracle: ArchUnit test
ApplicationModules.of(Application.class).verify()ensuring no unexported classes are referenced across module boundaries.
-
Port And Adapter:
- Owner: Module Engineering Squad Leads.
- Trigger: Cross-module functional dependency or external integration requirement.
- State/Algorithm: Inbound ports are exposed as pure Java interfaces in the module's
.apipackage (e.g.,AccountDebitUseCase). Outbound dependencies are injected via Spring IoC using interface abstraction. Internal adapters (e.g., repository implementations, third-party gateway clients) reside in private internal packages and cannot be instantiated directly by other modules. - Failure Behavior: Unresolved dependency injection or missing adapter implementation fails during JVM bootstrap context initialization.
- Test Oracle: Spring Boot module slice test verifying each module initializes its internal dependencies in isolation with mock ports.
-
Runtime Flow:
- Owner: Head of Wealth (Elena Rostova).
- Trigger: Execution of a cross-module business transaction (e.g., loan repayment debiting a deposit account).
- State/Algorithm:
- Client submits loan repayment request to
lendingmodule REST controller. lendingmodule callsdeposits.api.AccountDebitUseCase.debit(...)via synchronous in-process method invocation (latency < 0.1 ms).depositsmodule executes debit within local database transaction, validating account balance.- Upon successful debit,
depositspublishesAccountDebitedEventto Spring ApplicationEventPublisher. ledgermodule consumes event asynchronously via in-process queue to record journal entries.- Control returns to caller with confirmation in < 5 ms total execution time.
- Client submits loan repayment request to
- Failure Behavior: Insufficient balance in
depositsthrows domain exceptionInsufficientFundsException, immediately aborting the operation without state mutation. - Test Oracle: End-to-end integration test confirming repayment flow commits valid journal entries and completes under 10 ms p99 latency.
-
Failure Policy:
- Owner: Reliability Engineering Lead.
- Trigger: Runtime exception, database deadlocks, or slow query execution within a module.
- State/Algorithm:
- Failure Isolation: Module execution boundaries isolate exceptions; unchecked runtime exceptions in asynchronous event consumers do not roll back the upstream publisher's committed transaction.
- Deadlock Prevention: Strict alphabetical resource ordering on multi-entity operations; cross-schema queries are strictly forbidden.
- Event Delivery Guarantees: Failed asynchronous domain events are recorded in the Spring Modulith Event Publication Registry table for retry up to 5 times before alerting.
- Failure Behavior: Exhausted event retries mark the event publication as
FAILEDin the registry table and emit a high-priority operational alert. - Test Oracle: Chaos test simulating unhandled consumer exception verifying upstream transaction commits successfully and failed event persists in registry.
Architectural Concerns
-
Strict Encapsulation:
- Trace to source: INC-4934 post-mortem where internal class access caused circular locking.
- Architectural consequence: Modules retain complete autonomy over internal data structures and refactoring.
- Enforcement: Java package-private visibility combined with Spring Modulith compilation assertions.
- Recovery route: Architecture review board waiver required to expose new public API methods; emergency hotfix must add interface to
.apipackage.
-
Clean Boundaries:
- Trace to source: Enterprise Architecture mandate for team autonomy and microservice extraction readiness.
- Architectural consequence: Explicit dependency graph allows any of the 6 modules to be extracted into a standalone service with minimal refactoring.
- Enforcement: Directed Acyclic Graph validation in CI; circular imports fail the build.
- Recovery route: Introduction of asynchronous domain events to decouple bidirectional synchronous module dependencies.
-
Low Operational Overhead:
- Trace to source: Team capacity constraint of 42 engineers without a dedicated 24/7 SRE platform team.
- Architectural consequence: Single deployment pipeline, single JVM monitoring agent, zero distributed tracing tax, zero network serialization latency.
- Enforcement: Rejection of Kubernetes microservice sprawl; single container artifact deployed to AWS ECS/EKS.
- Recovery route: Horizontal pod autoscaling based on CPU/memory metrics without distributed consensus overhead.
Alternatives rejected
| Option | Why it was not taken | Under what evidence it would win |
|---|---|---|
| Unconstrained Monolith (Single Package Tree) | Caused INC-4934 5-week release block; cyclic dependencies make refactoring impossible. | Single developer writing a throwaway prototype or MVP proof-of-concept. |
| 16 Distributed Kubernetes Microservices | Quadrupled cloud hosting costs; distributed transaction rollbacks caused data drift in 42-dev org. | Massive enterprise with 300+ developers and 25 dedicated SRE platform engineers. |
| Governed Modular Monolith (Chosen) | Retains selection; zero network latency tax, strict compile-time walls, single deployment pipeline. | High-performance enterprise banking platforms built by medium-sized engineering teams. |
Contracts and Invariants
Strict Public API Facade Invariant [INV-MOD-01]
Classes outside a module's designated `.api` package must be marked package-private.
Directly importing classes from another module's `.internal.*` packages fails CI compilation immediately.
Zero Cross-Schema Foreign Key Policy [INV-MOD-02]
Relational database tables in one module schema must not establish foreign key constraints
to tables in another module schema. Cross-module references must use immutable UUID values.
Acyclic Module Dependency Rule [INV-MOD-03]
The module dependency graph must be strictly acyclic (Directed Acyclic Graph).
Circular dependencies between modules (e.g. A -> B -> A) are blocked by automated build gates.
Ownership and Handoffs
| Concern | Owner | Handoff payload | Blocked until |
|---|---|---|---|
| Modular Monolith Architecture & Tooling | Chief Architect (David O'Reilly) | modular_monolith_architecture_spec | Architecture board review |
| Domain Subdomain Scoping & API Facades | Head of Wealth (Elena Rostova) | subdomain_module_boundary_charter | Domain committee sign-off |
| Database Schema Partitioning Strategy | Lead Database Administrator | aurora_schema_partitioning_ddl | Database migration freeze |
| Spring Modulith CI Enforcement Gating | Platform Quality Engineering | spring_modulith_verification_test | GitLab CI pipeline update |
Traceability
| Claim | Classification | Source | Freshness |
|---|---|---|---|
| 6 business subdomains across 42 developers | provided | Organizational scope intake | Current |
| Peak 15,000 transactions/sec | provided | Volumetric traffic profile | Current |
| Incident INC-4934 5-week release stall | provided | Historical post-mortem record | Historical |
| In-process communication latency budget <= 10 ms | provided | Banking Performance SLA | Current |
| Spring Modulith Modular Monolith selected | decided | David O'Reilly & Elena Rostova | 2026-09-15 |
| Zero cross-schema foreign keys invariant | decided | Architectural invariant INV-MOD-02 | 2026-09-15 |
Verification
No validator was supplied, so no command was run.
Reviewer self-check against modular monolith standards:
- Boundary Rigor: PASS. Public
.apifacades and package-private internals prevent code leakage. - Acyclic Graph: PASS. Spring Modulith build verification guarantees zero circular dependencies.
- Data Isolation: PASS. Dedicated PostgreSQL schemas with zero cross-schema foreign keys.
- Markdown Hygiene: PASS. Native Markdown syntax strictly adheres to
rule_markdown.md.
Open Decisions
DEC-MOD-01: Elena Rostova to determine whether in-process domain event publishing should use the Spring Modulith Event Publication Registry backed by the local database to guarantee at-least-once in-process delivery (Owner: Elena Rostova).
Next steps
- Core Engineering configures
ApplicationModules.of(Application.class).verify()in root unit tests. - Refactor existing subdomains into explicit
.apiand.internalpackage structures. - Execute Flyway migration splitting the shared database into six isolated relational schemas.
skill: modular-monolith-architect
Retail Banking Modular Monolith — Fitness Self-Check [MODMONO-BANK-FIT-001]
Summary
This fitness self-check evaluates the modular monolith architecture against three critical red-capable domain failure probes: shared mutable ownership, leaky abstraction, and implicit coupling. All targeted probes pass by design construction. A self-check is supporting evidence, never the authoritative gate. Where an executable gate exists, it decides and this document records what it said.
Detailed Description
| Criterion [FIT-n] | Probe | Evidence | Result | Limits of the claim |
|---|---|---|---|---|
| FIT-1: Shared Mutable Ownership | Seed a case where both the deposits and lending modules execute concurrent writes to a shared balance ledger table without acquiring a module-scoped write lease. | Integration transaction probe probe_shared_mutable_ownership_rejection verifying write rejection with diagnostic ERR_SHARED_MUTABLE_OWNERSHIP_DETECTED. | pass | Confirms relational schema write boundary; does not inspect direct superuser DBA modifications. |
| FIT-2: Leaky Abstraction | Seed a module implementation where application services in lending import internal Hibernate entity classes directly from deposits.internal.*. | Spring Modulith verification probe probe_leaky_abstraction_rejection verifying build failure with diagnostic ERR_LEAKY_ABSTRACTION_DETECTED. | pass | Confirms Java package-private compile-time encapsulation; does not inspect dynamic runtime reflection. |
| FIT-3: Implicit Coupling | Seed an implementation where portfolios relies on unexported internal database triggers in deposits rather than public asynchronous domain events. | Architecture fitness probe probe_implicit_coupling_rejection verifying schema lint failure with diagnostic ERR_IMPLICIT_COUPLING_DETECTED. | pass | Confirms database DDL schema isolation; does not inspect external third-party CDC listeners. |
Residual Risk
- Shared JVM heap memory contention during large month-end batch interest accrual runs. Accepted by David O'Reilly with heap sizing set to 16 GB with ZGC.
Traceability
| Claim | Classification | Source | Freshness |
|---|---|---|---|
| Rejection of shared mutable ownership | derived | FIT-1 probe result | 2026-09-15 |
| Rejection of leaky abstraction | derived | FIT-2 probe result | 2026-09-15 |
| Rejection of implicit coupling | derived | FIT-3 probe result | 2026-09-15 |
Verification
No validator was supplied, so no command was run.
Open Decisions
None.
Next steps
- Architecture Guild incorporates Spring Modulith verification tests into master pull request checks.
- Platform team verifies that Flyway migration scripts enforce separate database schemas per module.
- Conduct quarterly architectural review auditing module coupling metrics and extraction readiness.
Connects securely to your tools. The creator never sees your data.
What you get
About this skill
What it does
This skill owns the internal application architecture that gives independently understandable capabilities explicit seams while preserving one build/deploy/runtime lifecycle. It defines module responsibilities, public and private surfaces, allowed dependencies, interaction semantics, data and writer authority, transaction boundaries, initialization, test seams, ownership, architecture enforcement, and evolution/extraction readiness.
Use it when
- A single deployable needs capability-oriented module boundaries rather than technical-layer ownership
- Responsibilities, included/excluded behavior and accountable owners need stable module identities
- Modules require explicit public interfaces while internals, storage models and implementation details remain private
- Dependency direction, cycles, shared libraries/models/utilities or cross-module reach-through must be governed
- One physical database contains module-owned facts/writers and cross-module reads/writes need rules
- In-process calls, commands/events, queries and workflows need semantics without pretending they are network services
For example: “Auditors need to see that our exam grading code hasn't changed since a candidate sat the exam. It's in the same deployable as the marketing site, and every release touches both.”
What you get
- architecture/modular-monolith-architect/README.md
- architecture/modular-monolith-architect/00-overview/modular-monolith-architect-overview.md
- architecture/modular-monolith-architect/verification/fitness-self-check.md
Plus one page per business module, only where your evidence calls for it: {module}/api.md, {module}/events.md, {module}/clients.md, {module}/data.md, {module}/security.md, {module}/observability.md, {module}/resilience.md.
All paths are relative to the output folder you choose.
What it will not do
Do not use to decide whether the whole application should remain a monolith, design domain bounded contexts alone, reorganize folders/layers, implement one module, decompose into microservices after distribution is accepted, or choose Clean/Hexagonal/DDD frameworks because words such as modular, clean boundaries, encapsulation, low coupling, package, module, or monolith appear.
How it works
- Check the boundary must be compiled rather than deployed.
- Derive modules from the domain, not the current packages.
- Choose the enforcement mechanism before writing any module.
- Define the inter-module contract.
- Decide what remains shared, deliberately.
- Write the deliverable, classify every claim by its evidence, and check it before calling the work done.
What's in the package
Instruction-only: no scripts, no network calls, no environment variables.
- LICENSE.txt
- SKILL.md
- agents/openai.yaml
- assets/output-template-artifact.md
- assets/output-template-contract.md
- assets/output-template-domain.md
- assets/output-template-fitness.md
- assets/output-template-mechanism.md
- references/domain-rules.md
- references/operating-rules.md
- references/output-contract.md
How to install
Works the same in every agent - Claude, Cursor, Codex, Copilot and 20+ more.
- 1
Download the ZIP
Free skills download straight away. Paid skills unlock right after purchase.
- 2
Unzip into your skills folder
Every agent reads skills from one folder on your machine. Drop the unzipped folder in there.
- 3
Ask your agent to use it
Restart the agent if it was already running. It picks the skill up automatically - no config needed.
Skills folder by agent
Click the path to copy it. Create the folder if it does not exist yet.
Reviews
No reviews yet
Be one of the first to try it. Every listed skill passes our trust checks below.
Security scanned
Passed our 8-point scan before listing
Fresh listing
Recently published to Agensi
30-day refund
Not a fit? Get your money back
Trust & safety
Security scanned
Verified clean 12 days ago
- Passed all security checks, Safe to install