Skip to content

AI-First Development

WebJs is designed from the ground up to be the framework AI agents can read, write, and ship. Every architectural decision (from the file layout to the naming conventions to the one-function-per-file rule) was made with one question in mind: can an LLM understand this without loading the entire codebase into context?

Why AI-First Matters

Modern AI coding assistants (Claude Code, GitHub Copilot, Cursor, Antigravity, etc.) are increasingly writing production code. But most frameworks were designed for humans who hold the whole project in their head. They rely on:

  • Implicit conventions: "you just know" where to put things.
  • Barrel files: re-exports that hide the real location of code.
  • Magic config: next.config.js, vite.config.ts, webpack aliases.
  • Build-time transforms: what the source says isn't what runs.
  • Scattered state: a single feature touches 5 files across 3 directories with no discoverable link.

These work fine for experienced developers who've memorised the conventions. They're hostile to AI agents that need to discover structure from the files themselves.

How WebJs Solves This

1. AGENTS.md: The Machine-Readable Contract

Every WebJs app has an AGENTS.md at the root, and it is short on purpose. WebJs follows Next.js App Router routing and Lit's component APIs, so an agent's existing habits already write most of an app correctly. The file holds only what differs:

  • The WebJs brief: the handful of places WebJs departs from Next.js and Lit (light DOM by default, erasable TypeScript, server code in *.server.ts, imports from @webjsdev/*), the instruction to run webjs check after each edit, and webjs verify to check, typecheck, test and boot every route in one call.
  • A build checklist for the template the app was created from.
  • Types and data: derive every type from its source, and keep data in the database.

Everything else is enforced rather than documented: webjs check and the runtime refuse a habit that cannot work, with the WebJs fix in the message, and the framework source in node_modules/@webjsdev/* is the exact reference, since there is no build.

An AI agent reads AGENTS.md once and knows: the shape of the app, what's safe to change, what's not, and how to add any feature. No guessing.

2. The WebJs MCP Server

Alongside the static AGENTS.md contract, every WebJs app ships a read-only Model Context Protocol server agents can wire up for live, version-accurate introspection of THIS app and the framework. It mutates nothing, so it is safe to call freely, and it is preferred over recalling WebJs from training data (which drifts). It is already available with no install (the WebJs CLI, a project dependency, has it built in as webjs mcp, and the equivalent standalone package runs as npx @webjsdev/mcp). It is an MCP STDIO server, so you do not run it in a terminal and read its output. Your MCP host (Claude Code, Cursor, etc.) launches it and surfaces its tools.

Claude Code is pre-wired by the scaffold. For another host, register the server by pointing it at the package:

// .cursor/mcp.json (or your host's MCP config)
{
  "mcpServers": {
    "webjs": {
      "command": "npx",
      "args": ["@webjsdev/mcp"]
    }
  }
}

Introspection of this app (read-only, no module load, no DB side effects):

  • list_routes: the live route table.
  • list_actions: server actions with their /__webjs/action/<hash>/<fn> RPC endpoints (the real hashes).
  • list_components: the registered custom-element tags.
  • check: the structured webjs check violations.
  • ui: the @webjsdev/ui kit inventory, or one component's helper signatures, paste-ready example, and a11y header.

Use these to learn the real route, action, and component surface before editing, instead of grepping or assuming.

The brief and the source: an init tool returns the WebJs brief, the short list of what differs from Next.js App Router routing and Lit components, which is the same text the scaffold's AGENTS.md opens with. A source tool reads the framework's OWN no-build source from node_modules/@webjsdev/*/src (what actually runs), and its export argument returns one export's signature plus its doc comment. There is no separate docs corpus for agents: WebJs is designed so Lit and Next.js habits produce correct code, and where one cannot, webjs check and the runtime refuse it with the fix in the message.

init warns when the app's installed @webjsdev/mcp is newer than the running server's, so a stale global install is visible instead of silently serving an old brief and old tools.

An agent has two complementary ways to understand the framework, and either beats guessing from training data: grep the full no-build source under node_modules/@webjsdev/*/src (the real code that runs, no sourcemaps), and the MCP for live app introspection plus the init and source tools.

3. Predictable File Layout

app/
  page.ts              → always the page component for this URL
  layout.ts            → always the wrapping layout
  route.ts             → always the HTTP handler
  middleware.ts         → always the request interceptor
  error.ts             → always the error boundary
  not-found.ts         → always the 404 page
modules/
  <feature>/
    actions/           → mutations, one file per function
    queries/           → reads, one file per function
    components/        → feature-owned UI
    utils/             → pure helpers
    types.ts           → shared type definitions

Every file has one job. An AI agent looking for "the function that creates a post" searches modules/posts/actions/, not a 500-line utils.ts or a re-exported barrel index. One grep, one result.

4. One Function Per File

Server actions and queries follow a strict one exported function per file convention:

modules/posts/actions/create-post.server.ts   → exports createPost()
modules/posts/actions/delete-post.server.ts   → exports deletePost()
modules/posts/queries/list-posts.server.ts    → exports listPosts()
modules/posts/queries/get-post.server.ts      → exports getPost()

This is the single most AI-friendly decision in the architecture. When an LLM needs to modify createPost, it reads exactly one file. It doesn't need to understand the rest of the module. Context window usage is minimal. The blast radius of a change is visible from the filename.

5. No Build Step = What You See Is What Runs

Frameworks with build pipelines transform source code before it executes. The JSX you write becomes React.createElement calls. Your imports become webpack chunks. Your CSS modules get hashed classnames. An AI agent reading the source sees one thing, while the runtime does another.

WebJs has no build step you run. The .ts file you see is the file that runs. .ts imports are stripped of types by the runtime's stripper (Node 24+'s built-in module.stripTypeScriptTypes, or amaro on Bun), which is whitespace replacement: every (line, column) in the source maps to the same position in the output, so stack traces stay byte-exact. The same transform runs server-side and on browser-bound requests. No intermediate representation, no generated code, no output directory. An AI agent can reason about what the code does by reading the file, because the file IS what runs. See No-Build Model for the full pipeline.

6. Explicit Server Boundary

The .server.ts extension is a visible, greppable marker that says "this code runs only on the server." An AI agent never accidentally puts a database call in a component, because the naming convention prevents it. And the framework enforces it: .server.ts files are rewritten to RPC stubs for the browser.

Compare with NextJs where 'use client' / 'use server' directives are easy to forget and their scope rules are subtle. The .server.ts convention is filename-level. You can't accidentally import server code without the filename literally telling you.

7. Typed RPC Without Schema

When an AI agent writes a server action:

// modules/posts/actions/create-post.server.ts
export async function createPost(
  input: { title: string; body: string }
): Promise<ActionResult<PostFormatted>> { ... }

The TypeScript signature IS the API contract. No separate schema file, no OpenAPI spec, no GraphQL SDL. The client component imports the function, TypeScript checks the types, and webjs's built-in serializer preserves them on the wire. An AI agent can:

  1. Read the function signature to understand the API.
  2. Modify the function and know every call site that breaks (via tsc).
  3. Add a new action by copying the pattern from an existing one.

Zero indirection. Zero codegen. Zero schema drift.

8. JSDoc or TypeScript: Agent's Choice

Some AI agents work better with TypeScript, others prefer JSDoc. WebJs supports both equally. The type-checking story is identical either way, since the TS language server reads both. An agent can generate whichever format it's more fluent in.

9. Cross-Agent Config, One Source

The scaffold ships a single cross-agent source of truth rather than a per-tool rule duplicate for each agent:

  • AGENTS.md, read natively by Cursor, opencode, Antigravity, and the Copilot coding agent, opening with the WebJs brief: what differs from Next.js routing and Lit components
  • A thin bridge for Claude Code, CLAUDE.md, which imports AGENTS.md (Cursor, opencode, Antigravity and the Copilot coding agent read AGENTS.md natively)

That is the whole agent doc set, deliberately short. An agent already knows Next.js routing and Lit components, so the brief spends its words only on what differs, and the tokens an agent would have spent reading a long rule file go to the app instead. Your team's own git and review process stays yours.

For Claude Code the scaffold also wires a PostToolUse hook, .claude/hooks/check-on-edit.sh, that runs webjs check --json after each edit to an app source file and hands that file's violations back to the agent with their fixes, so a wrong Lit or Next.js habit is corrected in the same turn. For a TypeScript file it also runs webjs typecheck and hands back that file's type errors (a few seconds; a module the agent has not written yet is not reported), so the first full typecheck finds a clean draft. It is silent when the file is clean, WEBJS_NO_TYPECHECK_ON_EDIT=1 skips the type errors, and WEBJS_NO_CHECK_ON_EDIT=1 turns it off.

10. Hooks Instead of Rules

For Claude Code the scaffold enforces what a rule file would otherwise ask for: a branch guard refuses an edit on main, a tests hook warns when source is committed without a test, and a stop hook asks for a commit before a turn ends with uncommitted work. A hook fires when it matters and costs nothing otherwise.

11. Automatic Tests and Docs

In a WebJs project, the user never has to say "also write tests" or "also update the docs." Agents do this automatically with every code change. The scaffold's tests hook backs it, and webjs test and webjs check verify it. For an agent lint-and-fix loop, run webjs check --json: the structured output lets the agent parse violations, fix them, and re-run until the report is clean (the same correctness data the MCP check tool returns).

12. Scaffold + Persistence Defaults

When a layman user says "create a todo app with webjs", the agent should produce a real full-stack app with a real database, not a JSON-file simulation. WebJs enforces this with three guardrails:

  • Exactly two scaffolds. webjs create <name> (full-stack default) and --template api. The CLI rejects any other --template value, so an agent can't hallucinate --template todo or --template blog. Auth is a feature you add (see the authentication docs), not a separate template.
  • Drizzle + SQLite wired up by default. Every scaffold ships db/schema.server.ts (plain Drizzle), db/connection.server.ts (exports db), the webjs.dev.before + webjs.start.before steps running webjs db migrate (idempotent, so a db:generate'd migration applies on the next boot), and npm run db:generate / db:migrate / db:studio / db:seed. The agent edits the schema, runs db:generate, and npm run dev applies it, and won't accidentally fall back to JSON files for persistence.
  • Persist with Drizzle, not JSON files. A data/todos.json or db.json used as a database resets on reload and cannot scale. This is a project convention in AGENTS.md, so an agent reading it takes the database path.

Picking the right scaffold from the user's prompt:

User asks for…                                          Scaffold
─────────────────────────────────────────────────────────────────────
Todo app, blog, notes, dashboard, marketplace, social   default
App with auth / login / signup / accounts (SaaS)        default
HTTP/JSON API only, no UI                                --template api

The scaffold is REFERENCE, not the final product. The agent's job after scaffolding is to replace the example app/page.ts ("Hello from …"), the example User model in db/schema.server.ts, and the example components with the app the user actually requested. The infrastructure (Drizzle wiring, test config, agent rules, route conventions) stays.

When the scaffolded AGENTS.md doesn't cover what you need (an obscure directive, an auth-provider recipe, deployment specifics, edge cases), the full hosted documentation is at the rest of these docs. Every API, every recipe, every example lives there. Reach for it before guessing or hand-rolling.

What an AI Agent Can Do with webjs

Given a WebJs app + AGENTS.md, an AI coding assistant can:

  • Add a new page: create app/about/page.ts, export a function returning html`...`. Done. No router config.
  • Add a new API endpoint: create app/api/users/route.ts, export GET / POST. Done. No Express boilerplate.
  • Add a server action: create modules/foo/actions/bar.server.ts, export an async function. Import it from a component. Done. No tRPC setup.
  • Add a component: create a file, extend the WebComponent({ ... }) factory with your property shape, implement render(), call ClassName.register('tag-name'). Done. No framework CLI scaffolding.
  • Add authentication: wire createAuth() from @webjsdev/server, or copy the gallery's auth demo (gallery/app/features/auth/ and gallery/modules/auth/), which has a login, a signed session and a protected route.
  • Add a database model: edit db/schema.server.ts, run webjs db generate then webjs db migrate. Create queries + actions in a new module. Done.
  • Debug an issue: read the failing route file, trace imports, find the action, check types. No build-artifact archaeology.

Design Principles for AI-Friendly Code

If you're writing a WebJs app that AI agents will work on (and they will), follow these principles:

  1. One function per file for actions and queries. Name the file after the function.
  2. Type everything. Function signatures are the API contract. An untyped function is invisible to the agent's reasoning.
  3. Keep routes thin. Business logic goes in modules. Routes are 5-line adapters that call a module function and return a Response.
  4. Use the modules convention. modules/feature/{actions,queries,components,utils,types.ts}. An agent knows where to look and where to put things.
  5. Keep AGENTS.md up to date. When you add a new convention, document it. When you add a new module, add a recipe. The agent reads this file on every session.
  6. No barrel files. Import from the specific file, not from an index.ts that re-exports. Agents work with individual files, not module graphs.
  7. No magic. If something happens implicitly (auto-registration, runtime transforms, generated code), document it explicitly in AGENTS.md. What the agent can't see, it can't reason about.

Comparison: AI-Friendliness

This is an opinionated comparison. Every framework has trade-offs.
                       webjs        NextJs       Express
──────────────────────────────────────────────────────────
AGENTS.md contract     ✅ built-in   ❌ none       ❌ none
MCP server (read-only) ✅ webjs mcp  ❌ none       ❌ none
Cross-agent config     ✅ AGENTS.md  ❌ none       ❌ none
Auto tests + docs      ✅ enforced   ❌ manual     ❌ manual
Branch guardrails      ✅ hooks      ❌ none       ❌ none
Convention validator   ✅ webjs check ❌ none      ❌ none
File = function        ✅ one/file   ⚠️ varies     ❌ free-form
No build transforms    ✅ none       ❌ SWC/webpack ✅ none
Explicit server bound. ✅ .server.ts ⚠️ 'use srv'  n/a
Typed RPC (no schema)  ✅ rich types ⚠️ Flight     ❌ manual
Autonomous mode        ✅ defaults   ❌ n/a        ❌ n/a

The AGENTS.md File

Here is the outline of the AGENTS.md a new app gets:

## The WebJs brief
## Build a full-stack app (default template)   (or the api template's checklist)
### Commands
## Types and data (all templates)

You can read the template on GitHub.