@stricture/cli API
The @stricture/cli package provides an interactive command-line interface for managing Stricture in your projects. It helps you initialize configurations, validate architecture, check for violations, generate diagrams, and scaffold directory structures.
Overview
Package: @stricture/cli
Command: stricture or npx stricture
Purpose: Interactive CLI for managing architecture enforcement
Key Features:
- Interactive project initialization
- Real-time violation checking
- Configuration validation
- Architecture diagram generation
- Directory scaffolding
- Auto-fix capabilities (planned)
Installation
Global
npm install -g @stricture/clipnpm add -g @stricture/cliProject-specific
npm install -D @stricture/clipnpm add -D @stricture/cliThen use via npx:
npx stricture <command>Commands
init
Initialize Stricture in your project with interactive preset selection.
Usage:
stricture init [options]Options:
--preset <preset>- Architecture preset to use (skips interactive selection)--yes- Accept all defaults without prompting--no-install- Donβt install dependencies
Interactive Flow:
- Analyzes project structure (package.json, tsconfig.json, framework detection)
- Recommends appropriate presets
- Guides you through preset selection
- Customizes boundaries based on your project
- Creates
.stricture/config.json - Updates ESLint configuration
- Installs required dependencies
Examples:
# Interactive mode (recommended for first-time setup)stricture init# Non-interactive with specific presetstricture init --preset @stricture/hexagonal --yes# Skip dependency installationstricture init --no-installWhat it creates:
.stricture/config.json- Stricture configuration- Updates
eslint.config.jsor.eslintrc.js- Adds Stricture plugin
Output:
ποΈ Stricture Initialization
β Project analyzedβ Loaded preset: Hexagonal Architectureβ Created .stricture/config.jsonβ Updated ESLint configurationβ Dependencies installed
Next Steps:
1. Run linting to check architecture: npm run lint
2. Or use the Stricture CLI to check: npx stricture check
3. Customize your configuration: Edit .stricture/config.json
Learn more: https://stricture.dev/docscheck
Check your project for architecture violations.
Usage:
stricture check [options]Options:
--config <path>- Path to config file (default:.stricture/config.json)--fix- Auto-fix violations where possible (experimental)--format <format>- Output format:text,json,checkstyle(default:text)--verbose- Verbose output with detailed progress
Behavior:
- Loads
.stricture/config.json - Scans all TypeScript/JavaScript files
- Checks each import against architectural rules
- Reports violations with helpful messages
- Exits with code 1 if violations found, 0 if clean
Examples:
# Check with default configstricture check# Check with custom configstricture check --config .stricture/api-config.json# Verbose outputstricture check --verbose# JSON output for CI/CDstricture check --format json > violations.jsonOutput (text format):
Loading configuration...β Configuration loaded
Scanning files...β Scanned 147 files
Checking imports...
Found 3 violations:
src/core/domain/user.ts 12:1 error Domain layer must be pure - no external dependencies Import: ../../adapters/driven/memory-repository Fix: Remove this import or move logic to application layer
src/core/application/create-user.ts 5:1 error Application should depend on interfaces, not implementations Import: ../../adapters/driven/memory-repository Fix: Import from ports: import { UserRepository } from '../ports/user-repository'
src/adapters/driving/cli.ts 8:1 error Driving adapter should not import driven adapter Import: ../driven/memory-repository Fix: Use dependency injection in composition root
Summary: Files checked: 147 Violations: 3 Boundaries: 5 Rules: 12Output (JSON format):
{ "valid": false, "violations": [ { "file": "src/core/domain/user.ts", "line": 12, "column": 1, "message": "Domain layer must be pure...", "rule": "domain-isolation", "severity": "error" } ], "summary": { "totalFiles": 147, "filesChecked": 147, "violationsFound": 3, "boundariesDefined": 5, "rulesLoaded": 12 }}Exit Codes:
0- No violations found1- Violations found or error occurred
validate
Validate your Stricture configuration file.
Usage:
stricture validate [options]Options:
--config <path>- Path to config file (default:.stricture/config.json)--verbose- Show detailed validation info
Checks:
- JSON syntax is valid
- Required fields are present
- Boundary patterns are valid glob patterns
- Rules reference existing boundaries
- Rule structure is correct
- Preset exists (if specified)
Examples:
# Validate default configstricture validate# Validate with detailsstricture validate --verboseOutput (valid config):
Validating configuration...
β Configuration is valid
Preset: @stricture/hexagonalBoundaries: 5Rules: 12Output (invalid config):
Validating configuration...
β Configuration validation failed
Errors: - Rule 'domain-to-adapters' references unknown boundary 'adaptors' (typo?) - Boundary 'domain' missing required field 'pattern' - Rule 'invalid-rule' has invalid severity 'critical' (must be 'error', 'warn', or 'off')Exit Codes:
0- Configuration is valid1- Configuration is invalid
diagram
Generate a visual diagram of your architecture.
Usage:
stricture diagram [options]Options:
--config <path>- Path to config file (default:.stricture/config.json)--output <file>- Output file path (prints to stdout if not specified)--format <format>- Diagram format:mermaid,ascii,svg(default:mermaid)
Formats:
Mermaid - GitHub-compatible diagram markup:
graph TB
Domain["Domain Layer"]
Application["Application Layer"]
Adapters["Adapters Layer"]
Application --> Domain
Adapters --> Application
ASCII - Terminal-friendly text diagram:
ββββββββββββββββββββ Domain Layer βββββββββββ¬βββββββββ β ββββββΌβββββ β App β ββββββ¬βββββ β ββββββΌβββββ βAdapters β βββββββββββSVG - Scalable vector graphics (planned)
Examples:
# Print Mermaid diagram to stdoutstricture diagram# Save to filestricture diagram --output architecture.mmd# ASCII diagramstricture diagram --format ascii# For READMEstricture diagram --format mermaid --output docs/architecture.mmdUse Cases:
- π Include in README.md (Mermaid renders on GitHub)
- π Generate documentation
- π¨ Visualize architecture decisions
- π Onboard new team members
scaffold
Generate directory structure based on your configuration.
Usage:
stricture scaffold [options]Options:
--config <path>- Path to config file (default:.stricture/config.json)--force- Create directories without confirmation--examples- Include example README files in each directory
Behavior:
- Reads boundary patterns from config
- Extracts directory paths (e.g.,
src/domain/**βsrc/domain/) - Shows preview of directories to create
- Prompts for confirmation (unless
--force) - Creates directories
- Optionally creates README.md in each directory
Examples:
# Interactive scaffoldstricture scaffold# With example READMEsstricture scaffold --examples# No confirmation (for scripts)stricture scaffold --forceOutput:
Scaffolding directory structure...
Directories to create: - src/core/domain - src/core/ports - src/core/application - src/adapters/driving - src/adapters/driven
? Create these directories? (Y/n) y
β Created src/core/domainβ Created src/core/portsβ Created src/core/applicationβ Created src/adapters/drivingβ Created src/adapters/driven
Created 5 directoriesGenerated README (with --examples):
# domain
This directory represents the **domain** boundary.
**Pattern**: `src/core/domain/**`
## Purpose
Add a description of this boundary's purpose and responsibilities.
## Dependencies
Document which other boundaries this layer can depend on.
## Examples
Add example files and usage patterns here.fix
Auto-fix architecture violations where possible (experimental).
Usage:
stricture fix [options]Options:
--config <path>- Path to config file (default:.stricture/config.json)--verbose- Show detailed fix operations
Capabilities (planned):
- Remove forbidden imports
- Suggest alternative imports
- Add missing layer indirection
- Generate adapter stubs
Example:
stricture fix --verboseGlobal Options
These options work with all commands:
--help, -h- Show help for a command--version, -v- Show CLI version
Examples:
# Show general helpstricture --help
# Show help for specific commandstricture check --help
# Show versionstricture --versionConfiguration
The CLI reads configuration from .stricture/config.json by default. You can specify a custom path with --config.
Example config:
{ "preset": "@stricture/hexagonal", "boundaries": [ { "name": "domain", "pattern": "src/core/domain/**", "mode": "file", "tags": ["core", "domain"] } ], "rules": [ { "id": "domain-isolation", "from": { "tag": "domain" }, "to": { "tag": "*" }, "allowed": false } ]}See Configuration Guide for details.
CI/CD Integration
GitHub Actions
name: Architecture Check
on: [push, pull_request]
jobs: architecture: runs-on: ubuntu-latest steps: - uses: actions/checkout@v3 - uses: actions/setup-node@v3 with: node-version: 20 - run: npm install - run: npx stricture check --format jsonGitLab CI
architecture-check: image: node:20 script: - npm install - npx stricture check only: - merge_requestsPre-commit Hook
{ "husky": { "hooks": { "pre-commit": "npx stricture check" } }}Output Formats
Text (default)
Human-readable output with colors and formatting.
Best for: Terminal, interactive use
JSON
Machine-readable structured output.
Best for: CI/CD integration, custom tooling, reports
Example:
stricture check --format json | jq '.violations | length'Checkstyle
XML format compatible with Jenkins and other CI tools.
Best for: Jenkins, SonarQube, legacy CI systems
Example:
stricture check --format checkstyle > checkstyle-result.xmlExit Codes
All commands follow standard Unix conventions:
0- Success1- Error or violations found
Use in scripts:
#!/bin/bashif npx stricture check; then echo "Architecture is clean!"else echo "Architecture violations found!" exit 1fiTroubleshooting
Config Not Found
Error: Could not find .stricture/config.json
Solution: Run stricture init to create configuration
Invalid Config
Error: Configuration validation failed
Solution: Run stricture validate --verbose to see specific errors
No Violations But ESLint Shows Errors
Problem: CLI reports clean but ESLint shows violations
Solution:
- Check ESLint is using same config:
--configoption - Verify ESLint cache is cleared:
eslint --cache-location .eslintcache - Ensure both tools use same TypeScript config
Performance Issues
Problem: check command is slow on large projects
Solutions:
- Add ignore patterns in config
- Use ESLint integration instead (incremental checking)
- Run on specific directories: check only changed files in CI
Environment Variables
The CLI respects these environment variables:
STRICTURE_CONFIG- Default config pathNO_COLOR- Disable colored outputCI- Automatically detected, disables interactive prompts
Example:
export STRICTURE_CONFIG=.stricture/api-config.jsonstricture check # Uses api-config.jsonSee Also
- @stricture/core API - Core validation engine
- @stricture/eslint-plugin API - ESLint integration
- Configuration Guide
- Presets Guide