Which architecture lets a coding agent read less, run everything and break fewer contracts: monolith, modular monolith, microservices in a monorepo, microservices across repositories, or services in one Encore app.

For AI coding agents, start with a monolith or modular monolith, and use services only when they share one repository, call each other through typed clients and run together locally. Encore is built around that setup.
Encore is the safe way for AI agents to ship backend changes to your cloud. Services with typed calls live in one app, encore run starts them all with their infrastructure, and each environment deploys them as one process or as separate services.
Verdict: an agent does its best work when it can read the code it changes, get a type error when it breaks a contract and run the whole system before anything ships. A plain or modular monolith gives you that for free at small and medium size. Encore keeps it once you have services, and it adds per-pull-request previews and infrastructure approval on the way to your own cloud. Separate repositories give agents the least to work with.
A coding agent reads the files it thinks are relevant, edits them, runs a check and reads the result, all inside a context window of fixed size. Anthropic's engineering team calls context a finite resource with diminishing returns, and Chroma's context rot report found that models get less reliable as input grows, even on simple tasks.
Architecture decides how much the agent has to read for a change and whether it can run what it changed. The general trade-offs are in monolith vs microservices. For agents, four questions decide most of it:
An Encore app is one repository where every directory with a service definition is a service. Each service declares its own databases, Pub/Sub topics and buckets in code, and calls between services look like function calls that Encore turns into network calls. When an agent changes the orders service and the billing service in one task, it can start both with encore run, call the endpoint and watch the request cross the boundary.
In TypeScript, a service is a directory with an encore.service.ts file:
// billing/encore.service.ts
import { Service } from "encore.dev/service";
export default new Service("billing");
The billing endpoint has typed request and response shapes, and that type is the contract other services compile against:
// billing/billing.ts
import { api } from "encore.dev/api";
interface ChargeRequest {
orderId: string;
amountCents: number;
}
interface ChargeResponse {
chargeId: string;
}
export const charge = api(
{ method: "POST", path: "/billing/charge" },
async (req: ChargeRequest): Promise<ChargeResponse> => {
return { chargeId: `ch_${req.orderId}` };
},
);
The orders service calls it through the generated client in ~encore/clients. If the agent renames a field in ChargeRequest, the orders service stops type-checking, so the mistake surfaces in the editor and not as a failed request in staging:
// orders/orders.ts
import { api } from "encore.dev/api";
import { billing } from "~encore/clients";
export const checkout = api(
{ expose: true, method: "POST", path: "/orders/:id/checkout" },
async ({ id }: { id: string }): Promise<{ chargeId: string }> => {
const { chargeId } = await billing.charge({ orderId: id, amountCents: 4200 });
return { chargeId };
},
);
Encore learns every service and every call between them from static analysis. The local development dashboard shows a service catalog and distributed traces, and the local MCP server hands the same metadata and traces to the agent, so it can check which services a request touched.
Whether that ships as one process or many is an environment setting. Each environment runs the services either in a single process, which is simpler and cheaper, or as separate processes that scale on their own, and you can pick differently for production and development without changing code. The same page lets you require that infrastructure changes are approved before a deploy goes ahead, which is a useful brake when an agent adds a database or a topic. Each pull request also gets a preview environment hosted by Encore, so the change runs on real infrastructure before review.

Moving from a monolith to services in production is a path Encore customers have taken, for example Bookshop.org's move from Rails monolith to Go microservices with Encore.
encore run starts every service locally with its databases, topics and buckets.Splitting a service means moving code into a new directory with its own service definition, and the typed clients point out every call site that breaks. Service clients cannot be passed around freely, because Encore finds the calls through static analysis. The .ref() method on a client covers those cases.
For a new or mid-sized app, a single codebase running as one process is the easiest place for an agent to work. Every caller of a function is one search away, and one build checks a refactor.
It gets harder as the codebase grows: the agent has more to search, and unrelated code competes for its context. Claude Code's documentation notes that specific and concise instructions are followed more consistently, and CLAUDE.md files in subdirectories load only when the agent works there, so splitting instructions per directory buys a lot of headroom.
A modular monolith keeps one process and adds boundaries the build checks. The agent gets smaller areas to reason about, with no network in between. In Python, import-linter turns a boundary into a contract that fails CI when one module reaches into another's internals:
[importlinter]
root_package = shop
[importlinter:contract:billing-boundary]
name = Orders only uses the billing public API
type = forbidden
source_modules =
shop.orders
forbidden_modules =
shop.billing.internal
The boundaries only hold if something checks them, so put the contract file and the command that runs it in AGENTS.md. Microservices vs modular monolith covers how to keep the boundaries from eroding.
With every service in one repository, the agent can search the whole system, and a Docker Compose file starts the services and their dependencies together:
# compose.yaml
services:
orders:
build: ./orders
environment:
BILLING_URL: http://billing:8080
DATABASE_URL: postgres://postgres:postgres@orders-db:5432/orders
depends_on: [billing, orders-db]
billing:
build: ./billing
orders-db:
image: postgres:17
environment:
POSTGRES_PASSWORD: postgres
POSTGRES_DB: orders
The Compose file is a second description of the system, and it drifts from the code. Every new service or database means editing it, and the HTTP contract between services is only typed if the team generates clients from a schema. Tracing a request across services locally needs OpenTelemetry wired into each one.
One repository per service gives teams full independence, and it is the hardest setup for an agent. The other services are visible only through their API documentation, a contract change means coordinated pull requests in several repositories, and running the full system usually means deploying to a shared environment.
Claude Code can run subagents, each in its own context window, which helps split the work. Each one still needs access to the code it changes and a way to run it.
Start with a monolith or a modular monolith. The agent can search all the code, a refactor is checked by one build, and the app runs with one command. Move to services when parts of the system need to deploy or scale on their own, and keep them in one repository with typed calls and a way to run all of them locally, so the agent can still test a change that crosses a service boundary.
Yes. Keep the modules behind small typed interfaces from the start and enforce the boundaries in CI, so the code that moves into a service already talks to the rest through one interface. Extract one module at a time, keep it in the same repository, and replace the in-process calls with typed client calls.
Yes. Past a certain size, the agent has more to read than it can hold well: agents work inside a finite context window, and Chroma's 2025 context rot report found that model output becomes less reliable as input length grows. Clear module or service boundaries help, because the agent can change one part while reading only the typed interfaces of the others.
Every service lives in one Encore app, and calls between services go through generated typed clients, so a broken contract is a type error before anything runs. encore run starts all services locally with their databases and Pub/Sub topics, and the local MCP server gives the agent the traces. Each pull request gets a preview environment hosted by Encore, an environment can require approval of infrastructure changes before a deploy, and each environment runs the services as one process or as separate processes in your own AWS or GCP account.
Give your AI coding agent real local and cloud infrastructure
Encore lets developers and agents declare databases, queues, and APIs in type-safe code—then auto-provisions real local environments, MCP introspection, and AWS/GCP deploys.