Clean-architecture recipe API (ASP.NET Core 10 + EF Core + PostgreSQL) with a React 19 / Vite frontend.
RecipeManager/
RecipeManager.Domain/ entities, guard clauses
RecipeManager.Application/ use cases, validators (FluentValidation/FluentResults)
RecipeManager.Infrastructure/ EF Core DbContext, migrations
RecipeManager.Api/ controllers, DI/startup, Swagger
RecipeManager.UnitTests/ xUnit + NSubstitute
RecipeManager.IntegrationTests/ xUnit + WebApplicationFactory (PostgreSQL via Testcontainers)
recipe-manager-frontend/ React 19 + Vite + CSS Modules
| Tool | Version | Notes |
|---|---|---|
| .NET SDK | 10.0 | All projects target net10.0. Pinned in RecipeManager/global.json with rollForward: latestFeature. |
| PostgreSQL | 16 or newer | Accessed via Npgsql. Default host/port localhost:5432. |
| Docker | any current version | Only needed for the integration tests, which start a real PostgreSQL container (ADR-017). Without it they are reported as skipped and everything else still runs. |
| Node.js | 20.19+ or 22.12+; 24 recommended | Only needed for the frontend. engines declares ^20.19.0 || >=22.12.0, the floor Vite 8 itself requires; recipe-manager-frontend/.nvmrc pins 24, which is what CI installs and what the project is tested on. nvm use in that folder picks it up. |
Install on Windows:
winget install Microsoft.DotNet.SDK.10winget install PostgreSQL.PostgreSQL.18 --interactivewinget install OpenJS.NodeJS.LTSOpen a new terminal afterwards so PATH picks up the new tools.
Run everything below from the RecipeManager/ folder (the one holding RecipeManager.sln).
dotnet restore RecipeManager.slndotnet build RecipeManager.slnCode style is part of the build (ADR-020). The root .editorconfig makes formatting (IDE0055), unused usings
(IDE0005), and block-scoped namespaces (IDE0161) build errors. When one fires, let the tool fix it:
dotnet format RecipeManager.slnRun this once per clone so git blame skips the one-off reformat commit and shows who really wrote each line
(GitHub's blame view does this automatically):
git config blame.ignoreRevsFile .git-blame-ignore-revsProgram.cs applies EF migrations at startup (app.MigrateDatabase()), so the API creates and updates
the schema on first run — but it will fail to start if PostgreSQL is not reachable.
Create the role and database once (run from an elevated-enough shell; you'll be prompted for the
postgres superuser password set during install):
& "C:\Program Files\PostgreSQL\18\bin\psql.exe" -U postgres -c "CREATE ROLE recipemanager LOGIN PASSWORD 'your-password';"& "C:\Program Files\PostgreSQL\18\bin\createdb.exe" -U postgres -O recipemanager DbRecipeManagerRecipeManager.Api/appsettings.json holds a password-less template:
Host=localhost;Port=5432;Database=DbRecipeManager;Username=recipemanager;Timeout=90
Supply the password locally via user-secrets so it never reaches git (the API project already has a
UserSecretsId):
dotnet user-secrets --project RecipeManager.Api set "ConnectionStrings:DefaultConnection" "Host=localhost;Port=5432;Database=DbRecipeManager;Username=recipemanager;Password=your-password"In deployment, override the same key with the ConnectionStrings__DefaultConnection environment variable.
To apply migrations manually instead of at startup:
dotnet tool install --global dotnet-efdotnet ef database update --project RecipeManager.Infrastructure --startup-project RecipeManager.Apidotnet run --project RecipeManager.Api --launch-profile https- HTTPS:
https://localhost:7231(Swagger UI at/swagger) - HTTP:
http://localhost:5249
Trust the local HTTPS certificate once, otherwise the browser and the Vite proxy will reject it:
dotnet dev-certs https --trustdotnet test RecipeManager.sln315 tests: 212 unit and 103 integration. Of the 103, 99 start a real PostgreSQL container (ADR-017) and the
other 4 (OpenApiContractTests, ADR-019) need no database at all. With Docker running you get 315 passed;
without it you get 216 passed and 99 skipped, each naming Docker as the reason. The skip is deliberate — see
the troubleshooting entry below — but it means a green run is only as complete as its skip count says. On a
Windows machine with Smart App Control enabled, the 4 contract tests do not skip — they fail with
FileLoadException, the same way the 99 integration tests do. On such a machine, run the backend in WSL2
instead — see Windows with Smart App Control.
The "with Docker" figure is confirmed by CI run 38144909040 (2026-10-11, R-22 PR 1): 212 unit + 103 integration
passed, 0 skipped — and reproduced locally inside WSL2 the same day against feat/cook-log. CI remains the authority for what merges; a WSL2 run is a faithful local reproduction of it, a native
Windows run under Smart App Control is not.
Unit tests with an HTML coverage report (requires dotnet tool install --global dotnet-reportgenerator-globaltool):
pwsh ./run-coverage.ps1cd recipe-manager-frontendnpm installnpm run devServes on http://localhost:3000 — the origin the API's CORS policy (AllowReactApp) allows, so don't
change the port without updating RecipeManager.Api/Startup/ServiceInitializer.cs.
.env.development points VITE_API_URL at https://localhost:7231/api. Delete or blank that variable to
fall back to the relative /api path, which vite.config.ts proxies to the same backend.
Start the API first — the frontend has no mock backend.
CI runs these on every pull request (see Continuous integration); run them locally first anyway, since a failure found in seconds beats one found on a runner.
npm run lintnpm run buildnpm run build type-checks src/ and vite.config.ts (tsc -b tsconfig.json tsconfig.node.json) before
Vite bundles anything, so a type error fails it. For a faster
loop while working, npm run typecheck runs the same check without producing dist/. npm test runs the
Vitest suite once; npm run test:watch re-runs on save.
The TypeScript types in src/types/generated/api.ts are generated from RecipeManager/contracts/openapi.json,
which is itself a snapshot of the API's OpenAPI document (ADR-019). After changing a DTO, a route, or a status
code, regenerate both, from RecipeManager/:
UPDATE_OPENAPI_SNAPSHOT=1 dotnet test --filter OpenApiContractTeststhen from RecipeManager/recipe-manager-frontend/:
npm run gen:apiand commit both files. CI fails if either is stale. On PowerShell, set the variable with
$env:UPDATE_OPENAPI_SNAPSHOT='1' and remove it afterwards.
If the snapshot test cannot run on your machine at all — Windows with Smart App Control enabled blocks it the
same way it blocks the integration tests, see Troubleshooting — first prefer running the
snapshot update inside WSL2, then committing
contracts/openapi.json there and pulling it into the Windows clone before npm run gen:api. Without WSL2, there
is a second route that needs no local test run:
- Push the change and let CI's Backend job fail on
OpenApiContractTests. - Download the
openapi-receivedartifact it uploads on that failure:gh run download <run-id> -n openapi-received
- Copy the downloaded
openapi.received.jsonoverRecipeManager/contracts/openapi.json. - Run
npm run gen:apifromRecipeManager/recipe-manager-frontend/as above, and commit both files.
Either route ends the same way: contracts/openapi.json and src/types/generated/api.ts committed together.
src/types/recipe.ts only aliases the generated schemas — never add a field there by hand.
The recommended route on a Windows machine with Smart App Control on. Smart App Control checks every
executable image Windows loads, and a freshly built, unsigned DLL has no reputation, so it blocks them
intermittently (see Troubleshooting). Docker alone does not help: Testcontainers puts only
PostgreSQL in a container, while the test host still loads this repo's DLLs on Windows. The dotnet process
itself has to run on Linux. WSL2 does that, and its loader is not subject to Windows code integrity — the same
reason CI never sees the problem.
The layout: a second clone inside the WSL filesystem runs dotnet build, test, and run; the existing Windows
clone keeps running Node and Vite; Docker Desktop provides Docker to both. With mirrored networking the two share
localhost, so nothing in the repo's configuration changes.
Verified on 2026-10-02 against main @ 01eeccc on Ubuntu 24.04, Docker Desktop 4.93: dotnet build 0 warnings,
dotnet test 192 passed / 0 skipped, and the SPA served from Windows loading recipes from the API in WSL2.
Steps marked (admin) need an elevated PowerShell; (reboot) means restart Windows afterwards.
1. Install WSL2 — (admin) (reboot). In PowerShell:
wsl --install -d Ubuntu-24.04If after the reboot wsl -l -v says there are no installed distributions, only the engine half finished. Run the
same command again from a normal PowerShell (installing the distribution needs neither admin nor a reboot); add
--web-download if the Store download stalls. Ubuntu 24.04 rather than a newer release: it is the one tested here.
2. Mirrored networking. Mirrored mode makes WSL and Windows share localhost: the API in WSL reaches Windows
PostgreSQL at localhost:5432, and the browser on Windows reaches the API at localhost:7231. Write the config
file with an explicit encoding — Windows PowerShell's > writes UTF-16, which WSL cannot read:
Set-Content -Path "$env:USERPROFILE\.wslconfig" -Value "[wsl2]`nnetworkingMode=mirrored" -Encoding asciiwsl --shutdownip -4 -br addr inside Ubuntu should now show your Windows LAN address, not a 172.x NAT one.
3. Docker Desktop — (admin). In PowerShell, not in Ubuntu:
winget install Docker.DockerDesktopIn Docker Desktop, Settings → Resources → WSL integration: enable Ubuntu-24.04 and Apply & restart. Do
not install a Docker engine inside Ubuntu (apt install docker.io); it would compete with Docker Desktop for the
socket. If docker version in Ubuntu then shows permission denied … /var/run/docker.sock, check
getent group docker: if your user is listed, the shell simply predates the group change — run
wsl --terminate Ubuntu-24.04 from PowerShell and reopen Ubuntu; if it is not, sudo usermod -aG docker $USER
first. Membership of docker is root-equivalent inside the distribution, which is the accepted norm for a
single-user development VM.
4. Clone inside the Linux filesystem — in Ubuntu, under ~, never under /mnt/c (that is the Windows disk
again, slow and subject to the same policy):
sudo apt update && sudo apt install -y git curl libicu74mkdir -p ~/src && cd ~/src && git clone https://github.com/guillerlp/RecipeManager.gitTo push from WSL with your Windows Git credentials:
git config --global credential.helper "/mnt/c/Program\ Files/Git/mingw64/bin/git-credential-manager.exe"5. .NET SDK, exactly as global.json asks. Do not use Ubuntu's apt package: Canonical builds .NET from
source, and source-built SDKs ship only in the 1xx feature band, which global.json's 10.0.302 with
rollForward: latestFeature refuses. Microsoft's install script reads global.json the way CI's setup-dotnet
does:
curl -sSL https://dot.net/v1/dotnet-install.sh -o ~/dotnet-install.sh && bash ~/dotnet-install.sh --jsonfile ~/src/RecipeManager/RecipeManager/global.jsonprintf '\nexport DOTNET_ROOT="$HOME/.dotnet"\nexport PATH="$DOTNET_ROOT:$DOTNET_ROOT/tools:$PATH"\n' >> ~/.profile && source ~/.profile~/.profile, not ~/.bashrc: Ubuntu's .bashrc returns early in non-interactive shells, so
wsl -- bash -lc "dotnet test" run from Windows would not find dotnet.
6. The database password. User-secrets live in ~/.microsoft/usersecrets/ on Linux, so the Windows ones are
not seen. Copy the Windows file rather than typing the password again — nothing to mistype, nothing in shell
history:
d=~/.microsoft/usersecrets/3fd489a5-aeb3-47b7-bb4b-1fcf640ac7cc && mkdir -p "$d" && cp /mnt/c/Users/<windows-user>/AppData/Roaming/Microsoft/UserSecrets/3fd489a5-aeb3-47b7-bb4b-1fcf640ac7cc/secrets.json "$d/" && chmod 600 "$d/secrets.json"The two copies drift apart if the password ever changes; copy again when it does.
7. The HTTPS certificate. The SPA calls https://localhost:7231 directly from the browser
(VITE_API_URL in recipe-manager-frontend/.env.development), so the Windows browser must trust whatever
certificate the API in WSL serves. Reuse the one Windows already trusts. In PowerShell:
dotnet dev-certs https --export-path "$env:USERPROFILE\rm-devcert.pfx" --password "<throwaway>"Then in Ubuntu — --import is only accepted together with --clean, which removes the certificate the SDK
generated on first run so Kestrel has exactly one to choose:
dotnet dev-certs https --clean --import /mnt/c/Users/<windows-user>/rm-devcert.pfx -p "<throwaway>" && rm /mnt/c/Users/<windows-user>/rm-devcert.pfxdotnet dev-certs https --check in Ubuntu and dotnet dev-certs https --check --trust in PowerShell must print
the same thumbprint.
Daily use. From ~/src/RecipeManager/RecipeManager in Ubuntu, the usual commands — dotnet build RecipeManager.sln, dotnet test RecipeManager.sln, dotnet run --project RecipeManager.Api --launch-profile https — and npm run dev from the Windows clone. Branches move between the two clones through git push/pull.
Never run the API on Windows and in WSL at the same time: with mirrored networking both bind localhost:7231.
.github/workflows/ci.yml runs on every pull request to main and every push to main, in two parallel jobs
on ubuntu-latest:
| Job | Steps |
|---|---|
| Backend | dotnet restore --locked-mode → dotnet build (Debug) → dotnet test (315) → upload openapi-received snapshot on failure → vulnerable-package check |
| Frontend | npm ci → contract types are current (npm run gen:api + diff check) → npm run typecheck → npm run lint → npm test → npm run build → npm audit --audit-level=high → npm audit --audit-level=high --prefix ../contracts |
Two things are worth knowing before a run surprises you:
- NuGet restores from committed lock files. Every project has a
packages.lock.json, and CI restores in locked mode. Change a package version and CI fails withNU1004until you rundotnet restore RecipeManager.sln --force-evaluateand commit the updated lock files. - CI builds Debug on purpose. A Release build makes every integration test fail: the
IntegrationTestenvironment throws in RELEASE builds by design, andWebApplicationFactoryuses that environment name. See ADR-005 and ADR-013.
The checks are not yet required to merge — that is a branch-protection setting on main.
RecipeManager.Api/Dockerfile builds the API alone (no database container). Build from the RecipeManager/
folder so the COPY paths resolve:
docker build -f RecipeManager.Api/Dockerfile -t recipemanager-api .The image needs a reachable PostgreSQL; pass the connection string via
ConnectionStrings__DefaultConnection. Note that Host=localhost resolves to the container, not your
machine — use host.docker.internal (Docker Desktop) or a compose service name instead.
You must install or update .NET to run this application / Framework 'Microsoft.NETCore.App', version 'X' not found
The solution built, but the matching runtime is missing. Install the .NET 10 SDK (above); dotnet --list-runtimes
should show a 10.x entry for both Microsoft.NETCore.App and Microsoft.AspNetCore.App.
API throws on startup with a Npgsql connection or authentication error
PostgreSQL is not running, or the credentials are wrong. Check the service with
Get-Service postgresql* in PowerShell, and confirm the password is set in user-secrets — the template in
appsettings.json deliberately has none.
relation "recipes" does not exist when querying in psql
PostgreSQL folds unquoted identifiers to lowercase, and EF creates the tables as "Recipes" and
"RecipeIngredients". Quote them: SELECT * FROM "Recipes";,
SELECT * FROM "RecipeIngredients" ORDER BY "Position";
Frontend requests fail with a certificate error
Run dotnet dev-certs https --trust.
The 46 integration tests are reported as skipped
Docker is not running or not installed. The integration tests start a PostgreSQL container (ADR-017), and
without a Docker endpoint they skip rather than fail, so the unit tests still give a usable result. The skip
message names the endpoint it tried, e.g. npipe://./pipe/docker_engine on Windows. Start Docker Desktop and
re-run, or rely on CI, which always has Docker.
dotnet run fails with "An Application Control policy has blocked this file"
A Windows Application Control policy (Smart App Control is a common source) refused to start
RecipeManager.Api\bin\Debug\net10.0\RecipeManager.Api.exe — the unsigned launcher the SDK generates for every
build. The code is fine. Run through the signed dotnet host instead, which skips generating that .exe:
dotnet run --project RecipeManager.Api --launch-profile https -p:UseAppHost=falseChanging the Application Control policy also works, but it is a machine-wide security setting — prefer the flag.
The same policy can also block the integration tests: every one fails with
FileLoadException … An Application Control policy has blocked this file. (0x800711C7) on
RecipeManager.IntegrationTests\bin\Debug\net10.0\RecipeManager.Api.dll. Here the flag does not help — the
blocked file is the DLL, not the launcher. This includes OpenApiContractTests (ADR-019): those 4 tests need no
Docker, but they still boot the API, so they fail here rather than skip. The unit tests still run; for the
integration tests and the contract tests, run the backend in
WSL2 or rely on CI, which runs all of them on Linux
for every PR. If you need to accept a contract change from a machine in this state, see "Changing the API
contract" above.
It is not limited to those two cases. The policy can block any freshly-built assembly, intermittently and
without a pattern worth predicting — dotnet ef has been blocked mid-run while scaffolding a migration, which
leaves no migration file rather than a broken one. Turning Smart App Control off is irreversible on Windows —
once off, it cannot be switched back on without reinstalling the OS — and declining that trade is reasonable.
The fix is to not load these DLLs on Windows at all: run the backend in
WSL2, the recommended route, which runs the full
suite locally. A local FileLoadException on native Windows remains an environment fact, not a defect.
Fallback without WSL2 — unreliable, but sometimes enough to get the API running natively. Build non-deterministically so every DLL gets a fresh hash, skip the launcher, and run without rebuilding:
dotnet build RecipeManager.sln -p:Deterministic=false -p:UseAppHost=falsedotnet run --project RecipeManager.Api --launch-profile https --no-build -p:UseAppHost=falseIf it is blocked again, repeat both. It can take several attempts, and it never makes the suite trustworthy. Why a fresh hash sometimes gets through is not documented by Microsoft; what is certain is that the new, unsigned DLL has no more reputation than the old one, so treat this as retrying rather than fixing.