This project was created using the template from Clean Architecture Template, and will be redone once github templates allows variable names in templates. Discussion
To debug or run the api locally use
dotnet watch run --launch-profile "https"e.g.
curl -X 'GET' \
'https://localhost:7104/api/Employee/GetEmployee?employeeId=1' \
-H 'accept: application/json'There is a Dockerfile and a docker-compose.yml in the root directory. The DockerFile can be build with:
docker build .The compose file starts five services:
- api – ASP.NET Core application.
- db – PostgreSQL 17 with SSL.
- pgadmin – Web UI for Postgres.
- seq – Centralised structured log server.
- jaeger – Distributed tracing system.
Start / Shutdown these services with
docker compose up -d
docker compose downSeq captures and can query structures logs.
Jaeger displays distributed traces.
docker-compose.yml+docker-compose.override.yml– default local-dev stack (override is loaded automatically).docker-compose.dev.yml– adds optional developer tooling (e.g. ).docker-compose.prod.yml– production-only tweaks (harder restart policies, resource limits, etc.).
# development
docker compose -f docker-compose.yml -f docker-compose.prod.yml up -d
# production
docker compose -f docker-compose.yml -f docker-compose.dev.yml up -dto run the developement stack.
All Tests can be run by chaning the working directory of the unit or integration tests and then using the command:
Applying the [Trait] attribute at the class level allows, that every test method in that class can be run seperatly.
Example to run individual test parts:
dotnet test --filter "category=application"cd tests/IntegrationTests
dotnet test --logger "console;verbosity=detailed"cd tests/UnitTests
dotnet test --logger "console;verbosity=detailed"Code Coverage is generated from unittests and integrationtests and merged into a report via GitHub Actions using the ReportGenerator tool.
The testsuite contains a postman collection that can be used via the postman application or its vscode extension. In .extras/postman.
The testsuite also contains a .http file with environments pre configured. In .extras/client you can either use the vscode extension Rest-Client or the built in feature from VS2022.
This project includes data derived from:
- Northwind PostgreSQL SQL Dump
- Original source: Northwind PostgreSQL Sample on GitHub
- License: MIT
- Author: Pierre THOMAS
This project supports a dual-mode setup for PostgreSQL using Docker Compose:
- Setup Mode (with root access): Use this to perform initial configuration, set permissions, and prepare mounted volumes.
- Production Mode (with TLS and
postgresuser): Use this mode for secure, day-to-day database operations.
Before starting the container for the first time:
-
Create the directory
C:/DockerVolumes/postgres/tlsmkdir C:\DockerVolumes\postgres\tls
-
Place your SSL certificate and key inside:
certificate.crtkey.pem
copy .\.extras\tls\certificate.crt C:\DockerVolumes\postgres\tls\ copy .\.extras\tls\key.pem C:\DockerVolumes\postgres\tls\
-
Create the directory
C:/DockerVolumes/postgres/sql/northwindmkdir C:\DockerVolumes\postgres\tls
-
Place the .sql files from
.extras/db/postgres/sqlinside:create-db-northwind.sqlcreate-schema-northwind.sqlnorthwind.sql
copy .\.extras\db\postgres\sql\create-db-northwind.sql C:\DockerVolumes\postgres\sql\northwind\ copy .\.extras\db\postgres\sql\create-schema-northwind.sql C:\DockerVolumes\postgres\sql\northwind\ copy .\.extras\db\postgres\sql\northwind.sql C:\DockerVolumes\postgres\sql\northwind\
These files are mounted read-only into the container and required for PostgreSQL to start with SSL.
All configuration files are located under:
.extras/db/postgres/
Use this mode to fix file ownership and permissions. This runs the container without TLS and as the root user.
cd .extras/db/postgres/
docker compose up --buildThis uses only docker-compose.yml and ignores docker-compose.override.yml.
Open a Shell Inside the Container
docker compose exec db bashYou should now see a root@postgres prompt.
Run Setup Commands
chown postgres:postgres /var/lib/postgresql/tablespace
chown postgres:postgres /var/lib/postgresql/tablespace/northwind
chown postgres:postgres /var/lib/postgresql/key.pem
chown postgres:postgres /var/lib/postgresql/certificate.crt
chmod 400 /var/lib/postgresql/key.pem
chmod 400 /var/lib/postgresql/certificate.crt
exitStop the Container
docker compose downNow that setup is complete, start the database securely using TLS and the postgres user.
Start the Container in Production Mode
docker compose -f docker-compose.yml upThis automatically combines docker-compose.yml and docker-compose.override.yml.
Open a Shell Inside the Container
docker compose exec db bashYou should now be logged in as postgres@postgres.
Run SQL Initialization Scripts
psql --dbname=postgres --username=postgres --file=/sql/create-db-northwind.sql
psql --dbname=northwind --username=postgres --file=/sql/create-schema-northwind.sql
psql --dbname=northwind --username=postgres --file=/sql/northwind.sql
exitStop the Container When Done
docker compose downSwitching Modes Setup Mode: Use --no-override to ignore the secure config:
docker compose upProduction Mode: Just run:
docker compose -f docker-compose.yml upThis flexible dual-mode approach allows for secure database operations while preserving the ability to make low-level system changes when necessary.
After setting up the database dotnet ef migrations can be generated using these commands
dotnet ef database update --project src/Infrastructure --startup-project src/Apidotnet ef dbcontext scaffold \
Npgsql.EntityFrameworkCore.PostgreSQL \
--output-dir Entities \
--context-dir Context \
--context NorthwindContext \
--project src/Infrastructure \
--startup-project src/Api \
--namespace Infrastructure.entity \
--context-namespace Infrastructure.context \
--schema northwind \
--use-database-names \
--no-onconfiguring \
--forceCI/CD is handled with Github Actions see the workflows in .github/workflows.
Using the .editorconfig file all projects can be formatted using
cd dotnet format .\__Northwind__.sln --verbosity diagnosticThis repo ships with a pre-commit hook in .githooks/pre-commit. Enable it once per clone by running
git config core.hooksPath .githooksto enable the hook after cloning the project. Git Hooks The pre-commit checks for formatting/ linting and also if the solution compiles and can be build without errors.