This skill should be used when the user asks "set up arch-guard", "create arch-guard config", "initialize architecture rules", "generate arch-guard.json", "configure layer rules", or wants to create an arch-guard.json configuration file for their project by analyzing the codebase structure and interactively defining layer rules.
Analyzes the codebase directory structure and optionally reads design docs to generate an arch-guard.json configuration file interactively.
Look for arch-guard.json in the current working directory.
Scan the project to determine language and structure:
For .NET projects:
find . -name "*.sln" -maxdepth 2
find . -name "*.csproj" -maxdepth 4
For Java projects:
find . -name "build.gradle" -o -name "pom.xml" -maxdepth 4
For TypeScript projects:
find . -name "tsconfig.json" -maxdepth 3
Identify:
src/, app/)tests/, test/)Present the discovered projects/modules and ask the user to define layers:
## Discovered Projects
I found the following projects under src/:
1. MyApp.Domain
2. MyApp.Domain.Contracts
3. MyApp.Application
4. MyApp.Infrastructure
5. MyApp.Api
6. MyApp.BuildingBlocks.Core
## Questions
1. How many architectural layers does your project have?
2. Which projects belong to each layer?
3. What is the dependency direction? (e.g., Domain has no dependencies, Infrastructure depends on Application)
4. Are there cross-cutting/shared projects? (e.g., BuildingBlocks)
5. Are there host/entry-point projects? (e.g., Api, Hosts)
Based on the layer structure, ask about reference rules:
## Reference Rules
For each layer, I need to know:
1. Which layers can it call? (calls_allowed)
2. Which layers must it never call? (calls_forbidden)
3. Are there specific forbidden references? (e.g., Infrastructure must not reference Domain)
4. Are there allowed cross-layer references? (e.g., Execution can reference Registry.Contracts)
Ask if the project uses a contracts-first pattern:
## Contracts-First Pattern
1. Does your project use a Contracts/Interfaces project pattern? (yes/no)
2. If yes, what is the project suffix? (default: "Contracts")
3. Where are interfaces stored? (default: "Interfaces/")
4. Where are shared models stored? (default: "Models/")
Ask about:
Assemble the configuration and present it to the user for review:
{
"version": "1",
"project": { ... },
"layers": [ ... ],
"references": { ... },
"contracts": { ... },
...
}
Ask: "Does this configuration look correct? Any changes needed?"
After user confirmation, write arch-guard.json to the project root.
## Setup Complete
- Config: arch-guard.json (written to project root)
- Layers: {count} defined
- Forbidden references: {count} rules
- Contracts-first: {enabled/disabled}
### Next Steps
- /arch-check — scan the codebase for existing violations
- /scaffold {module} — create a new module following the rules
- /adr "initial architecture" — document the architecture decisions