Architecture-as-Code for spec-driven development with full traceability.
Traditional development: Code first, document later (if ever).
Spec-driven development with Cartographer:
- Define your architecture in YAML (the spec)
- Implement with anchor comments linking code to spec
- Verify code matches spec with
cartographer scan - Evolve - changes to spec = architectural changelog (via git)
The spec becomes the single source of truth. AI agents and humans both follow it.
When you ask an AI to "add a phone field to User", without Cartographer it:
- Greps around hoping to find relevant files
- Guesses which files define User (model? schema? types? API?)
- Misses some, breaks others
With Cartographer, the AI:
- Queries
get_entity("User")→ sees all fields and their types - Queries
get_anchor("@graph:User.model")→ knows exact file and line - Follows the spec, updates all linked locations
The spec drives the change, not guesswork.
# Initialize in your project
npx mcp-cartographer init
# Define your architecture
# Edit .graph/entities/user.yaml
# Add anchors to your code
# // @graph:User.model
# Verify spec matches code
npx mcp-cartographer scan
# Expose to AI via MCP
npx mcp-cartographer serveEntities are your architectural building blocks:
# .graph/entities/user.yaml
name: User
description: Application user account
fields:
- name: id
type: uuid
primary: true
- name: email
type: string
unique: true
- name: status
type: enum
values: [active, inactive, suspended]
code_refs:
model:
anchor: "@graph:User.model"
description: ORM class definition
types:
anchor: "@graph:User.types"
description: TypeScript interfaces
validation:
anchor: "@graph:User.validation"
description: Zod schemaAdd anchor comments where concepts are implemented:
// @graph:User.model
export class User {
id: string;
email: string;
status: UserStatus;
}
// @end:User.model
// @graph:User.types
export interface CreateUserDTO {
email: string;
}
// @end:User.types
// @graph:User.validation
export const CreateUserSchema = z.object({
email: z.string().email(),
});
// @end:User.validationTraceability: Spec → Code and Code → Spec, always in sync.
$ npx mcp-cartographer scan
Scan Results
Entities: 3
Anchors: 9
✓ All anchors in syncWhen out of sync:
✗ Missing anchors (defined in spec, not found in code):
@graph:User.validation
Add this comment to your code where User validation is defined:
// @graph:User.validation
? Orphaned anchors (in code but not in spec):
@graph:Order.legacy
src/models/order.ts:42Configure in .mcp.json:
{
"mcpServers": {
"cartographer": {
"command": "npx",
"args": ["mcp-cartographer", "serve"]
}
}
}AI tools available:
list_entities()→ All entities in the architectureget_entity("User")→ Full spec with fields and code refsget_anchor("@graph:User.model")→ File, line, contentcheck_sync_status()→ Is spec in sync with code?
@graph:{Entity}.{category}
Categories:
model → ORM/class definition
schema → Database schema
types → TypeScript types/interfaces
validation → Validation schemas (Zod, Yup, etc.)
api.list → List endpoint
api.get → Get by ID endpoint
api.create → Create endpoint
api.update → Update endpoint
api.delete → Delete endpoint
.graph/config.yaml:
sourceRoots:
- src
- libFor the best experience with Claude Code, install the Cartographer plugin:
# From the repository
claude plugins install ./pluginThe plugin provides:
| Feature | Description |
|---|---|
/graph:check |
Verify spec-code synchronization |
/graph:entity |
Query entity details and relations |
/graph:impact |
Analyze change impact before modifications |
| Auto-activation | Skill activates when working with entities |
| Auto-verification | Hook runs scan after every file change |
See plugin/README.md for full documentation.
See GitHub Issues for detailed roadmap.
Core (complete):
- Entity schema with Zod validation
- YAML loader for entity definitions
- Anchor scanner for source files
- Graph + Anchor resolver
- MCP server with tools
- CLI (init, scan, serve)
- Relations between entities
- Impact analysis (what changes if I modify X?)
- Claude Code plugin with commands, skills, hooks
Next:
- Migration generation
- Architecture diagrams from spec
- Marketplace publishing
pnpm install # Install dependencies
pnpm dev # Dev mode with watch
pnpm test # Run tests
pnpm typecheck # Type check
pnpm build # Build for production- Architecture Decision Records (ADRs) - Capture why decisions were made
- Docs as Code - Documentation with same rigor as code
- C4 Model - Architecture diagrams
Cartographer complements these by capturing what exists and where it's implemented.