Janitor.Cli
1.0.5
dotnet tool install --global Janitor.Cli --version 1.0.5
dotnet new tool-manifest
dotnet tool install --local Janitor.Cli --version 1.0.5
#tool dotnet:?package=Janitor.Cli&version=1.0.5
nuke :add-package Janitor.Cli --version 1.0.5
Janitor
Clean up and standardize your C# repository structure automatically.
Janitor is a powerful CLI tool that analyzes .NET repositories, intelligently categorizes projects, and reorganizes them into clean, standardized folder structures following industry best practices like Clean Architecture, Vertical Slice, or Microservices patterns.
Why Janitor?
Over time, repositories become messy:
- Projects scattered across inconsistent folders
- Namespaces that don't match folder structure
- Mixed naming conventions (PascalCase, lowercase, kebab-case)
- IDE clutter and build artifacts everywhere
- Missing or outdated
.gitignore,.editorconfigfiles
Janitor cleans it all up automatically while you focus on building great software.
Installation
# Install globally from NuGet
dotnet tool install -g Janitor.Cli
# Or update if already installed
dotnet tool update -g Janitor.Cli
Once installed, use janitor from any directory:
janitor init # Create configuration
janitor plan /path/repo # Preview changes
janitor apply /path/repo # Apply transformations
Alternative installations: See INSTALL.md for building from source or local installation.
Quick Start
# 1. Initialize configuration (interactive wizard)
janitor init
# 2. Preview what will change
janitor plan /path/to/repo
# 3. Apply the transformations
janitor apply /path/to/repo
Key Features
๐ฏ Intelligent Project Classification
Automatically categorizes projects using weighted multi-factor analysis:
- Naming conventions (
*.Api,*.Worker,*.Core, etc.) - NuGet packages (ASP.NET Core, Hangfire, EF Core, etc.)
- Output type (executable vs library)
- Current folder location
๐๏ธ Built-in Templates
Choose from 5 folder structure templates:
- .NET Standard (default) - Category-based organization
- Clean Architecture - Presentation/Application/Domain/Infrastructure
- Vertical Slice - Feature-based organization
- Microservices - Service-oriented structure
- Minimal - Lowercase minimal structure
๐จ Flexible Folder Casing
7 casing styles: PascalCase, lowercase, UPPERCASE, camelCase, kebab-case, snake_case, or Preserve
๐ Namespace Alignment
Automatically updates namespaces to match your configured pattern:
{Company}.{Product}.{Category}.{Module}{Company}.{Product}.{Category}- Custom patterns supported
โ๏ธ DevOps Integration
Automatically updates paths in:
- Helm charts -
values.yaml,Chart.yaml, templates - CI/CD pipelines - GitHub Actions, Azure Pipelines, GitLab CI
- Docker -
Dockerfile,docker-compose.yml
๐ก๏ธ Safety First
- Automatic backups before every change
- Plan mode to preview without applying
- Validation checks for circular dependencies and namespace collisions
- Interactive review with confidence scores
๐งน Cleanup Features
- Removes build artifacts (
bin/,obj/) - Cleans empty directories
- Optional IDE/OS clutter removal
- Creates/updates
.gitignore,.gitattributes,.editorconfig
Commands
# Core commands
janitor init [path] # Create configuration file
--template, -t <name> # Use template
--yes, -y # Skip interactive prompts
janitor plan [repo] # Preview changes
--config, -c <path> # Custom config file
--format, -f <format> # Output: console, json, markdown
janitor apply [repo] # Apply transformations
--yes, -y # Auto-approve all changes
--config, -c <path> # Custom config file
janitor templates # List available templates
janitor template show <name> # Show template details
janitor validate <config> # Validate configuration
janitor backup list [repo] # List backups
janitor backup restore <backup> # Restore from backup
janitor version # Show version
Project Categories
| Category | Description | Detected By |
|---|---|---|
| Api | REST APIs, GraphQL, gRPC | *.Api, AspNetCore, Swashbuckle |
| Worker | Background services | *.Worker, Hosting packages |
| Job | Scheduled tasks | *.Job, Quartz, Hangfire |
| Consumer | Message consumers | *.Consumer, MassTransit, RabbitMQ |
| Service | Business logic | *.Service naming |
| Core | Domain models | *.Core, *.Domain |
| Infrastructure | Data access | *.Infrastructure, EF Core |
| Test | Tests | *.Tests, xUnit, NUnit |
Configuration
Janitor auto-discovers config files: .janitorrc.json, janitor.json, etc.
Example configuration:
{
"company": "MyCompany",
"productName": "MyProduct",
"namespacePattern": "{Company}.{Product}.{Category}",
"targetStructure": {
"srcFolder": "src",
"testFolder": "tests",
"folderNameCasing": "Pascal",
"categoryFolders": {
"Api": "Apis",
"Worker": "Workers",
"Core": "Core",
"Infrastructure": "Infrastructure"
}
},
"transformations": {
"moveProjects": true,
"updateNamespaces": true,
"cleanupUnusedFiles": false
},
"validation": {
"blockOnCircularDependencies": true,
"blockOnNamespaceCollisions": true
}
}
How It Works
Classification Algorithm uses weighted scoring:
Score = (Naming ร 0.4) + (Packages ร 0.3) + (OutputType ร 0.15) + (Location ร 0.15)
Workflow Phases:
- Scan - Discover all
.csprojand.slnfiles - Classify - Categorize projects with confidence scores
- Propose - Generate transformation plan
- Review - Interactive approval (or auto-approve with
--yes) - Backup - Create timestamped snapshot
- Apply - Execute transformations and update DevOps files
Confidence Levels:
- ๐ข High (โฅ80%) - Safe to apply
- ๐ก Medium (50-79%) - Review recommended
- ๐ด Low (<50%) - Manual review required
Documentation
- INSTALL.md - Installation and troubleshooting
- CUSTOM_FOLDER_STRUCTURES.md - Advanced folder patterns
- FOLDER_CASING.md - Casing behavior and examples
Architecture
src/
โโโ Janitor.Core/ # Domain models, interfaces
โโโ Janitor.Analysis/ # Repository scanning
โโโ Janitor.Rules/ # Classification engine
โโโ Janitor.Transformation/# Proposal & application
โโโ Janitor.Validation/ # Validation checks
โโโ Janitor.Infrastructure/# Backup, git files
โโโ Janitor.Cli/ # CLI (Spectre.Console)
Requirements
- .NET 8.0 SDK or higher
- C# 12
- Tested on macOS, Linux, Windows
Contributing
Contributions welcome! Areas of interest:
- New classification rules
- Additional templates
- Improved namespace refactoring
- More comprehensive tests
Roadmap
- Publish as NuGet global tool
- Build verification (
dotnet buildbefore/after) - Roslyn-based namespace improvements
- Visual dependency graphs
- Plugin system for custom rules
- VS Code extension
License
MIT License - See LICENSE file for details
Built to clean up messy repositories so you can focus on building great software. ๐งนโจ
| Product | Versions Compatible and additional computed target framework versions. |
|---|---|
| .NET | net8.0 is compatible. net8.0-android was computed. net8.0-browser was computed. net8.0-ios was computed. net8.0-maccatalyst was computed. net8.0-macos was computed. net8.0-tvos was computed. net8.0-windows was computed. net9.0 was computed. net9.0-android was computed. net9.0-browser was computed. net9.0-ios was computed. net9.0-maccatalyst was computed. net9.0-macos was computed. net9.0-tvos was computed. net9.0-windows was computed. net10.0 was computed. net10.0-android was computed. net10.0-browser was computed. net10.0-ios was computed. net10.0-maccatalyst was computed. net10.0-macos was computed. net10.0-tvos was computed. net10.0-windows was computed. |
This package has no dependencies.