How to Add Architecture Notes to CLAUDE.md

You’ve told Claude your tech stack and coding standards. But it keeps suggesting things that are technically correct and stylistically right — yet completely wrong for your architecture. It suggests calling the database from a component when you have a strict service layer. It suggests adding caching in a place your team decided never to cache. It recommends a pattern you explicitly moved away from six months ago.

Architecture notes fix this. They give Claude the why behind your codebase design, not just the what. When Claude understands how your system is structured and why, it stops suggesting things that fight your architecture.

📋 TL;DR
– Architecture notes explain how your system is structured and why you made those decisions
– They prevent Claude from suggesting valid-but-wrong solutions that break your design
– Focus on: data flow, layer separation, key patterns, and explicit “we decided against X” notes
– Plain English works — you don’t need diagrams or technical jargon
– Four to eight paragraphs is usually the right length

This is part of our complete CLAUDE.md — The Complete Beginner’s Guide (2026). If you haven’t built out your other CLAUDE.md sections yet, see What to Put in Your CLAUDE.md (With Real Examples) first.


What Architecture Notes Are (And Aren’t)

Architecture notes are: Plain English explanations of how your system is structured, what the key layers and components are, how data flows through the system, and which patterns you deliberately chose (or deliberately rejected).

Architecture notes are not: UML diagrams, system design documents, or exhaustive technical specs. You’re writing for Claude, not for a tech review board. A few paragraphs of clear prose is more useful than a 20-page specification.

The goal is to give Claude enough structural context that its suggestions fit your architecture without you having to explain it every session.


What to Include in Your Architecture Notes

1. The Overall System Structure

Start with one paragraph describing how your system is organized at the highest level. What are the main parts? How do they relate?


## Architecture Notes

### System Overview
This is a monolithic Next.js application with a layered architecture.
The front end (React components) communicates with the backend exclusively via
API routes in `app/api/`. The API routes delegate to a service layer in `lib/services/`.
The service layer is the only code that interacts with the database via Prisma.
Components never query the database directly — always via the API or Server Components.

Even this short paragraph prevents a significant class of wrong suggestions. Claude now knows it should never suggest Prisma calls from inside React components.

2. Data Flow

Describe how data moves through your system from input to output. This is especially important for apps with multiple layers, queues, or async processing.


### Data Flow

**Read path (displaying data):**
1. User visits a page → Next.js Server Component renders
2. Server Component calls a service function directly (no API route needed)
3. Service function queries database via Prisma
4. Data flows back as props into Client Components

**Write path (user actions):**
1. User submits a form or clicks a button (Client Component)
2. Client sends a request to an API route (`app/api/[resource]/route.ts`)
3. API route validates the request using Zod schema
4. API route calls the relevant service function
5. Service function performs database operation(s)
6. API route returns JSON; Client Component updates via React Query invalidation

**Background processing:**
Events that shouldn't block the user response (email sending, analytics) are
dispatched to a Trigger.dev job queue from within service functions.
Never process these synchronously in the API route.

This level of specificity means Claude will suggest mutations via API routes, not direct server actions from the component. It means Claude will put email sending in background jobs. It means Claude won’t put background processing logic in API routes.

3. Layer Separation Rules

Make the separation between your layers explicit. State what each layer can and cannot do.


### Layer Rules

**UI Layer (components, pages)**
- Can: render data, handle user interactions, call API routes for mutations
- Cannot: import from `lib/db/`, contain business logic, directly call service functions

**API Layer (app/api/ route handlers)**
- Can: validate incoming requests, call service functions, return JSON responses
- Cannot: contain business logic, query the database directly, call other API routes

**Service Layer (lib/services/)**
- Can: orchestrate business logic, call the data layer, dispatch background jobs
- Cannot: know about HTTP (no Request/Response objects), import from components

**Data Layer (lib/db/)**
- Can: define Prisma queries, handle transactions, manage database connections
- Cannot: contain business logic, be imported from components or API routes directly

This is one of the highest-value things you can add to CLAUDE.md. Claude will respect these boundaries in every suggestion it makes.

4. Patterns You Use

Describe the key patterns your codebase uses. Include a brief code example where the pattern needs illustration.


### Key Patterns We Use

**Result pattern for service functions**
Service functions never throw errors that callers need to handle for normal flow.
They return a Result type: `{ data, error }` where one is always null.

// All service functions follow this signature pattern

async function createUser(input: CreateUserInput): Promise> {

try {

const user = await db.user.create({ data: input })

return { data: user, error: null }

} catch (error) {

return { data: null, error: ‘Failed to create user’ }

}

}



**Repository pattern for complex queries**
Simple Prisma queries live in service files directly.
Complex, reusable queries are extracted to repository files in `lib/db/repositories/`.

**Server-first data fetching**
Data that can be fetched server-side always is. Client Components only fetch
data that requires client-specific context (current scroll position, window size)
or that changes in real time (notifications, live updates).

5. Patterns You Explicitly Rejected

This is often the most valuable architecture note and the most commonly skipped. Tell Claude what you considered and decided against, and why.


### Decisions We Made (And Why)

**We don't use Redux (we use Zustand)**
We evaluated Redux Toolkit but found it added too much boilerplate for our needs.
All global client state lives in Zustand stores. If Claude suggests Redux, use Zustand instead.

