CLAUDE-MD · context-engineering
CLAUDE.md section: architecture map
A module index, boundary rules, and where-things-go table for a hexagonal/vertical-slice Java monorepo: the section that stops agents exploring and guessing.
✓ verified 2026-06-10 · stack: claude-code, java, aws · source
The architecture section for a root CLAUDE.md in a Java service monorepo structured as vertical slices with hexagonal internals (the reasoning is the context-friendly repos pattern). It answers the three questions an agent otherwise spends tokens exploring: what modules exist, what boundaries hold, and where a given kind of change goes. It is a section, not a whole file. The full root-file shape, with commit conventions and per-module delegation, is the monorepo root template; this slots in as its architecture content.
## Architecture
Hexagonal (ports and adapters) inside vertical feature slices. Everyservice follows the same internal layout:
- domain/ — pure Java. No framework or AWS imports.- application/ — use cases. Orchestrates domain; no infrastructure imports.- adapter/in/ — inbound: REST controllers, SQS listeners.- adapter/out/ — outbound: JPA repositories, AWS SDK clients, HTTP clients.
## Module map
- order-service/ Order lifecycle | Spring Boot, PostgreSQL (RDS) | :8080- payment-service/ Payment processing | Spring Boot, Stripe adapter | :8081- notification-service/ Event notifications | Spring Boot, SQS consumer | :8082- shared-domain/ Value objects, events | plain Java, no frameworks | —
Each service has its own CLAUDE.md with commands and conventions; read itbefore working there.
## Where things go
- New REST endpoint → <service>/adapter/in/, calling an application use case- New business rule → <service>/domain/ — never in a controller or adapter- New AWS integration → <service>/adapter/out/, client from shared-domain AwsClients- Cross-service contract → an event in shared-domain/ — never import another service's packages- New technology or pattern → ADR first, in <service>/docs/decisions/ (structured MADR)
## Boundaries (ArchUnit-enforced — fix violations, never suppress)
- Adapters call use cases, never repositories directly- domain/ imports nothing from application/ or adapter/- No service imports another service's packages- AWS SDK v2 only; no SDK client construction outside adapter/out/What it does
- Replaces exploration with a lookup. The Claude Code best-practices docs identify the context window as the most important resource to manage and recommend domain-oriented organisation; a few hundred tokens of map saves an agent re-deriving the structure every session.
- Makes placement decisions deterministic. The where-things-go table turns “where should this class live?” (the question agents get wrong most expensively) into a lookup, including the ADR-first rule for decisions that deserve a record (drafted with the ADR author command).
- Points at enforcement instead of pleading. Boundaries are stated as ArchUnit-owned facts, so the agent fixes the failing test rather than negotiating with prose. The prose is the index; the tests are the law.
- Stays within the budget. Roughly 40 lines, in keeping with the best-practices warning that overlong files get ignored: every line here changes a placement or boundary decision.
Failure modes
- The map rots. A renamed module or a new slice not reflected here is
worse than no map: the agent follows stale descriptions confidently. Make
updating it part of the definition of done for adding a module, and put
CLAUDE.mdbehind CODEOWNERS review. - Prose and enforcement drift apart. If an ArchUnit rule changes and this section does not (or vice versa), the agent receives contradictory signals. Treat the boundary list as a mirror of the test class, and review them together.
- It is advisory. Like all CLAUDE.md content this is prompt-space: high compliance, not guaranteed. The boundaries hold because ArchUnit fails the build, and path-level protections belong in hooks. See the deterministic policy pillar.
- It tempts detail creep. Port numbers and tech stacks belong here; build commands, test conventions, and per-service judgment calls belong in the module’s own CLAUDE.md, or the file outgrows the discipline that makes it work.
Verified against the Claude Code best-practices guidance on context-window management, domain-oriented organisation, and CLAUDE.md sizing, fetched 2026-06-10.