A reusable, production-oriented .NET application foundation built around Clean Architecture, CQRS, Domain-Driven Design principles, and modern enterprise engineering practices.
.NET Application Foundation is a reusable software infrastructure template for building maintainable, testable, scalable, and production-oriented .NET applications.
The purpose of this repository is not to provide a sample business application.
Instead, it provides a pre-built application foundation that can be cloned or used as a starting point for new software projects.
The foundation provides the architectural boundaries, cross-cutting concerns, infrastructure integrations, development conventions, and engineering patterns required to bootstrap an enterprise-grade application without rebuilding the same technical foundation for every project.
New Project
│
▼
Clone Foundation
│
▼
Configure Environment
│
▼
Add Business Domain
│
▼
Build Application Features
│
▼
Deploy
The business domain is intentionally kept separate from the technical foundation.
Most enterprise applications repeatedly implement the same technical capabilities:
- Authentication and authorization
- Dependency injection
- Database access
- Repository abstractions
- Unit of Work
- CQRS
- Validation
- Logging
- Exception handling
- Health checks
- Observability
- Background processing
- Messaging
- Caching
- API documentation
- Configuration
- Security
- Testing infrastructure
Rebuilding these capabilities for every project increases development time and creates architectural inconsistency.
This repository provides a reusable foundation so that a new application can start with these capabilities already organized and integrated.
This repository is a:
- Software architecture template
- .NET application foundation
- Enterprise application starter
- Clean Architecture reference implementation
- Reusable infrastructure baseline
- Cross-cutting concerns foundation
- Development standardization template
This repository is not:
- A complete business application
- A CRM
- An ERP
- A CMS
- A tutorial-only project
- A microservices framework
- A replacement for domain-specific architecture decisions
The template provides technical foundations while leaving business requirements to the application built on top of it.
The solution follows Clean Architecture principles with dependencies flowing toward the application core.
┌──────────────────────┐
│ Web API │
│ Presentation │
└──────────┬───────────┘
│
▼
┌──────────────────────┐
│ Infrastructure │
│ │
│ EF Core │
│ SQL Server │
│ Identity │
│ RabbitMQ │
│ Hangfire │
│ Dapper │
└──────────┬───────────┘
│
▼
┌──────────────────────┐
│ Application │
│ │
│ CQRS │
│ MediatR │
│ DTOs │
│ Validation │
│ Interfaces │
└──────────┬───────────┘
│
▼
┌──────────────────────┐
│ Domain │
│ │
│ Entities │
│ Value Objects │
│ Domain Events │
│ Business Rules │
└──────────────────────┘
Dependencies should point inward.
Presentation
↓
Infrastructure
↓
Application
↓
Domain
The Domain layer must remain independent from infrastructure and presentation concerns.
CleanArchitecture/
│
├── .github/
│ └── workflows/
│ └── dotnet.yml
│
├── Docs/
│
├── Src/
│ │
│ ├── 1.Core/
│ │ │
│ │ ├── CleanArchitecture.Core.Domain/
│ │ │
│ │ └── CleanArchitecture.Core.Application/
│ │
│ ├── 2.Infrastructure/
│ │ │
│ │ └── CleanArchitecture.Infra.SqlServer/
│ │
│ └── 3.EndPoints/
│ │
│ └── CleanArchitecture.EndPoint.WebApi/
│
├── CleanArchitecture.sln
├── nuget.config
├── .gitignore
└── README.md
The current repository is organized into Core, Infrastructure, and EndPoints projects, providing clear architectural boundaries.
The Domain layer contains the business model.
Responsibilities include:
- Entities
- Aggregates
- Value Objects
- Domain Events
- Business Rules
- Domain Exceptions
- Domain Services
- Specifications
The Domain should not depend on:
- SQL Server
- Entity Framework Core
- HTTP
- Controllers
- RabbitMQ
- Hangfire
- Logging providers
- UI concerns
The Application layer contains application-specific business workflows and use cases.
Typical responsibilities include:
Commands
Queries
Handlers
DTOs
Validators
Interfaces
Application Services
Behaviors
Mappings
The Application layer coordinates business operations without depending on concrete infrastructure implementations.
Infrastructure contains technical implementations of application abstractions.
Current infrastructure integrations include:
- Entity Framework Core
- SQL Server
- Dapper
- ASP.NET Core Identity
- JWT infrastructure
- RabbitMQ
- Hangfire
- Dependency Injection registration
- Infrastructure services
The infrastructure layer implements interfaces defined by the inner layers.
The Web API layer is responsible for exposing application capabilities through HTTP.
Typical responsibilities include:
- HTTP endpoints
- Authentication
- Authorization
- Middleware
- Exception handling
- Swagger/OpenAPI
- Health checks
- Logging configuration
- Observability
- API configuration
Business logic should not be implemented directly inside controllers.
The template follows the following principles:
- Single Responsibility
- Open/Closed
- Liskov Substitution
- Interface Segregation
- Dependency Inversion
Dependencies point toward the application core.
Each layer owns a clearly defined responsibility.
Business logic depends on abstractions rather than infrastructure implementations.
Architectural boundaries should be enforced through project references and architecture tests.
Business logic should be independently testable without requiring external infrastructure.
| Technology | Purpose |
|---|---|
| .NET 10 | Application runtime |
| ASP.NET Core | Web API |
| C# | Primary language |
| Entity Framework Core | ORM |
| SQL Server | Relational database |
| Dapper | Micro-ORM / optimized queries |
| MediatR | CQRS / request pipeline |
| FluentValidation | Request validation |
| AutoMapper | Object mapping |
| ASP.NET Core Identity | Identity management |
| JWT Bearer | API authentication |
| RabbitMQ | Messaging |
| Hangfire | Background jobs |
| Scrutor | Dependency registration |
| Serilog | Structured logging |
| OpenTelemetry | Observability |
| Prometheus | Metrics |
| Swagger / OpenAPI | API documentation |
| Health Checks | Service health monitoring |
| MiniProfiler | Performance profiling |
The application layer supports a CQRS-oriented application model.
Typical structure:
Application/
│
├── Features/
│ ├── Users/
│ │ ├── Commands/
│ │ ├── Queries/
│ │ ├── DTOs/
│ │ └── Validators/
│ │
│ └── Organizations/
│ ├── Commands/
│ ├── Queries/
│ ├── DTOs/
│ └── Validators/
The goal is to keep each use case focused and independently maintainable.
The foundation supports multiple data access strategies.
Use EF Core for:
- Transactional operations
- Aggregates
- Change tracking
- Migrations
- Standard CRUD operations
Use Dapper selectively for:
- Read-heavy operations
- Complex SQL queries
- Reporting
- Performance-sensitive queries
The template does not require every operation to use the same data access technology.
The foundation supports:
ASP.NET Core Identity
│
▼
JWT Authentication
│
▼
Authorization Policies
│
▼
Protected API Resources
Application-specific authorization rules should be implemented using policies, roles, claims, and domain/application permissions as appropriate.
RabbitMQ is supported as the messaging infrastructure.
Typical use cases include:
- Integration events
- Asynchronous processing
- Inter-service communication
- Event-driven workflows
Messaging should remain behind abstractions so that the application is not tightly coupled to a specific broker.
Hangfire provides infrastructure for background jobs.
Typical use cases:
- Scheduled jobs
- Recurring jobs
- Deferred processing
- Long-running background tasks
- Retryable operations
Business code should remain independent from Hangfire-specific APIs.
Caching should be exposed through an application-level abstraction.
Example conceptual boundary:
Application
│
▼
ICacheService
│
▼
Infrastructure
│
├── In-Memory
└── Distributed Cache
This allows the implementation to change without modifying application use cases.
The foundation includes observability capabilities for production systems.
Structured logging is implemented with Serilog.
Typical information includes:
- Request information
- Application information
- Exception information
- Correlation information
- Execution context
OpenTelemetry can be used for:
- HTTP tracing
- Dependency tracing
- Distributed systems
- Telemetry export
Prometheus-compatible metrics can be exposed for monitoring application health and performance.
Health checks provide visibility into application dependencies.
Typical checks include:
Application
│
├── Database
├── External Services
├── Network Dependencies
└── Messaging Infrastructure
This is particularly useful for containerized and orchestrated environments.
The Web API exposes OpenAPI/Swagger documentation.
The documentation should be used to:
- Explore endpoints
- Test APIs
- Understand request/response models
- Document API contracts
Application failures should be represented consistently.
The API should provide predictable responses for:
Validation Errors
Authentication Errors
Authorization Errors
Not Found
Business Rule Violations
Infrastructure Failures
Unexpected Exceptions
A global exception-handling strategy should prevent infrastructure exceptions from leaking directly to API consumers.
Configuration should be environment-based.
Recommended configuration hierarchy:
appsettings.json
↓
appsettings.{Environment}.json
↓
Environment Variables
↓
User Secrets / Secret Store
Sensitive information must never be committed to source control.
Examples:
- Database passwords
- JWT signing secrets
- RabbitMQ credentials
- Cloud credentials
- API keys
- Connection strings containing credentials
The default relational database integration is SQL Server.
Typical development workflow:
dotnet restore
dotnet build
dotnet ef migrations add InitialCreate
dotnet ef database updateBefore running migrations, configure the appropriate connection string for the target environment.
Install:
- .NET 10 SDK
- Git
- SQL Server or SQL Server container
- Optional: RabbitMQ
- Optional: Docker
Verify .NET:
dotnet --versiongit clone https://github.com/KTajerbashi/dotnet-application-foundation.git
cd dotnet-application-foundationdotnet restoredotnet build --configuration ReleaseCreate the required configuration for:
Database
JWT
Identity
RabbitMQ
Logging
Observability
Do not commit secrets.
dotnet ef database updatedotnet run --project Src/3.EndPoints/CleanArchitecture.EndPoint.WebApiA typical development workflow is:
1. Define domain model
↓
2. Create application use case
↓
3. Add command/query
↓
4. Add validation
↓
5. Implement infrastructure abstraction
↓
6. Expose API endpoint
↓
7. Add tests
↓
8. Update documentation
For a real application built from this foundation, organize features vertically where appropriate.
Example:
Application/
└── Features/
└── Organizations/
├── Commands/
│ ├── CreateOrganization/
│ ├── UpdateOrganization/
│ └── DeleteOrganization/
│
├── Queries/
│ ├── GetOrganization/
│ └── GetOrganizations/
│
├── DTOs/
└── Validators/
This keeps related use-case code close together and makes large applications easier to navigate.
A production application created from this foundation should contain multiple testing levels.
tests/
│
├── UnitTests/
│
├── IntegrationTests/
│
└── ArchitectureTests/
Test:
- Domain rules
- Value objects
- Application handlers
- Validators
- Services
Test:
- Database integration
- API endpoints
- Authentication
- Infrastructure integrations
- Messaging
Verify:
- Domain does not depend on Infrastructure
- Domain does not depend on Presentation
- Application does not depend on Presentation
- Infrastructure does not violate dependency rules
GitHub Actions is used to automate validation.
The CI pipeline should verify at minimum:
Checkout
↓
Setup .NET
↓
Restore
↓
Build
↓
Unit Tests
↓
Integration Tests
↓
Architecture Tests
↓
Publish / Package
The CI environment must use the same major .NET SDK version as the application.
The foundation is intended to support containerized deployments.
Recommended container architecture:
┌───────────────┐
│ Web API │
└───────┬───────┘
│
┌──────────────┼──────────────┐
▼ ▼ ▼
SQL Server RabbitMQ External
Services
Recommended files:
Dockerfile
.dockerignore
docker-compose.yml
Docker should be treated as an optional deployment/development mechanism rather than a mandatory architectural dependency.
Before using the foundation for production, verify:
- Environment-specific configuration exists
- Secrets are externalized
- Database migrations are managed
- Authentication is configured
- Authorization policies are defined
- Structured logging is enabled
- Health checks are configured
- Metrics are configured
- Distributed tracing is configured
- Database indexes are reviewed
- API error handling is standardized
- Rate limiting is configured where required
- CORS is configured correctly
- HTTPS is enforced
- Security headers are configured
- Dependency vulnerabilities are reviewed
- Unit tests exist
- Integration tests exist
- Architecture tests exist
- CI pipeline passes
- Container image is scanned
- Production configuration is validated
The intended workflow is:
.NET Application Foundation
│
▼
Clone / Fork
│
▼
Rename Solution / Projects
│
▼
Configure Environment
│
▼
Define Domain
│
▼
Implement Use Cases
│
▼
Add API Features
│
▼
Add Tests
│
▼
Deploy
The foundation should provide the technical starting point while the consuming application provides the business domain.
This project follows several principles.
Infrastructure should support the business domain rather than control it.
External technologies should remain replaceable whenever practical.
Application
│
▼
Abstraction
│
▼
Implementation
Complexity should be introduced because the application requires it, not because a framework provides it.
The foundation should provide sensible defaults for:
- Security
- Logging
- Observability
- Validation
- Error handling
- Testing
- Configuration
Optional capabilities such as messaging, caching, background processing, and advanced observability should be adoptable without changing the core architecture.
- Clean Architecture
- Domain layer
- Application layer
- Infrastructure layer
- Web API
- EF Core
- SQL Server
- CQRS
- Validation
- Logging
- Health Checks
- OpenAPI / Swagger
- Identity
- JWT Authentication
- Dapper
- RabbitMQ
- Hangfire
- OpenTelemetry
- Prometheus
- Performance Profiling
- Dedicated Unit Test project
- Dedicated Integration Test project
- Architecture Tests
- Docker development environment
- Production Dockerfile
- Environment configuration examples
- Global SDK version via
global.json - Automated dependency updates
- Security scanning
- Code coverage reporting
- Release/versioning strategy
- CHANGELOG
- Template initialization scripts
The long-term target structure is:
.
├── .github/
│ └── workflows/
│
├── docs/
│
├── src/
│ ├── Domain/
│ ├── Application/
│ ├── Infrastructure/
│ └── WebApi/
│
├── tests/
│ ├── UnitTests/
│ ├── IntegrationTests/
│ └── ArchitectureTests/
│
├── scripts/
│ ├── setup.ps1
│ └── setup.sh
│
├── docker/
│
├── .editorconfig
├── .gitignore
├── Directory.Build.props
├── Directory.Packages.props
├── global.json
├── docker-compose.yml
├── CHANGELOG.md
├── LICENSE
├── README.md
└── *.sln
Projects built from this foundation should follow:
- Clean Code
- SOLID
- DRY
- KISS
- YAGNI
- Dependency Inversion
- Explicit boundaries
- Automated testing
- Automated CI validation
- Secure configuration management
- Structured logging
- Observable production services
Security is considered a first-class engineering concern.
Applications using this foundation should follow:
- Least privilege
- Secure secret management
- Strong authentication
- Policy-based authorization
- Input validation
- Secure headers
- HTTPS
- Dependency vulnerability scanning
- Secure database access
- Audit logging where required
Never commit credentials or production secrets to the repository.
Performance optimization should be evidence-driven.
The foundation supports tools that can help diagnose performance issues:
- Dapper
- MiniProfiler
- OpenTelemetry
- Prometheus
- EF Core query analysis
The preferred approach is:
Measure
↓
Identify bottleneck
↓
Optimize
↓
Measure again
Infrastructure should not introduce unnecessary complexity without a measurable requirement.
The primary goal of this foundation is long-term maintainability.
A project created from this template should allow developers to:
- Understand the architecture quickly
- Locate features predictably
- Replace infrastructure implementations
- Test business logic independently
- Add new features without modifying unrelated components
- Upgrade infrastructure independently
- Scale the application as requirements grow
This foundation is suitable for:
- Enterprise APIs
- Business applications
- Internal platforms
- SaaS backends
- Management systems
- Administrative systems
- Financial applications
- Workflow systems
- Multi-module applications
- Long-lived .NET systems
It is especially useful when the application is expected to evolve over multiple years.
A full enterprise foundation may be unnecessary for:
- Small prototypes
- One-off scripts
- Simple CRUD applications
- Short-lived proof-of-concepts
- Tiny internal utilities
Architecture should match the complexity and lifetime of the system.
Contributions should preserve the architectural principles of the repository.
Before introducing a new dependency, consider:
- Is it required by the business?
- Can the feature be implemented without it?
- Which architectural layer owns it?
- Does it introduce an unwanted dependency?
- Can it be replaced later?
- Can the behavior be tested?
- Does it increase operational complexity?
This project is intended to be used as a reusable software foundation.
See the LICENSE file for licensing terms.
Kamran Tajerbashi
Software Engineer focused on:
- .NET
- C#
- ASP.NET Core
- Angular
- Software Architecture
- Enterprise Application Development
- Distributed Systems
- Cloud-Native Development
This repository is designed around a simple idea:
Do not rebuild the technical foundation every time you start a new application.
Start with a proven architectural baseline.
Keep the business domain independent.
Add only the infrastructure the application actually needs.
Test the architecture.
Automate the build.
Observe the system.
And let the application focus on solving business problems.
Project: .NET Application Foundation
Architecture: Clean Architecture
Runtime: .NET 10
Primary Language: C#
Repository: KTajerbashi/CleanArchitecture