Skip to content
krus210Public

About

Spec-driven architecture validation for microservices

Resources

Contributing

Stars

16 stars

Watchers

0 watching

Forks

Repository files navigation

archspec

Spec-driven architecture validation for microservices.

License: MIT Benchmarks Agent skills

What it does

archspec captures a microservice's architecture as a versioned, machine-readable contract (SERVICE_MAP.yaml), generates Mermaid diagrams and ARCHITECTURE.md deterministically from it, and validates code changes against it on two layers:

  • Deterministic gate in pre-commit (schema, cycles, breaking changes, exceptions)
  • AI deep dive via /archspec:validate (idempotency, race conditions, eventual consistency)
                    ┌─────────────────────────┐
                    │  docs/SERVICE_MAP.yaml  │  ← single source of truth
                    └────────────┬────────────┘
                                 │
        ┌────────────────────────┼────────────────────────┐
        ▼                        ▼                        ▼
  /archspec:sync          pre-commit hook         /archspec:validate
  (Mermaid + ARCH.md)     (DET-001..015)          (AI-001..010)

Why

Pain archspec answer
ARCHITECTURE.md rots — written by hand, updated by goodwill Generated from YAML; CI fails on drift
C4 diagrams in Lucidchart aren't version-controlled Mermaid in repo, deterministic
Invariants like "endpoint must be idempotent" live in tribal knowledge Encoded in SERVICE_MAP.yaml; AI rules check the code
Reviewers can't mechanically check contracts Pre-commit + /archspec:validate reports
New contributors need weeks to understand the bounded context Read one YAML, get diagrams + invariants

5-minute install

archspec's three skills (architecture-sync, architecture-investigate, architecture-implement) are portable across Claude Code, Codex, and opencode. Pick the option that matches your setup.

Option A — Claude Code plugin (recommended)

/plugin marketplace add krus210/archspec
/plugin install archspec@archspec

After installation, run /reload-plugins (or restart Claude Code) so commands and skills become available.

Option B — any agent, via npx skills

# installs the 3 archspec skills into every detected agent
npx skills add krus210/archspec
# or scope it: -a claude-code (repeatable), -g (global), -y (no prompts),
#   --skill architecture-sync --skill architecture-investigate --skill architecture-implement

install / i / a are aliases of add. This installs skills only — the /archspec:* slash commands and git hooks come with Option A (or a manual clone). npx skills is the vercel-labs/skills CLI.

Option C — Codex (manual)

git clone https://github.com/krus210/archspec
mkdir -p .agents/skills   # or ~/.agents/skills for a global install
cp -r archspec/skills/architecture-sync        .agents/skills/
cp -r archspec/skills/architecture-investigate .agents/skills/
cp -r archspec/skills/architecture-implement   .agents/skills/

Older Codex builds scan ~/.codex/skills/ instead. Invoke a skill by typing $architecture-sync (or the skill name) or picking it from /skills.

Option D — opencode (manual)

git clone https://github.com/krus210/archspec
mkdir -p .opencode/skills   # or ~/.config/opencode/skills for a global install
cp -r archspec/skills/architecture-sync        .opencode/skills/
cp -r archspec/skills/architecture-investigate .opencode/skills/
cp -r archspec/skills/architecture-implement   .opencode/skills/

Append the archspec block (skills/architecture-sync/templates/CLAUDE.archspec-block.md) to AGENTS.md — the canonical cross-tool instructions file opencode reads (CLAUDE.md is only a fallback when no AGENTS.md exists). Optional command files go in .opencode/command/archspec/. Requires opencode ≥ v1.0.190 for native skills support.

Bootstrap a service

cd path/to/your-service
/archspec:init

