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

# Option 1: Clone (recommended)
git clone https://github.com/kenandrewmiranda/archkit.git
cd archkit && npm install

# Option 2: Global install
npm install -g github:kenandrewmiranda/archkit

# Option 3: One-shot
npx github:kenandrewmiranda/archkit

Quick Start

New project — interactive wizard

archkit                     # Scaffold .arch/ with 7-step wizard
archkit --claude            # + Claude Code native files (hooks, skills, rules)

Existing project — auto-detect

archkit init                # Reverse-engineer .arch/ from codebase
archkit init src --json     # Detection only, no file generation

Upgrade from 1.0

archkit update              # Self-update from GitHub
archkit migrate --dry-run   # Preview migration (safe)
archkit migrate             # Upgrade .arch/ without losing gotchas/rules

What Gets Generated

.arch/ Directory

FilePurposeTokens
SYSTEM.mdRules, reserved words, session management~800-1200
BOUNDARIES.mdHard NEVER rules (universal + app-type-specific)~300-500
CONTEXT.compact.md~500 token injectable for cheap-model calls~500
INDEX.mdKeyword → node/skill routing + cross-references~400-800
clusters/*.graphArchitecture graphs (Key-Rel-Dep v2 notation)~100 each
skills/*.skillPackage gotchas — pre-populated WRONG/RIGHT/WHY~200 each
apis/*.apiAPI contract digest stubs~100 each
lenses/*.mdResearch / Implement / Review mode overlays~150 each

Claude Code Native (--claude)

FilePurpose
CLAUDE.mdAuto-loaded every session (<200 lines)
.claude/rules/architecture.mdalwaysApply — rules + protocol mandate
.claude/rules/[feature].mdPath-targeted — loads when editing that feature
.claude/skills/[package]/SKILL.mdOn-demand package knowledge
.claude/settings.jsonPre-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).

# postgres.skill

## 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.

--- auth [feature] ---
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

LayerPurpose
[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

PatternMeaning
A → THIS → BA calls THIS, THIS calls B
A ← THIS → BA depends on THIS, THIS calls B
THIS ⇒ EvtNameTHIS 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

TypeArchitecture Pattern
SaaS / B2BLayered (Cont→Ser→Repo) + Modular Monolith
E-Commerce / MarketplaceLayered + Event-Driven
Real-Time (Chat/Collab)Event-Driven + Gateway
Data-Intensive / AnalyticsCQRS (Pipelines → Semantic → API)
AI-Powered ProductHexagonal (Ports + Adapters) + Pipelines
Consumer MobileMVVM (Screen → Hook → Service → DB)
Internal ToolsSimple Layered
Content Site (CMS/Blog)Static Generation + Interactive Islands

Scaffold & Setup

CommandPurpose
archkitInteractive 7-step wizard → .arch/
archkit --claude+ CLAUDE.md, .claude/rules/, hooks
archkit init [src]Reverse-engineer .arch/ from existing code
archkit migrateUpgrade 1.0 → 1.1 without data loss
archkit updateSelf-update from GitHub

Context Resolution

All resolve commands return structured JSON on stdout (log output on stderr). Safe to pipe.

CommandPurpose
archkit resolve warmupPre-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.

CommandPurpose
archkit review <file>Review file against rules + gotchas
archkit review --stagedReview git staged files
archkit review --diffReview modified (unstaged) files
archkit review --dir src/Review entire directory
archkit review --agentJSON output with autofix fields
archkit review --verifyRe-check previously flagged files

Review Checks by App Type

App TypeWhat Gets Checked
SaaSDB-in-controller, cross-feature imports, tenant scoping, money floats, layer hierarchy
E-CommerceSame as SaaS + inventory locking, payment idempotency
RealtimeDB-in-handler, I/O-in-domain, handler complexity
AIHardcoded LLM providers, inline prompts, missing guardrails
MobileLogic-in-screens, FlatList usage, direct API calls

Knowledge Capture

CommandPurpose
archkit gotcha <skill> "wrong" "right" "why"Direct gotcha capture
archkit gotcha --interactiveGuided gotcha wizard
archkit gotcha --debrief4-question session debrief
archkit gotcha --listJSON: all skills + gotcha counts
archkit gotcha --json <skill> "w" "r" "why"JSON output (agent-callable)

Health & Maintenance

CommandPurpose
archkit statsHealth dashboard (0-100 score)
archkit stats --compactOne-line health summary
archkit drift [--json]Detect stale/orphaned .arch/ files
archkit sync [src]Detect code changes needing .arch/ updates

Multi-Tool Export

CommandOutput
archkit export cursor.cursorrules
archkit export windsurf.windsurfrules
archkit export copilot.github/copilot-instructions.md
archkit export aider.aider-conventions.md
archkit export allAll of the above

Extensions

CommandPurpose
archkit extend createInteractive extension builder
archkit extend run <name> [args]Execute an extension
archkit extend listList installed extensions
archkit guard validate <file>Validate extension (22-rule security gate)
archkit guard auditFull .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.

# Agent workflow:
archkit resolve warmup                              # health check
archkit resolve context "add user notifications"    # get relevant files/rules
archkit resolve plan "add user notifications"       # get implementation steps
archkit review --staged --agent                     # pre-commit gate
archkit gotcha --json postgres "wrong" "right" "why" # capture learning

Token Budget

archkit shows token estimates for every generated file and warns when always-loaded context exceeds budget:

Upgrading from 1.0

archkit update              # Get latest code
archkit migrate --dry-run   # Preview changes (safe)
archkit migrate             # Apply upgrade

Migration preserves all user content (gotchas, learned rules, cross-refs) while adding:

Need help? Open an issue on GitHub or browse community configs on the marketplace.