Agents Playbook
Pillars/Architecture

Pillar — Architecture

How to keep a codebase **legible and modular under multi-agent development**.

Pillar — Architecture

How to keep a codebase legible and modular under multi-agent development.

The single biggest predictor of agent quality is whether the codebase tells the agent where to put new code. If the package boundaries are vague, agents pile features into the nearest big file. If the boundaries are explicit and named, agents route correctly even without supervision.

Documents in this pillar

DocLayerRead when
universal.mdStack-agnostic principlesDesigning any codebase
ts-concrete.mdTS / pnpm / Turbo recipesImplementing in a TS monorepo
adr-pattern.mdUniversal + TSRecording a decision
rfc-pattern.mdUniversal + TSProposing a breaking change
contracts-zod-pattern.mdTS-concreteDesigning JSON-RPC / HTTP / IPC boundaries
error-hierarchy.mdUniversal + TSDesigning the error model
file-size-budget.mdUniversal + TSEnforcing reviewability
anti-overengineering.mdUniversalResisting agent default-to-abstract
feature-flags-pattern.mdUniversal + TSDecoupling deploy from release
api-versioning-pattern.mdUniversalBreaking-change deprecation lifecycle
distributed-data-pattern.mdUniversalReplicas, sharding, CAP, eventual consistency
multi-region-pattern.mdUniversalGeo failover, sovereignty, RPO/RTO
event-streaming-pattern.mdUniversalQueues, pub/sub, streams; idempotency; DLQ; schema evolution
caching-cdn-pattern.mdUniversal3 cache tiers; TTL discipline; invalidation; key scoping
api-gateway-pattern.mdUniversalEdge ingress; what belongs vs not; BFF; GraphQL federation
service-mesh-pattern.mdUniversalSidecar mTLS; retries; observability; when to adopt vs not
platform-engineering-idp-pattern.mdUniversalInternal Developer Platform; golden paths; DORA metrics
iac-pattern.mdUniversalInfrastructure as code; modules; state; drift; cost forecast
offline-first-sync-pattern.mdUniversalLocal persistence; sync protocols; conflict resolution; CRDT

The core idea

A codebase has three architectural surfaces, and each one needs a different kind of documentation:

  1. Boundaries — what depends on what. Documented as a package routing table.
  2. Decisions — why the boundaries are where they are. Documented as ADRs.
  3. Contracts — what crosses boundaries. Documented as Zod (or equivalent) schemas, with stable error codes and versioning.

If any of the three is implicit, agents will reinvent it differently each session.

Anti-patterns this pillar prevents

  • Agents reimplementing upstream primitives because the routing table didn't say where they live.
  • Agents proposing breaking changes in a PR description instead of an RFC, so the change is invisible to future agents.
  • Agents throwing raw new Error('...') at a JSON-RPC boundary, making the error opaque in the client.
  • Files growing to 1500 lines because no budget said "extract".
  • Two agents creating sibling packages that re-export the same primitive under different names.

How to adopt

  1. Read universal.md. Internalize the five non-negotiables.
  2. Write your project's AGENTS.md routing table (template in ../../templates/AGENTS.md.template.md).
  3. Stand up ADR + RFC directories (templates in ../../templates/). Number the first ADR "Philosophy".
  4. Wire structural gates from ../../scripts/ — the file-size, named-export, and no-any gates pay back in week one.
  5. Add an ADR every time an agent proposes a structural change. Reject the change if there is no ADR.