| name | Architecture Graph |
| description | This skill should be used when the user asks about "entities", "relations", "architecture graph", "spec-driven development", "code annotations", "@graph anchors", mentions ".graph/" directory, asks to "add entity", "create relation", "verify sync", "check drift", discusses "code_refs", "architecture specification", or is working with YAML entity files in .graph/entities/. Provides guidance for maintaining architecture-as-code consistency. |
| version | 0.1.0 |
Architecture Graph Skill
Overview
Cartographer enables spec-driven development where architecture specifications in .graph/ define the source of truth for entities, relations, and code structure. The code follows the spec, not the other way around.
Core Concepts
Entities
Entities are defined in .graph/entities/*.yaml:
name: User
description: Application user account
fields:
- name: id
type: uuid
primary: true
- name: email
type: string
unique: true
- name: name
type: string
relations:
- name: todos
entity: Todo
type: has_many
code_refs:
model:
anchor: "@graph:User.model"
schema:
anchor: "@graph:User.schema"
Key properties:
name: PascalCase entity identifierdescription: Human-readable purposefields: Typed fields with constraints (primary, unique, nullable)relations: Connections to other entitiescode_refs: Links to implementation code via anchors
Relations
Relations define how entities connect:
| Type | Description | Example |
|---|---|---|
has_many |
One-to-many | User has_many Todos |
belongs_to |
Many-to-one (inverse) | Todo belongs_to User |
has_one |
One-to-one | User has_one Profile |
has_many_through |
Many-to-many via junction | User has_many Categories through TodoCategories |
Code References (code_refs)
Code is linked to specs via anchor comments in source files:
// @graph:User.model
export interface User {
id: string;
email: string;
name: string;
}
// @end:User.model
Anchor syntax:
- Start:
// @graph:EntityName.refType - End:
// @end:EntityName.refType - Works in any language with comments
Spec-Driven Workflow
When implementing or modifying code, always follow this workflow:
1. Check the Spec First
Before writing any code, read the entity YAML in .graph/entities/:
# Use /graph:entity command
/graph:entity User
Or read the file directly to understand:
- What fields are expected
- What relations exist
- Where code should be anchored
2. Follow the Spec
Implement exactly what's specified:
- Use the same field names and types
- Implement all defined relations
- Place code in the anchored locations
3. Add Anchors
Wrap implementations with @graph: comments:
// @graph:User.model
// Implementation here
// @end:User.model
4. Verify Sync
Run /graph:check to validate that code matches spec.
Available Commands
| Command | Purpose |
|---|---|
/graph:check |
Verify spec-code synchronization |
/graph:entity <name> |
Query entity details |
/graph:impact <entity> |
Analyze change impact |
MCP Tools
The Cartographer MCP server provides these tools:
| Tool | Purpose |
|---|---|
scan |
Analyze codebase, find anchors |
query |
Get entity details |
validate |
Check spec compliance |
impact |
Analyze change dependencies |
get_relations |
Fetch entity relations |
Best Practices
1. Spec-First Development
Always define in .graph/ before implementing:
1. Create/update .graph/entities/new-entity.yaml
2. Implement code with anchors
3. Run /graph:check
2. Atomic Anchors
One anchor per logical unit:
model- Data structure/interfaceschema- Validation ruleshandler- API endpoint handlerrepository- Database access layer
3. Keep in Sync
Run /graph:check after every modification to catch drift early.
4. Document Relations
Make entity connections explicit in both entities:
# user.yaml
relations:
- name: todos
entity: Todo
type: has_many
# todo.yaml
relations:
- name: user
entity: User
type: belongs_to
Common Tasks
Adding a New Entity
- Create
.graph/entities/new-entity.yamlwith all fields - Add relations to connected entities
- Create code files with anchor comments
- Run
/graph:checkto verify
Adding a Relation
- Update both entity YAML files
- Add foreign key field if needed
- Update both code_refs sections
- Verify with
/graph:check
Modifying a Field
- Run
/graph:impact Entity.fieldfirst - Update the entity YAML
- Modify all code_refs locations
- Run
/graph:check
Checking Impact Before Changes
Before modifying an entity:
/graph:impact User.email
This shows:
- All code locations that need updates
- Related entities affected
- Suggested action items
Field Types Reference
Common field types in entity definitions:
| Type | Description |
|---|---|
uuid |
Universally unique identifier |
string |
Text data |
integer |
Whole numbers |
float |
Decimal numbers |
boolean |
True/false |
timestamp |
Date and time |
date |
Date only |
json |
JSON object |
enum |
Fixed set of values |
array |
List of items |
Troubleshooting
Anchor Not Found
If /graph:check reports missing anchors:
- Verify the anchor comment syntax is correct
- Check that start and end tags match
- Ensure the file path in code_refs is correct
Orphaned Anchor
If code has an anchor but spec doesn't reference it:
- Add the code_ref to the entity YAML, or
- Remove the anchor comment from code
Type Mismatch
If field types don't match:
- Check the entity YAML for the expected type
- Update the implementation to match
- Consider if spec needs updating instead