A CLI tool that validates project references in a modular monolith architecture. It ensures that C# projects follow architectural rules to maintain clean boundaries between modules.
- ✅ Project Discovery: Automatically scans directories for
.csprojfiles - ✅ Reference Validation: Validates project references against modular monolith rules
- ✅ Configurable Rules: Customize project structure and dependency rules via configuration file
- ✅ Multiple Output Formats: Console, JSON, and Markdown reports
- ✅ CI/CD Ready: Exit codes and quiet mode for automation
- ✅ Rich Console Output: Color-coded tables and panels with Spectre.Console
Install ModularGuard with a single command:
curl -fsSL https://raw.githubusercontent.com/n2jsoft-public-org/ModularGuard/main/install.sh | bashOr with wget:
wget -qO- https://raw.githubusercontent.com/n2jsoft-public-org/ModularGuard/main/install.sh | bashirm https://raw.githubusercontent.com/n2jsoft-public-org/ModularGuard/main/install.ps1 | iexThe installation script will:
- Detect your platform and architecture automatically
- Download the latest release
- Install to
~/.local/bin(Linux/macOS) or%USERPROFILE%\.local\bin(Windows) - Configure your PATH if needed
Pull the latest Docker image from GitHub Container Registry:
docker pull ghcr.io/n2jsoft-public-org/modularguard:latestDownload the latest release for your platform from the releases page:
- Linux (x64):
modularguard-linux-x64.tar.gz - Linux (ARM64):
modularguard-linux-arm64.tar.gz - macOS (x64):
modularguard-osx-x64.tar.gz - macOS (ARM64):
modularguard-osx-arm64.tar.gz - Windows (x64):
modularguard-win-x64.zip - Windows (ARM64):
modularguard-win-arm64.zip
Extract and optionally add to your PATH:
# Linux/macOS
tar -xzf modularguard-*.tar.gz
chmod +x modularguard
mkdir -p ~/.local/bin
mv modularguard ~/.local/bin/
# Add ~/.local/bin to your PATH if needed
# Windows (PowerShell)
Expand-Archive modularguard-win-x64.zip
# Move to a directory in your PATH# Clone the repository
git clone https://github.com/n2jsoft-public-org/ModularGuard.git
cd ModularGuard
# Build the project
dotnet build
# Run from source
dotnet run --project src/CLI -- check <path-to-your-project># Validate current directory
docker run --rm -v $(pwd):/workspace ghcr.io/n2jsoft-public-org/modularguard:latest check /workspace
# Validate specific directory
docker run --rm -v /path/to/your/project:/workspace ghcr.io/n2jsoft-public-org/modularguard:latest check /workspace
# With output file
docker run --rm -v $(pwd):/workspace ghcr.io/n2jsoft-public-org/modularguard:latest check /workspace --format json --output /workspace/report.json# Validate current directory
modularguard check .
# Validate specific directory
modularguard check /path/to/your/project# Validate current directory
dotnet run --project src/CLI -- check .
# Validate specific directory
dotnet run --project src/CLI -- check /path/to/your/projectModularGuard supports multiple output formats for different use cases:
# Console format (default) - Rich interactive output with tables
modularguard check .
# JSON format - Clean structured output (no console tables)
modularguard check . --format json
modularguard check . --format json --output report.json
# Markdown format - Clean markdown report (no console tables)
modularguard check . --format markdown --output report.md
# SARIF format - For IDE/tooling integration (no console tables)
modularguard check . --format sarif --output report.sarif.json
# CSV format - For spreadsheet analysis (no console tables)
modularguard check . --format csv --output report.csvNote: When using non-Console formats (json, markdown, sarif, csv), the tool automatically suppresses verbose console output (project tables, scanning messages) to produce clean, parseable output. Use --verbose to see progress messages even with structured formats.
# JSON output
docker run --rm -v $(pwd):/workspace ghcr.io/n2jsoft-public-org/modularguard:latest check /workspace --format json --output /workspace/report.json
# Markdown output
docker run --rm -v $(pwd):/workspace ghcr.io/n2jsoft-public-org/modularguard:latest check /workspace --format markdown --output /workspace/report.md# Quiet mode (minimal output, good for CI/CD)
modularguard check . --quiet
# Verbose mode (includes file paths and detailed progress)
modularguard check . --verbose
# Verbose with structured format (shows progress + structured output)
modularguard check . --format json --verbose
# Docker examples
docker run --rm -v $(pwd):/workspace ghcr.io/n2jsoft-public-org/modularguard:latest check /workspace --quiet
docker run --rm -v $(pwd):/workspace ghcr.io/n2jsoft-public-org/modularguard:latest check /workspace --verboseBehavior Summary:
- Console format: Shows all tables and messages by default
- Non-Console formats (
json,markdown,sarif,csv): Suppresses tables and scanning messages for clean output --verbose: Shows progress messages with any format--quiet: Minimal output (only errors) with any format
ModularGuard enforces the following rules for modular monolith projects:
- ✅ Can reference:
Shared.Core - ❌ Cannot reference: Infrastructure, App, or Endpoints projects
- ✅ Can reference:
Shared.Infrastructure, same module's Core project - ❌ Cannot reference: App or Endpoints projects
- ✅ Can reference:
- Matching
Shared.App.[Admin|Private|Public] - Same module's Core and Infrastructure projects
- Other modules'
*.Shared.Eventsand*.Shared.Messages
- Matching
- ❌ Cannot reference: Endpoints projects
- ✅ Can reference: Same module's matching App project only
- ❌ Cannot reference: Core or Infrastructure projects directly
- ✅ Events can reference:
Shared.Events.Abstractions - ✅ Messages can reference: Message abstraction projects
The tool can be customized using a configuration file. Create a .modularguard.yml or .modularguard.json file in your
project root.
ModularGuard automatically searches for configuration files in the following order:
.modularguard.yml.modularguard.yaml.modularguard.jsonmodularguard.ymlmodularguard.yamlmodularguard.json
If no configuration file is found, ModularGuard uses default modular monolith rules.
# .modularguard.yml
projectStructure:
patterns:
- name: "Core"
pattern: "*.Core"
type: "core"
moduleExtraction: "^(.+)\\.Core$"
- name: "Infrastructure"
pattern: "*.Infrastructure"
type: "infrastructure"
moduleExtraction: "^(.+)\\.Infrastructure$"
- name: "CustomLayer"
pattern: "*.Custom"
type: "custom"
moduleExtraction: "^(.+)\\.Custom$"
dependencyRules:
core:
allowed:
- "Shared.Core"
denied:
- "*.Infrastructure"
- "*.App"
- "*.Endpoints"
infrastructure:
allowed:
- "Shared.Infrastructure"
- "{module}.Core" # Same module's Core project
denied:
- "*.App"
- "*.Endpoints"
custom:
allowed:
- "*" # Allow all
denied: []
ignoredProjects:
- "*.Tests"
- "*.TestHelpers"
severityOverrides:
- rule: "ConfigurableRule[core]"
severity: "Warning" # Downgrade from Error to WarningDefine custom project patterns and types:
- name: Display name for the project type
- pattern: Glob pattern to match project names (e.g.,
*.Core,*.Custom) - type: Unique identifier for the project type
- moduleExtraction: Regex pattern to extract module name (optional)
Define allowed and denied dependencies for each project type:
- allowed: List of allowed dependency patterns
- Exact match:
Shared.Core - Wildcard:
*.Shared.Events - Module-scoped:
{module}.Core(references same module)
- Exact match:
- denied: List of prohibited dependency patterns
Use glob patterns to ignore specific projects:
ignoredProjects:
- "*.Tests"
- "*.Benchmarks"
- "TestHelpers.*"Override severity levels for specific rules:
severityOverrides:
- rule: "ConfigurableRule[core]"
severity: "Warning" # Options: Error, Warning, Info0: No violations found1: Violations found (errors detected)
Scanning for projects in: /path/to/project
Found 15 project(s)
╭─────────────────┬─────────────────┬──────────────────────────┬────────────╮
│ Module │ Project Type │ Project Name │ References │
├─────────────────┼─────────────────┼──────────────────────────┼────────────┤
│ UserManagement │ Core │ UserManagement.Core │ 1 │
│ │ Infrastructure │ UserManagement.Infra... │ 2 │
╰─────────────────┴─────────────────┴──────────────────────────┴────────────╯
Validating project references...
✓ No violations found!
{
"summary": {
"totalModules": 3,
"totalProjects": 12,
"errorCount": 0,
"warningCount": 0,
"isValid": true
},
"modules": [...],
"violations": []
}dotnet testsrc/
├── CLI/
│ ├── Commands/ # CLI commands
│ ├── Models/ # Data models
│ ├── Services/ # Business logic
│ ├── Validation/ # Validation rules
│ └── Reporting/ # Export formats
tests/
└── CLI.Tests/ # Unit tests
The tool is built using:
- Spectre.Console.Cli: Command-line interface framework
- Microsoft.Build: MSBuild API for reading
.csprojfiles - xUnit: Testing framework
See AGENTS.md for development principles and guidelines.
See the /roadmap directory for detailed implementation phases.
[Add your license here]