Production-ready .NET backend template with Clean Architecture, Generic CRUD, and Minimal APIs
A modern, scalable .NET backend template that gets you from zero to production-ready API in minutes. Built with Clean Architecture principles, featuring database-agnostic design and minimal boilerplate.
ποΈ Clean Architecture - Proper separation of concerns across layers
β‘ Minimal APIs - Lightweight, fast HTTP endpoints
ποΈ Multi-Database - MongoDB and PostgreSQL with EF Core support
π¦ Template Package - Install via dotnet new
π§ Easy Extension - Add new entities in minutes
π§ͺ Fully Testable - Interface-based design for easy mocking
π OpenAPI/Swagger - Auto-generated API documentation
π³ Docker Ready - Containerization support (coming soon)
Clone the repository:
git clone https://github.com/shewart/dotnet-backend-template.git
cd dotnet-backend-templateInstall the template locally:
# Windows (PowerShell/CMD)
./install-template.ps1
# Linux/Mac/Git Bash
./install-template.shCreate your project:
# MongoDB (default)
dotnet new dotnet-backend -n MyApi
# PostgreSQL
dotnet new dotnet-backend -n MyApi --DatabaseProvider PostgreSQL
cd MyApi
dotnet run --project MyApi.Api- Configure your database (see Database Providers)
- Run the API
dotnet run --project Dotnet.Api
- Test endpoints
curl http://localhost:5087/api/products
- View API docs: http://localhost:5087/swagger
βββββββββββββββββββ βββββββββββββββββββ βββββββββββββββββββ
β Dotnet.Api ββββββ Dotnet.Application ββββββ Dotnet.Core β
β (Controllers) β β (Interfaces) β β (Entities) β
β Minimal APIs β β Services β β Models β
βββββββββββββββββββ βββββββββββββββββββ βββββββββββββββββββ
β β β
ββββββββββββββββββββββββββΌβββββββββββββββββββββββββ
β
βββββββββββββββββββ
β Dotnet.Infrastructure β
β (Data Access) β
β Repositories β
βββββββββββββββββββ
βββ Dotnet.Api/ # π Presentation Layer
β βββ Program.cs # Startup & DI configuration
β βββ appsettings.json # Configuration
β βββ Properties/
βββ Dotnet.Application/ # π Application Layer
β βββ Interfaces/ # Service contracts
βββ Dotnet.Core/ # π Domain Layer
β βββ Entities/ # Domain entities
βββ Dotnet.Infrastructure/ # βοΈ Infrastructure Layer
β βββ Services/ # Data access implementations
β βββ Configuration/ # Settings & config
βββ .template.config/ # Template configuration
This template supports multiple databases through a generic service pattern:
| Database | Status | Guide |
|---|---|---|
| MongoDB | β Ready | MongoDB Setup |
| PostgreSQL | β Ready | PostgreSQL Setup |
| SQL Server | π§ Coming Soon | SQL Server Setup |
| SQLite | π§ Planned | SQLite Setup |
Default: MongoDB (ready out of the box)
All endpoints follow RESTful conventions with full CRUD operations:
GET /api/products # Get all products
GET /api/products/{id} # Get product by ID
POST /api/products # Create new product
PUT /api/products/{id} # Update product
DELETE /api/products/{id} # Delete product
GET /api/products/count # Get total count
GET /api/products/paged # Get paginated resultsExample Request:
curl -X POST http://localhost:5087/api/products \\
-H "Content-Type: application/json" \\
-d '{
"name": "MacBook Pro",
"description": "Apple MacBook Pro 16-inch",
"price": 2499.99,
"category": "Electronics",
"inStock": true
}'Validation Example:
# This will return validation errors:
curl -X POST http://localhost:5087/api/products \\
-H "Content-Type: application/json" \\
-d '{
"name": "",
"price": -100,
"category": "InvalidCategory"
}'The template includes comprehensive input validation using FluentValidation:
- Request DTOs - Separate DTOs for create/update operations
- Business Rules - Custom validation logic for domain constraints
- Automatic Validation - Integrated with ASP.NET Core model binding
- Detailed Error Messages - Clear feedback for invalid inputs
- Product names: 2-100 characters, required
- Prices: Must be > 0 and β€ $1,000,000
- Categories: Must be from predefined list (Electronics, Books, Clothing, Home, Sports, Automotive)
- Descriptions: Max 500 characters
- Electronics products: Cannot contain restricted keywords
{
"type": "https://tools.ietf.org/html/rfc7231#section-6.5.1",
"title": "One or more validation errors occurred.",
"status": 400,
"errors": {
"Name": ["Product name must be between 2 and 100 characters"],
"Price": ["Price must be greater than 0"],
"Category": ["Category must be one of: Electronics, Books, Clothing, Home, Sports, Automotive"]
}
}The template makes it incredibly easy to add new entities:
// Dotnet.Core/Entities/Customer.cs
public class Customer
{
[BsonId]
[BsonRepresentation(BsonType.ObjectId)]
public string? Id { get; set; }
public required string Name { get; set; }
public required string Email { get; set; }
}// Program.cs
builder.Services.AddScoped<IMongoService<Customer>>(sp =>
{
var database = sp.GetRequiredService<IMongoDatabase>();
var settings = builder.Configuration.GetSection("MongoDbSettings").Get<MongoDbSettings>();
return new MongoService<Customer>(database, settings!.Collections.Customers);
});// Program.cs
var customersApi = app.MapGroup("/api/customers").WithTags("Customers");
customersApi.MapGet("/", async (IMongoService<Customer> service) =>
Results.Ok(await service.GetAllAsync()));
// ... other CRUD endpointsThat's it! π You now have a fully functional Customer API.
The template includes comprehensive testing setup:
# Run included API tests
# Use test-api.http with REST Client in VS Code
# Unit tests (coming soon)
dotnet test
# Integration tests (coming soon)
dotnet test --filter Category=Integrationdocker build -t my-api .
docker run -p 5000:8080 my-apiaz webapp create --resource-group myRG --plan myPlan --name my-api- β MongoDB support with generic CRUD
- β PostgreSQL support with Entity Framework Core
- β FluentValidation input validation
- β Request/Response DTOs
- β Minimal APIs with full CRUD operations
- β Clean Architecture foundation
- β OpenAPI/Swagger documentation
- β Template installation system
- β CQRS-ready service pattern
v1.2 - Multi-Database Universe ποΈ
- SQL Server Provider - Enterprise-ready with advanced features
- SQLite Provider - Lightweight option for development/testing
- Cosmos DB Provider - Azure cloud-native database support
v1.2 - Communication Hub π‘
- Resend Email Service - Modern email API with .NET SDK
- SMS Integration - Twilio/MessageBird support
- Push Notifications - Firebase/APNs integration
- WebSocket Real-time - Live updates and chat functionality
- Webhook Management - Secure webhook handling and verification
v1.3 - File & Document Powerhouse π
- Multi-Storage Upload - Local, Azure Blob, AWS S3, Cloudinary
- Image Processing - Resize, crop, watermark, format conversion
- PDF Generation - Advanced reporting with templates and charts
- Document Conversion - Word/Excel to PDF, HTML to PDF
- QR Code Generation - Dynamic QR codes with analytics
- Digital Signatures - Document signing with certificates
v1.4 - Security & Identity Fortress π
- JWT Authentication - Access/refresh token management
- OAuth2 Providers - Google, GitHub, Microsoft, Apple integration
- Role-Based Authorization - Flexible permission system
- API Key Management - Scoped keys with rate limiting
- Two-Factor Authentication - TOTP, SMS, Email verification
- Password Security - Breach detection, strength validation
v1.5 - AI & Smart Integrations π€
- OpenAI Integration - GPT-4, embeddings, text analysis
- Azure Cognitive Services - Translation, sentiment, OCR
- Smart Image Analysis - Auto-tagging, content moderation
- Chatbot Framework - Conversational AI with context
- Content Generation - Auto-generate descriptions, summaries
- Recommendation Engine - ML-powered suggestions
v1.6 - Performance & Monitoring Beast β‘
- Redis Caching - Distributed caching with invalidation
- Rate Limiting - Advanced throttling with Redis
- Health Checks - Comprehensive system monitoring
- Structured Logging - Serilog with enrichers and sinks
- Metrics & Telemetry - Prometheus, Application Insights
- Background Jobs - Hangfire integration with dashboards
v1.7 - DevOps & Cloud Ready π³
- Docker Multi-Stage - Optimized containerization
- Kubernetes Manifests - Production-ready K8s deployment
- Helm Charts - Parameterized K8s deployments
- CI/CD Templates - GitHub Actions, Azure DevOps pipelines
- Infrastructure as Code - Terraform, ARM templates
- Environment Management - Config per environment
v2.0 - Microservices & Enterprise π’
- Service Mesh Ready - Istio/Linkerd integration
- Event-Driven Architecture - RabbitMQ, Azure Service Bus
- CQRS & Event Sourcing - Advanced patterns
- Multi-Tenant Support - SaaS-ready architecture
- Distributed Tracing - OpenTelemetry integration
- GraphQL Gateway - Federated APIs
- Advanced Security - Zero-trust architecture, mTLS
We welcome contributions! Here's how to get started:
- Fork the repository
- Create a feature branch:
git checkout -b feature/amazing-feature - Make your changes following our coding standards
- Add tests for new functionality
- Submit a pull request
Have questions or ideas? Join our GitHub Discussions!
This project is licensed under the MIT License - see the LICENSE file for details.
- Built with β€οΈ by shewart
- Inspired by Clean Architecture principles
- Community-driven development
β Star this repo if it helped you build something awesome!
π Ready to build your next API? Get started now