BoxCleanArchitectureApiTemplate 1.0.0
dotnet add package BoxCleanArchitectureApiTemplate --version 1.0.0
NuGet\Install-Package BoxCleanArchitectureApiTemplate -Version 1.0.0
<PackageReference Include="BoxCleanArchitectureApiTemplate" Version="1.0.0" />
<PackageVersion Include="BoxCleanArchitectureApiTemplate" Version="1.0.0" />
<PackageReference Include="BoxCleanArchitectureApiTemplate" />
paket add BoxCleanArchitectureApiTemplate --version 1.0.0
#r "nuget: BoxCleanArchitectureApiTemplate, 1.0.0"
#:package BoxCleanArchitectureApiTemplate@1.0.0
#addin nuget:?package=BoxCleanArchitectureApiTemplate&version=1.0.0
#tool nuget:?package=BoxCleanArchitectureApiTemplate&version=1.0.0
BoxCleanArchitectureApiTemplate
🌟 Overview
BoxCleanArchitectureApiTemplate is a robust ASP.NET Core Web API template built with strong Clean Architecture principles. It's designed to help developers quickly kickstart high-quality, testable, maintainable, and scalable API applications for production environments. This template integrates best practices and essential libraries to accelerate your development process.
✨ Features
- Clean Architecture Principles: Clear separation of layers (Domain, Application, Infrastructure, Presentation) for enhanced maintainability and testability.
- ASP.NET Core 8.0: Built on the latest .NET 8.0 SDK.
- JWT (JSON Web Token) Authentication: Secure authentication and authorization system using JWT for API endpoints.
- Dynamic IP Whitelist Middleware: Middleware to restrict API access based on allowed IP addresses, managed dynamically.
- Dynamic API Access Restrictions: A system to define time-based access restrictions for specific API Endpoints, manageable from the database.
- Swagger/OpenAPI Integration: Interactive API documentation via Swagger UI for easy testing and understanding of API endpoints.
- Robust Error Handling: Centralized error handling for API responses.
- Entity Framework Core: ORM for data management with SQL Server databases.
- Centralized Logging: Configured logging for easy monitoring and troubleshooting.
- MediatR: Utilized for CQRS (Command Query Responsibility Segregation) pattern and handling requests/responses.
- FluentValidation: For robust data validation.
🚀 Getting Started
1. Install the Template
Ensure you have .NET SDK version 8.0 or newer installed. Then, run the following command to install the template from the NuGet Gallery:
dotnet new install BoxCleanArchitectureApiTemplate::*
2. Create a New Project from the Template
Navigate to the folder where you want to create your new project, then run the command:
dotnet new Boxcleanapi -n MyNewAwesomeApi
After that cd [YourProjectName]
dotnet restore
dotnet build
- Replace
YourProjectNamewith your desired project name. - The template will automatically create the solution and all sub-projects, setting up namespaces and project references correctly.
3. Database Setup
Open the Solution (
YourProjectName.sln) in Visual Studio.Open the
appsettings.jsonfile in your main project (YourProjectName).Update the
ConnectionStringsto point to your SQL Server instance:"ConnectionStrings": { "DefaultConnection": "Server=YourServerName;Database=YourDatabaseName;User Id=YourUser;Password=YourPassword;TrustServerCertificate=True" },Run EF Core Migrations to create the database and schema:
# Open Terminal/PowerShell in Visual Studio or Command Prompt # Navigate to the YourProjectName.Infrastructure folder cd YourProjectName.Infrastructure dotnet ef database update
4. Run the Application
- Set your
YourProjectNameproject as the Startup Project in Visual Studio. - Press
F5or click the "Run" button in Visual Studio. - The application will start and automatically open the Swagger UI in your browser.
🔑 Security & Configuration
JWT Authentication
- Once the application is running, access the Swagger UI.
- Navigate to the Login API endpoint (e.g.,
/api/Account/Login). - Obtain a JWT Token.
- Click the "Authorize" button in the top right corner of the Swagger UI.
- In the "Value" field, type
Bearer(with a space after Bearer) and paste your JWT Token immediately after it. - Click "Authorize" to apply the token for authenticated API calls.
- Important: Ensure the token you receive has a
ClaimTypes.Roleorrolewith a value like"Admin"or an appropriate role to access restricted endpoints.
Dynamic IP Whitelist
- The IP Whitelist Middleware checks the IP Address of the client accessing the API.
- You can manage allowed IPs in the
IpWhitelisttable in your database. - Testing: Try adding your own IP address to the
IpWhitelisttable to allow API access. If there are no IP entries in the table, or your IP is on the allowed list, access will be granted.
Dynamic API Access Restrictions
- API Access Restrictions are managed in the
ApiAccessRestrictionstable in the database. - You can define
ApiPath,HttpMethod,RestrictionStartTime,RestrictionEndTime,IsActive, andReasonfor each restriction. - This middleware checks if an API call falls within a restricted time frame.
- Testing: Try adding an entry to the
ApiAccessRestrictionstable to restrict access to a specific API endpoint during certain hours.
📂 Project Structure
The project is structured following Clean Architecture principles:
YourProjectName(Presentation Layer):- The main ASP.NET Core Web API project.
- Contains Controllers, Middlewares (e.g.,
IpWhitelistMiddleware), Startup Configuration, and the Program entry point.
YourProjectName.Application(Application Layer):- Holds the core business logic of the application.
- Includes Commands, Queries, Handlers, Interfaces for Application Services, and Validations.
- References
YourProjectName.Domain.
YourProjectName.Domain(Domain Layer):- The heart of the business logic, independent of other layers.
- Contains Entities, Value Objects, Aggregates, Domain Events, and Repository Interfaces.
YourProjectName.Infrastructure(Infrastructure Layer):- Implements the Interfaces defined in the Domain and Application Layers.
- Handles Database concerns (EF Core), External Services, and Third-party Libraries.
- References
YourProjectName.Domain.
YourProjectName.TestAPI(Integration/Functional Tests):- A project dedicated to Integration or Functional Tests.
🤝 Contributing
If you have suggestions or encounter issues, please contact me.
📄 License
This template is licensed under the MIT License.
| Product | Versions Compatible and additional computed target framework versions. |
|---|---|
| .NET | net8.0 is compatible. net8.0-android was computed. net8.0-browser was computed. net8.0-ios was computed. net8.0-maccatalyst was computed. net8.0-macos was computed. net8.0-tvos was computed. net8.0-windows was computed. net9.0 was computed. net9.0-android was computed. net9.0-browser was computed. net9.0-ios was computed. net9.0-maccatalyst was computed. net9.0-macos was computed. net9.0-tvos was computed. net9.0-windows was computed. net10.0 was computed. net10.0-android was computed. net10.0-browser was computed. net10.0-ios was computed. net10.0-maccatalyst was computed. net10.0-macos was computed. net10.0-tvos was computed. net10.0-windows was computed. |
-
net8.0
- _ProjectName_.application (>= 1.0.0)
- _ProjectName_.Infrastructure (>= 1.0.0)
- AspNetCore.HealthChecks.SqlServer (>= 8.0.0)
- AspNetCore.HealthChecks.UI (>= 8.0.0)
- AspNetCore.HealthChecks.UI.Client (>= 8.0.0)
- AspNetCore.HealthChecks.UI.Core (>= 8.0.0)
- AspNetCore.HealthChecks.UI.InMemory.Storage (>= 8.0.0)
- AspNetCore.HealthChecks.Uris (>= 8.0.0)
- AspNetCoreRateLimit (>= 4.0.2)
- Microsoft.AspNetCore.Authentication.JwtBearer (>= 8.0.2)
- Microsoft.AspNetCore.Mvc.Versioning (>= 5.1.0)
- Microsoft.Extensions.Diagnostics.HealthChecks (>= 8.0.3)
- Newtonsoft.Json (>= 13.0.3)
- NWebsec.AspNetCore.Middleware (>= 3.0.0)
- Serilog (>= 4.3.0)
- Serilog.AspNetCore (>= 9.0.0)
- Serilog.Sinks.MSSqlServer (>= 8.2.2)
- Swashbuckle.AspNetCore (>= 6.4.0)
NuGet packages
This package is not used by any NuGet packages.
GitHub repositories
This package is not used by any popular GitHub repositories.
| Version | Downloads | Last Updated |
|---|---|---|
| 1.0.0 | 626 | 7/23/2025 |
Initial release of the Clean Architecture Web API Template.