Skip to content

Architecture: spec-sync docs

Reference

How SpecSync keeps its validation and SDD lifecycle deterministic, portable, and usable by both humans and coding agents.

System shape

SpecSync is a single Rust binary with five cooperating layers:

CLI / MCP / agent skills
        -�-
SDD change lifecycle and canonical spec model
        -�-
structural, API, dependency, and schema validation
        -�-
language-specific regex or tree-sitter extraction
        -�-
Git, filesystem, registry, and GitHub adapters

The CLI is the source of truth. Editor extensions, GitHub Actions, MCP clients, and native agent skills invoke the same commands and receive the same results.

Source layout

AreaResponsibility
main.rs, cli.rs, cli_args.rsCommand parsing, dispatch, enforcement, and output formats
change.rsVerified SDD interviews, approvals, deltas, evidence, acceptance, and archival
parser.rs, validator.rsSpec structure, Public API tables, coverage, and canonical checks
deps.rsSource import discovery and dependency graph validation
exports/Language detection and public-symbol extraction
schema.rsSQL table and column drift validation
config.rs, types.rsCanonical TOML configuration and shared data models
generator.rs, commands/Scaffolding and command implementations
hash_cache.rs, watch.rsIncremental validation and filesystem watching
registry.rs, importer.rsCross-project references and external spec import
github.rs, comment.rsGitHub metadata, drift issues, and PR summaries
agents.rs, hooks.rs, mcp.rsCoding-agent skills, Git hooks, and JSON-RPC integration

Design principles

Deterministic local core. Spec checking, generation, scoring, dependency analysis, and lifecycle enforcement do not call a model or require an API key.

Hybrid extraction. Regex extraction is portable and remains the default. Tree-sitter AST extraction is available for supported languages when parse_mode = "ast" is configured. Per-language reference pages document the exact behavior and caveats.

Fail-closed evidence. Definition approvals, verification, and closing approvals are digest-bound. Changes to scoped code, tests, configuration, file kind, executable mode, or contract inputs invalidate stale evidence.

Git-native history. Canonical specs, semantic deltas, requirements, decisions, and evidence remain reviewable as ordinary files. Accepted changes archive only after delivery integration.

One engine for humans and agents. Native skills present the deterministic CLI interview conversationally; they do not create a separate agent-only lifecycle.

Validation pipeline

1. Lifecycle gate

When SDD is enabled, SpecSync validates active workspaces, approvals, semantic deltas, task completion, requirement evidence, and meaningful-path coverage.

2. Structural contract

  • Parse frontmatter and required fields
  • Verify source files and dependency specs exist
  • Require configured ## sections
  • Validate requirement and companion conventions

3. API and schema surface

  • Detect each source language
  • Extract public symbols using its configured parser
  • Compare symbols with backtick-quoted Public API entries
  • Compare documented database tables and columns with migrations

Spec-only symbols are errors. Code-only symbols and undocumented schema details are warnings that become failures in strict mode.

4. Dependency graph

Source imports are mapped to owning specs and compared with depends_on. Strict mode rejects undeclared imports, missing modules, and cycles.

5. Coverage and quality

Coverage measures source files and LOC governed by specs. Scoring evaluates frontmatter, required sections, API completeness, depth, and freshness.

Adding a language

  1. Add or update the extractor in src/exports/.
  2. Register extensions, test exclusions, and parser support.
  3. Add focused fixtures for visibility, comments, strings, re-exports, and malformed input.
  4. Update the language registry data in site/src/data/languages/.
  5. Run the full export verification suite and strict SpecSync check.

Extractors must fail safely on unreadable input and must not require a language compiler or server at runtime.

Important dependencies

CratePurpose
clapCLI parsing
serde, serde_jsonConfiguration, policy, evidence, and JSON output
regexPortable parsing and extraction
tree-sitter-*Optional AST-backed language extraction
walkdirProject discovery and coverage
sha2Cache and lifecycle evidence digests
notifyWatch mode
ureqRegistry, import, and GitHub HTTP access---not AI inference

See the spec format, workflow, and language reference for the user-facing contracts implemented by these layers.