Skip to content

SSWConsulting/SSW.CleanArchitecture

Repository files navigation

SSW Banner

SSW Clean Architecture Template

SSW TV | YouTube

.NET Code Scanning Package contributions welcome ADRs

SSW.CleanArchitecture Repo Analytics

πŸ€” What is it?

This is a template for creating a new project using Clean Architecture, leveraging SSW Rules & SSW's over 30 years of experience developing software in the Microsoft space.

✨ Features

  • 🎯 Domain Driven Design Patterns
  • βš–οΈ EditorConfig - comes with the SSW.EditorConfig
  • πŸ“¦ Slim - no authentication provider, no authorization & no UI framework
  • 🌐 Minimal Endpoints - because it's fast & simple. ⚑
    • Extension methods to ensure consistent HTTP Verbs & Status Codes
  • πŸ”‘ Global Exception Handling - it's important to handle exceptions in a consistent way & protect sensitive information
    • Transforms exceptions into a consistent format following the RFC7231 memo
  • πŸ“ OpenAPI/Swagger - easily document your API
  • πŸ—„οΈ Entity Framework Core - for data access
  • 🧩 Specification Pattern - abstract EF Core away from your business logic
  • πŸ”€ CQRS - for separation of concerns
  • πŸ“¦ MediatR - for decoupling your application
  • πŸ“¦ FluentValidation - for validating requests
  • πŸ“¦ AutoMapper - for mapping between objects
  • πŸ†” Strongly Typed IDs - to combat primitive obsession
    • e.g. pass CustomerId type into methods instead of int, or Guid
    • Entity Framework can automatically convert the int, Guid, nvarchar(..) to strongly typed ID.
  • πŸ”¨ dotnet new cli template - to get you started quickly
  • πŸ“ Directory.Build.Props
    • Consistent build configuration across all projects in the solution
      • e.g. Treating Warnings as Errors for Release builds
    • Custom per project
      • e.g. for all test projects we can ensure that the exact same versions of common packages are referenced
      • e.g. XUnit and NSubstitute packages for all test projects
  • πŸ§ͺ Testing
  • Architecture Tests
    • Using NetArchTest
    • Know that the team is following the same Clean Architecture fundamentals
    • The tests are automated so discovering the defects is fast

πŸŽ‰ Getting Started

Installing the Template

  1. Install the SSW CA template
dotnet new install SSW.CleanArchitecture.Template

NOTE: The template only needs to be installed once. Running this command again will update your version of the template.

  1. Create a new directory
mkdir Northwind365
cd Northwind365
  1. Create a new solution
dotnet new ssw-ca

NOTE: name is optional; if you don't specify it, the directory name will be used as the solution name and project namespaces.

Alternatively, you can specify the name and output directory as follows:

dotnet new ssw-ca --name {{SolutionName}} --output .\

Adding a Feature

  1. Create a query
cd src/Application/Features
mkdir {{FeatureName}}
cd {{FeatureName}}
dotnet new ssw-ca-query --name {{QueryName}} --entityName {{Entity}} --slnName {{SolutionName}}
  1. Create a command
cd src/Application/Features
mkdir {{FeatureName}}
cd {{FeatureName}}
dotnet new ssw-ca-command --name {{CommandName}} --entityName {{Entity}} --slnName {{SolutionName}}

Running the Solution

  1. Start dockerized SQL Server
docker compose up
  1. Run the solution
dotnet run

NOTE: The first time you run the solution, it may take a while to download the docker images, create the DB, and seed the data.

πŸš€ Publishing Template

Template will be published to NuGet.org when changes are made to CleanArchitecture.nuspec on the main branch.

Process

  1. Update the version attribute in CleanArchitecture.nuspec
  2. Merge your PR
  3. package GitHub Action will run and publish the new version to NuGet.org
  4. Create a GitHub release to document the changes

NOTE: We are now using CalVer for versioning. The version number should be in the format YYYY.M.D (e.g. 2024.2.12).

πŸŽ“ Learn More

Training

If you're interested in learning more about Clean Architecture SSW offers two events:

Learning Resources

You're interested learning more about Clean Architecture, please see this excellent video by Matt Goldman:

Alternatively, SSW has many great rules about Clean Architecture:

You can also find a collection of commumity projects built on Clean Architecture here:

🀝 Contributing

Contributions, issues and feature requests are welcome! See Contributing for more information.