Skip to content

About

Clean Architecture Template WebApi with Angular front end

Topics

Resources

Stars

0 stars

Watchers

0 watching

Forks

Repository files navigation

Build

Clean Architecture WebApi, Angular front end

Clean Architecture starter for .NET 10 It is simplified and modified version based on concept taken from Clean.Architecture.Solution.Template

Differences:

  • Added Angular front end with user login and to-dos interfaces (WebApi and frontEnd works on different ports)
  • No MediatR (WolverineFx used)
  • No AutoMapper (refactored code)
  • No Aspire stack
  • No NUnit (XUnit used)
  • Functional tests are using TestContainers in order to run on GitHub test actions
  • Fixes & refactoring
  • Api rate limiter added
  • HybridCache added

What's included in the template?

  • Shared project with common Domain-Driven Design abstractions.
  • Domain layer with sample entities and domain events.
  • Application layer with abstractions for:
    • CQRS (lightweight, WolverineFx command/query handlers)
    • Example use cases (Todos,WeatherForecasts and Users)
    • Cross-cutting concerns (logging, validation) implemented as decorators
    • Commands change data that cached queries are built from, so drop the cache once they succeed.
  • Infrastructure layer with:
    • JWT authentication with refresh tokens (with token rotation)
    • Permission-based authorization
    • EF Core + PostgreSQL
  • Web.Api layer with:
    • Minimal API endpoints
    • OpenTelemetry tracing and metrics (ASP.NET Core, HTTP, Npgsql, runtime)
    • Global exception handling and ProblemDetails
    • Scalar API reference (OpenAPI) with JWT support
    • Rate limiter
  • ClientApp (Angular, src/ClientApp) with:
    • Login page and route guard for the protected pages
    • To-dos page: add and delete lists (with a colour), add, complete and delete items, and set item priority
    • HTTP interceptor that attaches the bearer token and refreshes it once on a 401
    • Token storage in localStorage
    • Dev server proxy for /api (proxy.conf.json), so no CORS setup is needed
    • Unit tests with Vitest (ng test)
  • Testing projects
    • Functional testing (Application.FunctionalTests)
    • Unit testing (Application.UnitTests)
    • Domain testing (Domain.UnitTests)
  • CI (GitHub Actions, .github/workflows/build_and_test.yml) with a .NET build/test job and a separate ClientApp test job

Getting started

Run docker and create container for local development with Postgres

Run docker-compose up -d to pull and start postgress db

Build

Run dotnet build to build the solution.

Run

To run the application:

dotnet run --project .\src\Web

The application expects PostgreSQL on 127.0.0.1:5432, configured in src\Web\appsettings.json. The API reference is served at /scalar.

Client app (Angular)

The Angular client lives in src/ClientApp and calls the WebApi through /api. In development, ng serve forwards /api to the WebApi (proxy.conf.json), so no CORS setup is needed for the client.

Both services must run:

  1. WebApi on http://localhost:5117 (Terminal 1):
    dotnet run --project .\src\Web --launch-profile http
  2. Angular client on http://localhost:3000 (Terminal 2):
    cd src\ClientApp
    npm install
    npm start

Open http://localhost:3000 and sign in. The development database is seeded with administrator@localhost / Administrator1!. The client stores the bearer tokens in localStorage and refreshes them on a 401.

The WebApi can also be called directly, for example from the Scalar reference at http://localhost:5117/scalar or from Web.http.

Client build and tests:

cd src\ClientApp
npm run build
npm test -- --watch=false

Test

The solution contains unit, integration, and functional tests.

To run the tests:

dotnet test

The functional tests start their own PostgreSQL container with Testcontainers, so Docker must be running. The container is created once per test run, and tables are reset between tests. No local PostgreSQL server is needed.

About

Clean Architecture Template WebApi with Angular front end

Topics

Resources

Stars

0 stars

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages