codedash-schemas
Stable public schema types for codedash code metrics output.
Overview
This crate provides the external contract for codedash's analysis JSON output. Internal domain model changes in codedash are absorbed by an Anti-Corruption Layer (ACL), so this schema remains stable for downstream consumers.
codedash (binary/lib)
┌──────────────────────────────────┐
│ domain/ast.rs │
│ (internal model — may change) │
│ │ │
│ ▼ │
│ port/schema.rs (ACL: From impls)│
│ │ │
└──────────────┼────────────────────┘
▼
┌──────────────────────────────────┐
│ codedash-schemas │
│ (public contract — stable) │
└──────────────────────────────────┘
│
┌───────────────────┼───────────────────┐
▼ ▼ ▼
Rust consumers JSON consumers GUI (egui-cha etc.)
(serde deser) (JSON Schema) (Rust SDK)
Design: Anti-Corruption Layer (ACL)
codedash follows DDD's Anti-Corruption Layer pattern to decouple the public schema from the internal domain model:
domain/ast.rs(codedash internal) — Internal types optimized for parsing and enrichment logic. May change freely across codedash versions.port/schema.rs(codedash internal) — The ACL boundary.Fromtrait implementations map domain types to schema types. This is the only place where the two models touch.codedash-schemas(this crate) — Stable public types. Versioned independently. Breaking changes follow semver.
This separation ensures:
- codedash can refactor its internals without breaking consumers
- The JSON output format has an explicit, documented contract
- Schema types carry minimal dependencies (
serdeonly, no tree-sitter/git2/mlua)
Usage
Rust consumers
Add to Cargo.toml:
[]
= "0.1"
= "1"
Deserialize codedash's JSON output:
use AstData;
let json = read_to_string?;
let data: AstData = from_str?;
for file in &data.files
JSON Schema (non-Rust consumers)
A pre-generated JSON Schema file is available at:
codedash-schemas/schema/ast-data.schema.json
Non-Rust consumers (TypeScript, Python, Go, etc.) can use this file for validation or type generation:
- TypeScript: generate interfaces via
json-schema-to-typescript - Python: generate Pydantic models via
datamodel-code-generator - Go: generate structs via
go-jsonschema
The schema file is kept up-to-date by CI. When a PR touches codedash-schemas/, GitHub Actions regenerates the JSON Schema and auto-commits any diff.
Generating from Rust
Enable the schema feature to derive schemars::JsonSchema on all types.
[]
= { = "0.1", = ["schema"] }
= "1"
let schema = schema_for!;
let json = to_string_pretty.unwrap;
write.unwrap;
To regenerate locally, run the bundled example:
Types
| Type | Description |
|---|---|
AstData |
Top-level output: files + dependency edges |
FileData |
Per-file data: path, module name, AST nodes, imports |
NodeData |
Single AST node: function, struct, enum, impl, etc. |
Edge |
Dependency edge between two files |
ImportInfo |
An internal import statement |
CallInfo |
A function call reference |
Optional features
| Feature | Dependencies | Description |
|---|---|---|
schema |
schemars |
Derives JsonSchema on all types for JSON Schema generation |
Minimum Supported Rust Version
1.80
License
MIT