AI × Frontend
How to Build an AI-Friendly Next.js Codebase
AI coding agents are getting better. Your codebase needs to get better too.
21 Sept 2026 · 10–12 min read
Today the interesting question is no longer simply:
"Which AI coding tool should I use?"
A better question is:
"What does an AI-friendly codebase look like?"
A coding agent can read code, create files, change an implementation, run tests, read errors, and repeat that loop. What it cannot do on its own is understand architecture, business rules, or the conventions a team has built over years.
That leads to a useful principle:
The better your codebase communicates its intent, the more useful an AI coding agent becomes.
Next.js is already moving in this direction. Recent versions added capabilities aimed at AI agents, including AGENTS.md, first-party Skills, browser tooling, browser log forwarding, and MCP-related tooling.
01AI does not struggle with code. AI struggles with context.
Imagine handing a new developer this task:
"Add authentication to this application."
That person would need to know:
- where authentication already lives
- which API client the project uses
- how sessions are stored
- whether the page is a Server Component or a Client Component
- where validation belongs
- what the error-handling convention is
- where the tests live
- what the naming convention is
An AI agent has the same problem.
If a repository looks like this:
components/
hooks/
utils/
services/
lib/
helpers/
common/
shared/
misc/and the boundaries are unclear, the agent has to guess.
The more it has to guess, the more likely it is to produce an implementation that does not belong.
02What an AI-friendly codebase looks like
Frontend
│
┌──────────────┼──────────────┐
│ │ │
Pages Features Shared
│ │ │
│ ┌───┴───┐ │
│ │ │ │
│ Auth Profile │
│ │
└──────────────┬──────────────┘
│
Services
│
APIAn AI-friendly codebase usually has five qualities:
1. Clear architecture
The agent can quickly answer:
Where does this feature belong?2. Explicit conventions
The agent does not have to guess:
How should I write this?3. Local documentation
The agent can see:
Why does this code exist?4. Automated feedback
The agent can tell:
Did my change actually work?5. Small, testable boundaries
The agent can change one small part without breaking the whole system.
03`AGENTS.md`: an instruction manual for the coding agent
One of the more useful changes in the current Next.js ecosystem is documentation written for agents through AGENTS.md. Next.js describes it as the place that helps an agent use documentation that matches the framework version.
project/
├── app/
├── components/
├── features/
├── lib/
├── tests/
├── AGENTS.md
└── package.json
# AGENTS.md
## Architecture
- Use Server Components by default.
- Client Components require justification.
- Feature-specific components belong
inside /features.
## API
- Do not call external APIs directly
from Client Components.
## TypeScript
- Do not use `any`.
- Prefer discriminated unions.
## Testing
Run:
pnpm lint
pnpm typecheck
pnpm testAGENTS.md should not become a giant documentation file.
It should answer the questions an agent needs before it edits code.
For example:
# Project Instructions
## Architecture
This project uses Next.js App Router.
Server Components are the default.
Use Client Components only when the component
requires browser APIs, state, or event handlers.
## Components
Shared components:
components/ui
Feature components:
features/<feature>/components
## Data Fetching
Server-side data fetching belongs in:
features/<feature>/services
Do not fetch application APIs directly
inside presentation components.
## TypeScript
Never use `any`.
Prefer explicit domain types.
## Validation
Use Zod for external input validation.
## Before finishing a task
Run:
pnpm lint
pnpm typecheck
pnpm testThe important part is not that a file happens to be named AGENTS.md.
The important part is:
Your repository should explicitly communicate how it expects code to be written.
04Do not write "Use best practices"
This is a weak instruction:
Write clean code.
Follow best practices.
Use good architecture.AI cannot turn those sentences into a constraint that is sharp enough to follow.
Write this instead:
## Component rules
Server Components are the default.
Use "use client" only if the component requires:
- useState
- useEffect
- browser APIs
- event handlers
Do not add "use client" simply because
a component renders interactive-looking UI.That is a much better instruction because it can become a decision tree.
05Design architecture so an agent can navigate it
For a larger application, I usually prefer a structure like this:
src/
│
├── app/
│
├── features/
│ ├── auth/
│ │ ├── components/
│ │ ├── services/
│ │ ├── schemas/
│ │ ├── types/
│ │ └── tests/
│ │
│ ├── profile/
│ │ ├── components/
│ │ ├── services/
│ │ ├── schemas/
│ │ └── types/
│ │
│ └── dashboard/
│
├── components/
│ └── ui/
│
├── lib/
│
└── types/features/auth
features/profile
features/dashboardTake a task like:
"Add email verification to authentication."
The agent can start here:
features/auth/instead of searching the whole repository.
This is not only an AI optimization.
It is also a better architecture for people.
06Give the agent tools, not just instructions
An agent that can only read source code is limited.
An agent that can:
Read code
↓
Edit code
↓
Run tests
↓
Start browser
↓
Inspect errors
↓
Fix
↓
Run tests againhas a much stronger feedback loop.
Next.js 16.x has added more tooling in this direction, including browser-related capabilities, browser log forwarding, and agent-oriented development tools.
┌──────────────┐
│ AI Agent │
└──────┬───────┘
↓
Change code
↓
┌──────────────┐
│ Browser │
└──────┬───────┘
↓
Error / UI
↓
┌──────────────┐
│ Logs │
└──────┬───────┘
↓
Agent fixes
│
└──────────→07Testing becomes the agent's feedback mechanism
This part matters more than it first appears.
If you ask AI to:
"Build a checkout flow."
and there are no tests, the agent cannot answer:
Did it work?With tests:
describe("checkout", () => {
it("creates an order", async () => {
// ...
});
it("rejects an invalid payment", async () => {
// ...
});
});the task becomes:
Implement
↓
Run tests
↓
Read failure
↓
Fix
↓
Run tests
↓
DoneThat is a different workflow.
08Write tasks like engineering specifications
Instead of:
"Create a profile page."
write:
## Task
Create a profile page for authenticated users.
## Requirements
- Use a Server Component for the page.
- Profile data comes from `profileService`.
- Email is read-only.
- Name can be edited.
- Validate input with Zod.
- Show server validation errors.
- Revalidate profile data after mutation.
## Acceptance criteria
- User can update their name.
- Invalid input displays an error.
- API errors do not crash the page.
- Existing tests continue to pass.
## Validation
Run:
pnpm lint
pnpm typecheck
pnpm testAI should not have to invent the acceptance criteria.
09AI-friendly does NOT mean AI-generated everything
This distinction is easy to miss.
A codebase that is good for AI does not mean:
"Let AI write everything."
It means:
Make the system understandable enough that humans and AI can collaborate effectively.
People still decide:
- architecture
- business rules
- security boundaries
- data model
- product behavior
- trade-offs
AI can help with:
- implementation
- refactoring
- tests
- documentation
- debugging
- repetitive code
- exploration
10A practical AI-friendly checklist
AI-FRIENDLY NEXT.JS
✓ Clear architecture
✓ Feature boundaries
✓ AGENTS.md
✓ Explicit conventions
✓ Type-safe APIs
✓ Automated tests
✓ Lint + typecheck
✓ Browser feedback
✓ Actionable errors
✓ Small tasks
✓ Clear acceptance criteriaThe architecture I would start with
Repository
│
├── AGENTS.md
│
├── src/
│ ├── app/
│ ├── features/
│ ├── components/
│ ├── lib/
│ └── types/
│
├── tests/
│
├── package.json
│
└── README.mdThen build a feedback loop:
┌─────────────┐
│ Human │
└──────┬──────┘
│
Task
↓
┌─────────────┐
│ AI Agent │
└──────┬──────┘
│
Code
↓
┌────────────┼────────────┐
↓ ↓ ↓
Tests Typecheck Browser
│ │ │
└────────────┼────────────┘
↓
Feedback
↓
Agent
↺Conclusion
AI coding agents are changing frontend development, but the most important part may not be which model is strongest.
It may be:
How well does your codebase explain itself?
A codebase with clear architecture, clear conventions, trustworthy tests, and a good feedback loop is useful to both a developer and an AI agent.
That is also a more practical way to think about "AI-native development":
Don't build software around AI. Build software that AI can understand.
Further reading
- Next.js AI improvements
- Next.js Agent Evals
- Next.js 16 documentation
- React Server Components documentation
21 Sept 2026
That’s all for this note.