A robust .NET 8 Web API built with Clean Architecture principles, featuring user authentication, email verification, and comprehensive API documentation.
- Clean Architecture - Organized in Domain, Application, Infrastructure, and Web layers
- User Authentication - Registration, login, and email verification
- Email Verification - Secure verification code system
- JWT Authentication - Token-based security
- Entity Framework Core - Code-first database approach
- Swagger Documentation - Interactive API documentation
- SQL Server - Robust database backend
- Repository Pattern - Clean data access layer
Enforca/
βββ Domain/ # Business entities and core logic
βββ Application/ # Use cases and DTOs
βββ Infrastructure/ # Data access and external services
βββ Web/ # API controllers and configuration
- .NET 8 - Latest .NET framework
- Entity Framework Core - ORM for database operations
- SQL Server - Database
- AutoMapper - Object mapping
- FluentValidation - Input validation
- Swagger/OpenAPI - API documentation
- JWT Bearer - Authentication tokens
- .NET 8 SDK
- SQL Server or SQL Server LocalDB
- Visual Studio 2022 or JetBrains Rider
git clone https://github.com/yourusername/enforca-api.git
cd enforca-api
Update the connection string in Web/appsettings.json
:
{
"ConnectionStrings": {
"DefaultConnection": "Server=(localdb)\\mssqllocaldb;Database=EnforcaDb;Trusted_Connection=true;"
}
}
For email verification functionality, add to appsettings.json
:
{
"EmailSettings": {
"FromEmail": "[email protected]",
"FromName": "Enforca App",
"SmtpHost": "smtp.gmail.com",
"SmtpPort": 587,
"Username": "[email protected]",
"Password": "your-app-password"
}
}
dotnet restore
# Install EF Core tools (if not already installed)
dotnet tool install --global dotnet-ef
# Create and apply migrations
dotnet ef migrations add InitialCreate --project Infrastructure --startup-project Web
dotnet ef database update --project Infrastructure --startup-project Web
cd Web
dotnet run
The API will be available at:
- HTTPS: https://localhost:7001
- HTTP: http://localhost:5000
- Swagger UI: https://localhost:7001/swagger
POST /api/auth/register
- User registrationPOST /api/auth/login
- User loginPOST /api/auth/verify-email
- Email verificationPOST /api/auth/resend-verification
- Resend verification code
GET /api/users/profile
- Get user profile (authenticated)PUT /api/users/profile
- Update user profile (authenticated)
POST /api/auth/register
Content-Type: application/json
{
"fullName": "John Doe",
"email": "[email protected]",
"password": "SecurePassword123!"
}
POST /api/auth/login
Content-Type: application/json
{
"email": "[email protected]",
"password": "SecurePassword123!"
}
POST /api/auth/verify-email
Content-Type: application/json
{
"email": "[email protected]",
"code": "123456"
}
Column | Type | Description |
---|---|---|
Id | uniqueidentifier | Primary key |
FullName | nvarchar(100) | User's full name |
nvarchar(255) | User's email (unique) | |
PasswordHash | nvarchar(500) | Hashed password |
IsEmailVerified | bit | Email verification status |
CreatedAt | datetime2 | Creation timestamp |
UpdatedAt | datetime2 | Last update timestamp |
Column | Type | Description |
---|---|---|
Id | uniqueidentifier | Primary key |
UserId | uniqueidentifier | Foreign key to Users |
Code | nvarchar(6) | Verification code |
CreatedAt | datetime2 | Creation timestamp |
ExpiresAt | datetime2 | Expiration timestamp |
IsUsed | bit | Usage status |
dotnet ef migrations add YourMigrationName --project Infrastructure --startup-project Web
dotnet ef database update --project Infrastructure --startup-project Web
dotnet test
Domain/
βββ Entities/ # Domain entities (User, VerificationCode)
βββ Interfaces/ # Repository interfaces
βββ Enums/ # Domain enums
Application/
βββ DTOs/ # Data Transfer Objects
βββ Services/ # Application services
βββ Interfaces/ # Service interfaces
βββ Mappings/ # AutoMapper profiles
Infrastructure/
βββ Data/ # DbContext and configurations
βββ Repositories/ # Repository implementations
βββ Services/ # Infrastructure services (Email, etc.)
βββ Migrations/ # EF Core migrations
Web/
βββ Controllers/ # API controllers
βββ Middleware/ # Custom middleware
βββ Extensions/ # Service extensions
- Password Hashing - Secure password storage with bcrypt
- JWT Tokens - Stateless authentication
- Email Verification - Account security through email confirmation
- Input Validation - Comprehensive request validation
- CORS Configuration - Cross-origin request handling
- Uses SQL Server LocalDB
- Detailed error messages
- Swagger UI enabled
- Configure production database connection
- Set up proper email service (SendGrid, etc.)
- Enable HTTPS enforcement
- Configure logging
- Fork the repository
- Create a feature branch (
git checkout -b feature/amazing-feature
) - Commit your changes (
git commit -m 'Add amazing feature'
) - Push to the branch (
git push origin feature/amazing-feature
) - Open a Pull Request
This project is licensed under the MIT License - see the LICENSE file for details.
Francis Gbohunmi
- GitHub: @francisgbohunmi
- Email: [email protected]
- Built with .NET 8 and Entity Framework Core
- Clean Architecture principles
- RESTful API best practices
β If you found this project helpful, please give it a star!