Define and enforce architectural rules in your projects with ease. This extension helps maintain a clean codebase by ensuring layers (like Controllers, Services, and Repositories) only interact in ways you've explicitly allowed.
Features
Smart Rule Discovery: Automatically searches for arch-rules.json up the directory tree. Perfect for monorepos or subfolder-specific rules.
Rule Templates: Quickly bootstrap your project with the "Architecture: Generate Default Rules" command.
Real-time Feedback: Get instant diagnostic warnings in your editor when an architectural rule is violated.
Language Agnostic: Works by scanning imports using regex and glob patterns, making it compatible with TypeScript, JavaScript, C#, and more.
Usage
Install the extension.
Open a project folder.
Run the commandArchitecture: Generate Default Rules from the Command Palette (Ctrl+Shift+P).
Customize the generated arch-rules.json to fit your architectural needs.
Start coding! Warnings will appear in the "Problems" tab and on the import lines if you violate a rule.
Configuration
Rules are defined in arch-rules.json. Example:
{
"layers": {
"Controller": "**/Controllers/**",
"Service": "**/Services/**",
"Repository": "**/Repositories/**"
},
"rules": [
{
"from": "Controller",
"allow": ["Service"],
"disallow": ["Repository"],
"message": "Controllers should not call Repositories directly. Use a Service."
}
]
}
layers: Map layer names to glob patterns.
rules: Define which layers can access which. Use allow or disallow.
message: Custom warning message displayed in the editor.
Why use this?
Maintaining a strict architecture is hard as projects grow. This linter acts as an automated "Architecture Review" that runs while you type, preventing technical debt before it even reaches a code review.
Extension Settings
This extension contributes the following settings:
architectureComplianceLinter.rulesFile: Specifies the name of the configuration file to look for (default is arch-rules.json).