What is SAPFIAI?
SAPFIAI is a production-ready API template built with Clean Architecture principles and ASP.NET Core 8.0. It provides a solid foundation for building scalable, maintainable, and testable enterprise applications with built-in security, authentication, and authorization features. The template follows industry best practices and implements CQRS (Command Query Responsibility Segregation) pattern using MediatR, making it easy to separate read and write operations while keeping your codebase organized and maintainable.SAPFIAI stands for a technical template designed to accelerate enterprise API development while maintaining high code quality and architectural standards.
Key Features
Clean Architecture
Separation of concerns with four distinct layers: Domain, Application, Infrastructure, and Web (Presentation)
CQRS with MediatR
Command and Query separation for better scalability and maintainability
Advanced Security
JWT authentication, refresh tokens, 2FA, rate limiting, IP blacklisting, and account lockout protection
Entity Framework Core 8
Code-first database approach with migrations support for SQL Server and SQLite
FluentValidation
Centralized validation logic with expressive, easy-to-test validation rules
AutoMapper
Automatic object-to-object mapping between DTOs and domain entities
Comprehensive Testing
Unit, functional, and integration tests using NUnit, FluentAssertions, Moq, and Respawn
CI/CD Ready
Pre-configured pipelines for GitHub Actions and Azure DevOps
Architecture Overview
SAPFIAI follows Clean Architecture principles, organizing code into four distinct layers:Layer Responsibilities
Domain Layer (Core Business Logic)
Domain Layer (Core Business Logic)
- Entities: Core business objects (e.g.,
ApplicationUser,Permission,AuditLog) - Value Objects: Immutable objects representing domain concepts
- Enums: Domain-specific enumerations (e.g.,
LoginFailureReason,BlackListReason) - Exceptions: Custom domain exceptions
- No dependencies on other layers
src/Domain/Application Layer (Use Cases)
Application Layer (Use Cases)
- Commands & Queries: CQRS implementation using MediatR
- Handlers: Business logic execution
- DTOs: Data transfer objects for API communication
- Validators: FluentValidation rules
- Interfaces: Contracts for infrastructure services
- Depends only on Domain layer
src/Application/Infrastructure Layer (External Concerns)
Infrastructure Layer (External Concerns)
- DbContext: Entity Framework Core configuration
- Services: Concrete implementations (email, authentication, security)
- Identity: ASP.NET Core Identity configuration
- Background Jobs: Scheduled cleanup tasks
- Migrations: Database schema versioning
- Depends on Application and Domain layers
src/Infrastructure/Web Layer (Presentation)
Web Layer (Presentation)
- Endpoints: Minimal API endpoints
- Middleware: IP blocking, exception handling
- Configuration: Dependency injection setup
- Swagger: API documentation
- Depends on all other layers
src/Web/Technology Stack
| Technology | Version | Purpose |
|---|---|---|
| ASP.NET Core | 8.0 | Web framework and API foundation |
| Entity Framework Core | 8.0 | ORM and database migrations |
| MediatR | 12.x | CQRS mediator pattern |
| AutoMapper | 12.x | Object-to-object mapping |
| FluentValidation | 11.x | Input validation |
| ASP.NET Core Identity | 8.0 | User authentication and management |
| NUnit | 3.x | Unit testing framework |
| FluentAssertions | 6.x | Readable test assertions |
| Moq | 4.x | Mocking framework for tests |
| Respawn | 6.x | Database cleanup for tests |
Security Features
SAPFIAI includes enterprise-grade security features out of the box:JWT Authentication
Secure token-based authentication with configurable expiration
Refresh Tokens
Long-lived tokens with automatic rotation for enhanced security
Two-Factor Authentication
Optional 2FA via email for additional account protection
Rate Limiting
IP-based rate limiting to prevent brute force attacks (5 attempts per 15 minutes)
IP Blacklisting
Automatic and manual IP blocking with configurable expiration
Account Lockout
Temporary account lockout after failed login attempts (5 attempts = 15 min lockout)
Audit Logging
Complete audit trail of all authentication and security events
Background Cleanup
Automated cleanup of expired tokens, IP blocks, and old audit logs
CQRS Pattern
SAPFIAI implements the CQRS pattern to separate read and write operations:Use Cases
SAPFIAI is ideal for:- Enterprise APIs: Build robust, scalable APIs for enterprise applications
- Microservices: Use as a template for individual microservices
- Authentication Services: Leverage built-in security features for auth services
- Learning: Understand Clean Architecture and CQRS patterns in practice
- Rapid Prototyping: Start new projects with a solid foundation
What’s Next?
Quickstart
Get your API running in under 5 minutes
Installation
Detailed installation and configuration guide
Authentication
Learn about authentication endpoints
Architecture
Deep dive into the architecture
System Requirements
Before getting started, ensure you have:
- .NET 8.0 SDK or higher
- SQL Server (LocalDB, Express, or full) or SQLite
- Visual Studio 2022+ or VS Code with C# extension
- Git for version control
Community and Support
SAPFIAI is based on Clean Architecture principles popularized by Robert C. Martin (Uncle Bob) and Jason Taylor’s Clean Architecture template.Clean Architecture
Original Clean Architecture article by Uncle Bob
.NET 8 Documentation
Official .NET 8 documentation