archkit Documentation
Give AI the blueprint before you give it the task.
archkit is a context engineering system that makes AI coding agents dramatically more effective. It generates a .arch/ directory with architecture graphs, package skills, API contracts, and rules — so the AI generates code that fits your system, not just code that works.
Installation
git clone https://github.com/kenandrewmiranda/archkit.git
cd archkit && npm install
npm install -g github:kenandrewmiranda/archkit
npx github:kenandrewmiranda/archkit
Quick Start
New project — interactive wizard
archkit
archkit --claude
Existing project — auto-detect
archkit init
archkit init src --json
Upgrade from 1.0
archkit update
archkit migrate --dry-run
archkit migrate
What Gets Generated
.arch/ Directory
| File | Purpose | Tokens |
SYSTEM.md | Rules, reserved words, session management | ~800-1200 |
BOUNDARIES.md | Hard NEVER rules (universal + app-type-specific) | ~300-500 |
CONTEXT.compact.md | ~500 token injectable for cheap-model calls | ~500 |
INDEX.md | Keyword → node/skill routing + cross-references | ~400-800 |
clusters/*.graph | Architecture graphs (Key-Rel-Dep v2 notation) | ~100 each |
skills/*.skill | Package gotchas — pre-populated WRONG/RIGHT/WHY | ~200 each |
apis/*.api | API contract digest stubs | ~100 each |
lenses/*.md | Research / Implement / Review mode overlays | ~150 each |
Claude Code Native (--claude)
| File | Purpose |
CLAUDE.md | Auto-loaded every session (<200 lines) |
.claude/rules/architecture.md | alwaysApply — rules + protocol mandate |
.claude/rules/[feature].md | Path-targeted — loads when editing that feature |
.claude/skills/[package]/SKILL.md | On-demand package knowledge |
.claude/settings.json | Pre-commit review hook + warmup nudge |
Skills skill
Skills teach AI agents about package-specific patterns and antipatterns. Each gotcha entry shows what the AI would generate by default (WRONG), the correct approach (RIGHT), and a one-line explanation (WHY).
## Meta
pkg: pg@8
docs: https://node-postgres.com
updated: 2026-04-04
## Use
PostgreSQL with Row-Level Security for multi-tenant SaaS.
## Gotchas
WRONG: SELECT * FROM users WHERE id = $1
RIGHT: SELECT id, email, name FROM users WHERE id = $1 AND tenant_id = $2
WHY: Missing tenant_id allows cross-tenant data access.
## Boundaries
Does not handle authorization logic — only tenant isolation.
## Snippets
```sql
CREATE POLICY tenant_isolation ON users
USING (tenant_id = current_setting('app.tenant_id')::uuid);
```
Skills come pre-populated with real WRONG/RIGHT/WHY entries for: PostgreSQL, Prisma, Stripe, BullMQ, Valkey, Keycloak, Docker, JWT. No empty skeletons on day 1.
Graphs graph
Graphs define feature architecture using a compact notation. Each node represents a code unit (controller, service, repository) with its layer, responsibility, and connections.
AuthCont [C] : OAuth routes, /auth/sync, /auth/me | $auth → THIS → AuthSer
AuthSer [S] : Token exchange, user sync, ban check | AuthCont ← THIS → AuthRepo
AuthRepo [R] : users table lookup, create user | AuthSer ← THIS → $db
AuthType [T] : AuthContext, SyncUserInput
AuthVal [V] : Zod schemas for auth input
AuthTest [X] : unit + integration tests
Node Layers
| Layer | Purpose |
[C] | Controller — HTTP routes, request handling |
[S] | Service — Business logic, orchestration |
[R] | Repository — Database queries, data access |
[T] | Types — TypeScript interfaces |
[V] | Validation — Zod schemas |
[E~] | Events — Async event subscribers |
[X] | Tests — Unit and integration tests |
Flow Notation
| Pattern | Meaning |
A → THIS → B | A calls THIS, THIS calls B |
A ← THIS → B | A depends on THIS, THIS calls B |
THIS ⇒ EvtName | THIS emits an async event |
Presets preset
Presets configure archkit's scaffolding wizard. They define the app type, tech stack, features, and skills to install.
{
"appName": "saas-starter",
"appType": "saas",
"stack": {
"Frontend": "Next.js + Tailwind",
"API": "Hono",
"Database": "PostgreSQL (with RLS)"
},
"features": [
{ "id": "auth", "name": "Authentication" }
],
"skills": ["postgres", "valkey", "keycloak"],
"claudeMode": true
}
Run with: archkit init --preset saas-starter.json
Supported App Types
| Type | Architecture Pattern |
| SaaS / B2B | Layered (Cont→Ser→Repo) + Modular Monolith |
| E-Commerce / Marketplace | Layered + Event-Driven |
| Real-Time (Chat/Collab) | Event-Driven + Gateway |
| Data-Intensive / Analytics | CQRS (Pipelines → Semantic → API) |
| AI-Powered Product | Hexagonal (Ports + Adapters) + Pipelines |
| Consumer Mobile | MVVM (Screen → Hook → Service → DB) |
| Internal Tools | Simple Layered |
| Content Site (CMS/Blog) | Static Generation + Interactive Islands |
Scaffold & Setup
| Command | Purpose |
archkit | Interactive 7-step wizard → .arch/ |
archkit --claude | + CLAUDE.md, .claude/rules/, hooks |
archkit init [src] | Reverse-engineer .arch/ from existing code |
archkit migrate | Upgrade 1.0 → 1.1 without data loss |
archkit update | Self-update from GitHub |
Context Resolution
All resolve commands return structured JSON on stdout (log output on stderr). Safe to pipe.
| Command | Purpose |
archkit resolve warmup | Pre-session health check (blockers = stop) |
archkit resolve context "<prompt>" | Resolve prompt → nodes, skills, files, rules |
archkit resolve preflight <feature> <layer> | Verify target before generating code |
archkit resolve scaffold <feature> | Checklist for new feature |
archkit resolve lookup <id> | Look up any node, skill, or cluster |
archkit resolve plan "<prompt>" | Structured implementation plan |
archkit resolve verify-wiring [src] | Detect dead code / unwired components |
archkit resolve audit-spec <spec> [src] | Check spec requirement coverage |
Code Review
App-type-aware review that checks against rules, boundaries, and gotchas.
| Command | Purpose |
archkit review <file> | Review file against rules + gotchas |
archkit review --staged | Review git staged files |
archkit review --diff | Review modified (unstaged) files |
archkit review --dir src/ | Review entire directory |
archkit review --agent | JSON output with autofix fields |
archkit review --verify | Re-check previously flagged files |
Review Checks by App Type
| App Type | What Gets Checked |
| SaaS | DB-in-controller, cross-feature imports, tenant scoping, money floats, layer hierarchy |
| E-Commerce | Same as SaaS + inventory locking, payment idempotency |
| Realtime | DB-in-handler, I/O-in-domain, handler complexity |
| AI | Hardcoded LLM providers, inline prompts, missing guardrails |
| Mobile | Logic-in-screens, FlatList usage, direct API calls |
Knowledge Capture
| Command | Purpose |
archkit gotcha <skill> "wrong" "right" "why" | Direct gotcha capture |
archkit gotcha --interactive | Guided gotcha wizard |
archkit gotcha --debrief | 4-question session debrief |
archkit gotcha --list | JSON: all skills + gotcha counts |
archkit gotcha --json <skill> "w" "r" "why" | JSON output (agent-callable) |
Health & Maintenance
| Command | Purpose |
archkit stats | Health dashboard (0-100 score) |
archkit stats --compact | One-line health summary |
archkit drift [--json] | Detect stale/orphaned .arch/ files |
archkit sync [src] | Detect code changes needing .arch/ updates |
Multi-Tool Export
| Command | Output |
archkit export cursor | .cursorrules |
archkit export windsurf | .windsurfrules |
archkit export copilot | .github/copilot-instructions.md |
archkit export aider | .aider-conventions.md |
archkit export all | All of the above |
Extensions
| Command | Purpose |
archkit extend create | Interactive extension builder |
archkit extend run <name> [args] | Execute an extension |
archkit extend list | List installed extensions |
archkit guard validate <file> | Validate extension (22-rule security gate) |
archkit guard audit | Full .arch/ security audit |
For AI Agents
All resolve, review, gotcha --json, drift, sync commands return structured JSON on stdout. Log output goes to stderr — safe to pipe.
archkit resolve warmup
archkit resolve context "add user notifications"
archkit resolve plan "add user notifications"
archkit review --staged --agent
archkit gotcha --json postgres "wrong" "right" "why"
Token Budget
archkit shows token estimates for every generated file and warns when always-loaded context exceeds budget:
- EFFICIENT (<1000 tokens) — minimal overhead
- MODERATE (1000-2000) — good for always-loaded
- HIGH (2000-3000) — consider trimming
- OVER BUDGET (>3000) — use CONTEXT.compact.md for cheap-model calls
Upgrading from 1.0
archkit update
archkit migrate --dry-run
archkit migrate
Migration preserves all user content (gotchas, learned rules, cross-refs) while adding:
- BOUNDARIES.md, CONTEXT.compact.md
- Built-in gotchas merged into existing skills
- Session Management table
- archkit-protocol skill + hooks (if --claude was used)