This creates docs/SERVICE_MAP.yaml, generates initial diagrams + ARCHITECTURE.md, installs the pre-commit hook, and appends the archspec block to AGENTS.md (the canonical cross-tool instructions file) and CLAUDE.md (Claude Code's native file). It runs the same way once the skill is loaded on any host: Claude Code /archspec:init; Codex $architecture-sync and ask it to bootstrap; opencode load the skill and ask it to bootstrap.

What you get

archspec is intentionally small: each command/skill has a concrete artifact at the end, and those artifacts stay in the repo.

Flow Output
/archspec:init / architecture-sync bootstrap docs/SERVICE_MAP.yaml, docs/diagrams/{context,container,sequence}.mmd, generated docs/ARCHITECTURE.md, .servicemap/schema.json, docs/adr/, installed git hooks, and the archspec block in AGENTS.md and CLAUDE.md
/archspec:sync / architecture-sync Regenerated Mermaid diagrams and the managed region of docs/ARCHITECTURE.md
/archspec:investigate / architecture-investigate Read-only contract summary, clarification questions, an optional cross-check against a reference/golden spec, a chat-only sequence diagram for the proposed change, a YAML diff to apply before coding — including an edge_cases[] risk register that turns every finding into a DET-003-enforced test path — plus a persisted docs/plans/*.archplan.md artifact reviewed by an independent plan-review gate, and a definition-of-done + validation loop to run after implementation
/archspec:implement / architecture-implement Contract edits applied + re-synced docs, a coding plan with an archplan↔task conformance table, the implemented change, five conformance passes (wiring, event emission, end-to-end field threading, dedup atomicity, requirement evidence), green /archspec:validate + /archspec:check-architecture, and an independent diff review
/archspec:validate Markdown report grouped by BLOCK / WARN / INFO / SUPPRESSED, with file references and fix hints
/archspec:check-architecture Monorepo-wide architecture audit across all SERVICE_MAP.yaml files

The generated diagrams are plain Mermaid, so a fresh /archspec:init produces reviewable text artifacts rather than screenshots. Example output from a task-service init is checked in under examples/task-service-init-output/docs/diagrams.

Context diagram:

flowchart LR
  subgraph this["task-service"]
    svc[task-service]
  end
  upstream_api-gateway[api-gateway] --> svc
  svc -.-> storage_task-store[("in-memory: task-store")]
  svc ==>|publish| topic_task-created>task.created]
Loading

Container diagram:

flowchart LR
  subgraph svc_box["task-service"]
    svc[task-service]
  end
  up_api-gateway[api-gateway] -->|CreateTask, GetTask, ListTasks| svc
  svc -.-> store_task-store[("in-memory: task-store")]
  svc ==>|publish v1| pub_task-created>task.created]
Loading

Sequence diagram:

sequenceDiagram
  autonumber
  participant client as Client
  participant svc as task-service
  participant task-store as in-memory:task-store
  participant events as message-bus
  client->>svc: gRPC CreateTask
  Note over svc: read X-Idempotency-Key
  svc->>task-store: write
  svc->>events: publish task.created (v1)
  svc-->>client: response
  client->>svc: gRPC GetTask
  svc->>task-store: read
  svc-->>client: response
  client->>svc: gRPC ListTasks
  svc->>task-store: read
  svc-->>client: response
Loading

What /archspec:init does

For Go services, init runs a read-only scanner over your source files and pre-fills docs/SERVICE_MAP.yaml with what it finds:

  • HTTP endpoints from net/http, chi, gin, echo route registration
  • gRPC endpoints from pb.RegisterXxxServer calls
  • Downstream gRPC dependencies from grpc.NewClient / grpc.Dial, with the target service name resolved from address constants where possible
  • Storage clients: postgres (pgx, pgxpool), redis (go-redis), mongodb (mongo-driver), generic SQL (sqlx/database/sql), and in-memory repository factories
  • Messaging topics from Kafka (segmentio/kafka-go writer/reader, IBM/sarama producer/consumer-group) and NATS (nats-io/nats.go core Publish/Subscribe/QueueSubscribe and JetStream Publish), with subjects resolved through Go const tables in the same file

For each finding, archspec asks you to confirm it and to supply the fields the scanner cannot extract from code: SLA, idempotency policy, timeouts, retries, fallback strategy, and contract paths. Skipped findings do not enter the YAML.

If the service is not Go, or the scanner finds nothing, init falls back to a fully manual questionnaire. Messaging stacks the scanner does not know yet (RabbitMQ, GCP Pub/Sub, in-house queues) do not cause failures — events just come back empty and the questionnaire asks you to list them manually. Adding a new backend to the scanner is a small contribution: extend _MESSAGING_BACKENDS in skills/architecture-sync/scripts/scan_go.py with one publish/subscribe pattern pair plus a fixture.

Commands

Command Purpose
/archspec:init Bootstrap a new service
/archspec:sync Regenerate Mermaid + ARCHITECTURE.md from SERVICE_MAP.yaml
/archspec:validate Run the AI rules and produce a markdown report
/archspec:investigate Pre-feature workflow: read contract, propose YAML changes inline, persist a reviewed .archplan.md
/archspec:implement Implement an .archplan.md: contracts → coding plan → TDD → conformance passes → validate
/archspec:check-architecture Monorepo-wide audit across all SERVICE_MAP.yaml files

See commands/*.md for full details.

Skills (autopilot)

Skill Triggers when Produces
architecture-sync After Edit on SERVICE_MAP.yaml; phrases like "regenerate diagram", "service map drift" Validated SERVICE_MAP.yaml, refreshed Mermaid diagrams, refreshed ARCHITECTURE.md, staged generated artifacts
architecture-investigate Phrases like "let's add X", "investigate Y", "understand how Z works" Read-only architecture slice, clarification gate, optional reference-spec cross-check, change-only sequence diagram, proposed YAML diff with an edge_cases[] risk register, self-review loop, persisted .archplan.md + independent plan-review gate, definition-of-done + validation checklist
architecture-implement An .archplan.md exists and the user says "implement the plan", "build it" Applied contract edits, coding plan with conformance table, TDD implementation, five conformance passes, green validate/check-architecture, independent diff review

Skills are portable across Claude Code, Codex, and opencode — see the install options above.

What gets validated

Click to expand the rule list

Deterministic (DET-*) — pre-commit, < 1s, zero false positives:

  • DET-001 schema validation · DET-002 dependency cycles · DET-003 reference paths
  • DET-004 diagram drift · DET-005 hand-edited diagrams · DET-006 idempotency breaks
  • DET-007 removed edge_cases / scenarios · DET-008 missing changelog
  • DET-009 consistency model change · DET-010..015 exception discipline
  • DET-016 TODO literals in required-concrete fields

AI (AI-*) — /archspec:validate, contextual:

  • AI-001 idempotency · AI-002 outbox bypass · AI-003 optimistic locking
  • AI-004 façade-only violation (planned) · AI-005..006 coverage (planned) · AI-007 swallowed errors
  • AI-008 redundant calls · AI-009 undeclared events · AI-010 undeclared endpoint (planned)

Full catalog: docs/VALIDATION_RULES.md.

Extending to your language

Day one ships linters/go/. Adding linters/python/ or linters/node/ means dropping a folder and following docs/EXTENDING.md. Activation is automatic via service.language in SERVICE_MAP.yaml.

Determinism guarantees

Generators sort inputs by stable key, use a pure slugify() for IDs (no hashing), and read no clocks, randomness, environment, or filesystem state beyond the input YAML and templates. LF line endings, UTF-8 no BOM, fixed trailing newline. The benchmark suite enforces this: 20 runs of every input must produce one SHA-256 per output file.

Benchmarks

./benchmarks/run.sh

Three suites: determinism, schema, violations (F1 ≥ 0.95 threshold). Behavioral evaluation requiring ANTHROPIC_API_KEY is deferred to a later milestone.

How it compares

archspec hand-written ARCHITECTURE.md Structurizr / C4 modeling
Source of truth YAML in repo Markdown, drifts DSL in separate tool
CI gate yes no partial
Generated diagrams yes (Mermaid) no yes
AI-level invariant checks yes no no
Cost free, local free, manual commercial

Contributing

See CONTRIBUTING.md. Linters for new languages are very welcome.

License

MIT. See LICENSE.

About

Spec-driven architecture validation for microservices

Resources

Contributing

Stars

16 stars

Watchers

0 watching

Forks

Releases

Packages

Used by

Contributors

Languages