Truss is a CLI tool that enforces architectural boundaries in JavaScript and TypeScript projects.
It prevents unintended dependencies between layers, such as controllers importing database modules directly, by analyzing static imports and building a dependency graph.
Truss detects both direct and transitive violations and is designed for deterministic local runs and CI pipelines.
As applications grow, architectural boundaries are often violated unintentionally:
- controllers start importing database modules directly
- routes bypass services
- dependencies become tangled and hard to reason about
Truss enforces these boundaries automatically, helping prevent architectural drift.
Run without installing:
npx truss-lint init
npx truss-lint checkOr install globally:
npm install -g truss-lint
truss-lint init
truss-lint checkTruss can render a dependency graph of your project with layer grouping and highlighted architectural violations.
Install locally in your project:
npm install -D truss-lintOr run directly with npx:
npx truss-lint init
npx truss-lint checkCreate a starter configuration file in your project:
npx truss-lint initThis generates a truss.yml file in your project root.
Edit the generated truss.yml to define your architecture:
version: "1"
layers:
client:
- "client/**/*.ts"
- "client/**/*.tsx"
server:
- "server/**/*.ts"
rules:
- name: no-client-to-server
from: client
disallow: [server]npx truss-lint checknpx truss-lint graph > graph.dot
dot -Tsvg graph.dot -o graph.svgThis helps visualize architectural structure and identify problematic dependencies.
Truss performs deterministic static analysis using a dependency graph pipeline:
- Load and validate
truss.yml - Discover source files (
.ts,.tsx,.js,.jsx) - Parse imports and build dependency edges
- Assign files to layers
- Evaluate rules
- Apply suppressions
- Render human-readable or JSON output
- Exit with a CI-friendly status code
- Graph-based dependency analysis
- Detection of direct and transitive architectural violations via graph traversal
- Dependency cycle detection integrated into analysis diagnostics
- Layer-based architecture enforcement via configuration
- Deterministic CLI and JSON outputs
- CI integration for automated architectural checks
- Visual graph rendering with violation highlighting
0No unsuppressed violations1One or more unsuppressed architectural violations2Configuration or CLI usage error3Internal error
Truss: Architectural violations found (2)
Direct Violations (1)
--------------------------------
[VIOLATION] no-api-to-db
Layers: api -> db
src/api/user.ts:15
import { db } from "../db/client";
Reason: API layer must not depend directly on DB layer.
Transitive Violations (1)
--------------------------------
[TRANSITIVE VIOLATION] no-api-to-db
Layers: api -> db
src/api/user.ts:0
[transitive]
Path: src/api/user.ts -> src/service/status.ts -> src/db/client.ts
Reason: API layer must not depend on DB layer.
Summary:
Unsuppressed: 2
Suppressed: 0
Total: 2
Truss: No Architectural violations found
Checked 9000 files
Truss guarantees stable and deterministic output across runs:
- consistent sorting of violations
- stable JSON schema
- snapshot-safe CLI output
This ensures reliable CI checks and predictable developer experience.
When --format json is provided, Truss prints exactly one JSON object to stdout.
All JSON output includes:
schemaVersionkind(reportorerror)
{
"schemaVersion": "1.1.0",
"kind": "report",
"exitCode": 1,
"checkedFiles": 42,
"edges": 137,
"unsuppressed": [],
"suppressed": [],
"parserIssues": [],
"analysis": {
"diagnostics": [],
"categories": {
"parser": 0,
"graph": 0,
"validation": 0,
"suppression": 0
}
},
"summary": {
"unsuppressedCount": 0,
"suppressedCount": 0,
"parserIssueCount": 0,
"diagnosticCount": 0,
"totalCount": 0
}
}{
"schemaVersion": "1.1.0",
"kind": "error",
"exitCode": 2,
"error": "Failed to load truss.yml"
}Truss integrates with CI pipelines to enforce architectural constraints automatically.
name: Truss
on:
pull_request:
push:
branches: [main]
jobs:
truss:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- uses: actions/setup-node@v4
with:
node-version: 20
- run: npm ci
- run: npx truss-lint checkThe integration suite uses fixture repos and committed snapshots to keep the CLI contract explicit.
- Snapshot tests for human-readable and JSON output
- Validation of exit codes (
0–3) - Coverage of clean, violation, suppressed, and error scenarios