**We don't use tRPC (we use REST API routes)**
We looked at tRPC but our team includes non-TypeScript contributors and we wanted
a conventional REST API. Don't suggest tRPC or GraphQL — we've ruled these out.

**We don't use a microservices architecture**
This is a deliberate decision for our current stage. Don't suggest splitting things
into separate services. If a suggestion would require a separate service, suggest
a module within the monolith instead and flag the tradeoff.

**We don't use React Server Actions for mutations**
We use API routes for all mutations so the API can also be consumed by our
mobile app. Don't use `'use server'` directives — use API routes instead.

The “we decided against X” notes are gold. They prevent Claude from suggesting perfectly valid alternatives that you’ve already evaluated and rejected.

6. External Integrations

If your system integrates with external services, describe how those integrations are structured.


### External Integrations

**Stripe (payments)**
All Stripe logic is in `lib/integrations/stripe/`. The `stripe` package is only
imported in that folder — never in components, API routes, or services directly.
Webhooks are handled in `app/api/webhooks/stripe/route.ts`.
The service layer calls Stripe integration functions, not Stripe directly.

**Resend (email)**
Email sending is always done in background jobs via Trigger.dev — never synchronously.
Email templates are React components in `lib/emails/templates/`.
The `resend` package is only imported in `lib/integrations/email.ts`.

**Clerk (authentication)**
Authentication is handled entirely by Clerk. We don't store passwords or session tokens.
The current user is always accessed via Clerk's `auth()` function in server code
or `useUser()` in Client Components — never from a custom session store.

How Long Should Architecture Notes Be?

Four to eight paragraphs or sections is usually right. The goal is to cover the key structural decisions, not to document everything.

If your architecture notes are getting longer than 500 words, you’re probably including too much detail. Focus on:

  • The overall structure (1 paragraph)
  • Data flow (1-3 paragraphs)
  • Layer rules (1 section with bullet points)
  • Key patterns (2-4 patterns with brief examples)
  • Decisions made and why (3-5 decisions)

Skip details that don’t affect what Claude might suggest. You don’t need to document your CI/CD pipeline or your git branching strategy in CLAUDE.md.


Real Example: Full Architecture Notes Section

Here’s a complete, realistic architecture notes section for a SaaS application:


## Architecture Notes

### System Overview
This is a Next.js 14 App Router monolith. The frontend (React Server and Client Components)
communicates with business logic via a service layer. The service layer is the only code
that accesses the database. External APIs are accessed only through integration modules
in `lib/integrations/`. This is an intentional layered architecture — keep the layers separate.

### Data Flow
Read operations: Server Components call service functions directly and pass data as props.
Write operations: Client Components call API routes → API routes validate and call services →
services write to the database → API routes return JSON → Client Components update via
React Query cache invalidation.
Background tasks (emails, webhooks): dispatched from services to Inngest for async processing.

### Layer Rules
- **Components** → can call API routes, cannot import from `lib/db` or `lib/services`
- **API routes** (`app/api/`) → can call services, cannot query the database directly
- **Services** (`lib/services/`) → own the business logic, call `lib/db` for data access
- **DB layer** (`lib/db/`) → only Prisma queries and data access utilities here
- **Integrations** (`lib/integrations/`) → third-party API clients (Stripe, Resend, etc.)

### Authentication
Clerk handles all authentication. Access the current user with:
- Server: `const { userId } = auth()` from `@clerk/nextjs/server`
- Client: `const { user } = useUser()` from `@clerk/nextjs`
Never build custom session handling. Never store user IDs in cookies.

### Patterns We Use
- React Query for all client-side server state — not Context or local useState
- Zod schemas for all API input validation — define schemas in `lib/schemas/`
- Prisma transactions for multi-step database operations
- Named exports throughout — no default exports

### Decisions We've Made
- **No GraphQL** — we use REST API routes. Don't suggest GraphQL or tRPC.
- **No Redux** — we use Zustand for global UI state and React Query for server state.
- **No microservices** — we're a small team and a monolith is correct for our scale.
- **No React Server Actions for mutations** — our API also serves a mobile app.

Common Mistakes in Architecture Notes

Being too technical and formal. You’re writing for Claude, not for a systems architecture review. Plain English is better than formal notation.

Focusing on tools instead of patterns. “We use Prisma” belongs in the tech stack section. “The service layer is the only code that imports Prisma” belongs in architecture notes.

Forgetting the “decided against” section. This is the most important section for preventing wrong suggestions. If you chose Zustand over Redux, say so. If you use REST instead of tRPC, say so.

Making it too long. Architecture notes that run to 1,000+ words become unwieldy. Focus on what Claude might suggest that would break your design.


Key Takeaways

  • Architecture notes explain your system’s structure** — not just what tools you use, but how the pieces connect and why
  • Data flow descriptions** prevent Claude from suggesting paths that skip your layers
  • Layer rules** are specific enough to verify: “components cannot import from lib/db” is testable
  • “We decided against X”** is the most underused section — it prevents Claude from suggesting alternatives you’ve already evaluated
  • Four to eight sections or paragraphs** is the right length — long enough to cover key decisions, short enough to stay useful

Next Steps

Return to CLAUDE.md — The Complete Beginner’s Guide (2026) for the full picture.