This repository serves as a robust starting point for building .NET Web APIs. It comes pre-configured with essential components to jumpstart your development, following Clean Architecture principles.
- Clean Architecture: Organized into Domain, Application, Infrastructure, and WebApi layers.
- Database: Pre-configured PostgreSQL connection with Entity Framework Core.
- Identity: Built-in authentication system (JWT in Secure HttpOnly cookies).
- Security: Automated auditing, secure cookie management, and user context abstraction.
- Containerization: Ready-to-use
Dockerfileanddocker-composesetup. - Tooling: Includes initialization scripts to rename the project and set up ports automatically.
Before you begin, ensure you have the following installed:
Follow these simple steps to set up your new project:
Fork this repository or clone it directly to your local machine:
git clone <your-repo-url>
cd web-api-templateThis template includes scripts to rename the project (from "MyProject" to your desired name) and configure ports. It will also restore local .NET tools (like dotnet-ef).
For macOS / Linux:
chmod +x init.sh
./init.shFor Windows (PowerShell):
.\init.ps1What the script does:
- Asks for your Project Name (e.g.,
MyAwesomeApi). - Asks for a Base Port (default
13000).- API will run on
Base Port + 2(e.g.,13002). - Database will run on
Base Port + 4(e.g.,13004).
- API will run on
- Renames all files, directories, and namespaces in the solution.
- Updates
docker-compose.local.ymland configuration files with the new ports. - Restores local .NET tools (ensures
dotnet-efis available). - (Optional) Creates a fresh initial Entity Framework migration.
Once initialized, you can start the entire infrastructure (API + Database) using Docker Compose:
docker compose -f docker-compose.local.yml up -dThe API will be available at http://localhost:<API_PORT> (e.g., http://localhost:13002).
The Scalar API reference can be accessed at http://localhost:<API_PORT>/scalar/v1 (in development).
- src/MyProject.Domain: Contains enterprise logic and entities.
- src/MyProject.Application: Contains application logic, interfaces, and DTOs.
- src/MyProject.Infrastructure: Contains implementation of interfaces (EF Core, Caching, Cookies, Identity).
- src/MyProject.WebApi: The entry point of the application (Controllers, Middleware).
Note: When running the API in the
Developmentconfiguration, the application automatically applies any pending migrations on startup.
If you chose not to run migrations during initialization, or need to add new ones later:
- Ensure the database container is running.
- Restore local tools (if you haven't already):
dotnet tool restore
- Run the following command from the root directory:
dotnet ef migrations add <MigrationName> --project src/<YourProjectName>.Infrastructure --startup-project src/<YourProjectName>.WebApi --output-dir Features/Postgres/Migrations
dotnet ef database update --project src/<YourProjectName>.Infrastructure --startup-project src/<YourProjectName>.WebApi