This project is an assignment trying to mimic a simplified version of an Insurance Claim System that manages customer claims.
The system should:
- Allow customers to file claims online.
- Store claims in a database.
- Process claims and assign them a status (e.g., Pending, Approved, Rejected).
- Provide an API to retrieve claims by their status.
This project repository is aspired based on Vertical slice architecture in .NET 8 by Nadirbad.
- ASP.NET API with .NET 8
- CQRS with MediatR
- FluentValidation
- Entity Framework Core 8
- Ardalis Result and Ardalis Result FluentValidation to behave as a standard Result wrapper type.
- xUnit, FluentAssertions, Bogus
- MudBlazor
Afterwards, the API project architecture is refactored towards the Vertical slice architecture style.
Since the timeline is only 4 days for 3 parts (API, Test and Web), I wanted to create a simple API solution that focuses on the feature. The API architecture should be as simple as possible to anyone can quickly understand the logic. So I choose the vertical slices architecture style, an type of architecture that help us focus more on the business logic rather than the technical layers.
Vertical slice architecture makes us stop thinking about horizontal layers and start thinking about vertical slices and organize code by Features. When the code is organized by feature you get the benefits of not having to jump around projects, folders and files. Things related to given features are placed close together.
When moving towards the vertical slices we stop thinking about layers and abstractions. The reason is the vertical slice doesn't necessarily need shared layer abstractions like repositories, services, controllers. We are more focused on concrete behavior implementation and what is the best solution to implements.
The solution template is broken into 3 projects:
ASP.NET Web API project is an entry point to the application. It contains all the controller and domain logic for handling the claim management system.
- Database: To initialize and configure a DbContext instance. Also containing some seed data in OnModelCreating override method.
- Domain: Contain the Claim model.
- Extensions: To contain the configuration for Database, CORS, validation and other services,...
- Features: Contain the controller and the claim endpoint logic. Each endpoint is splited into a separate folder. You can see that the logic handler and the validation will be owned for each endpoint. This make any newcomers who just seen the project can get used to understand the project quickly.
Vertical slice architecture allow us to write the test easily for each layers. In the project, I had write a bunch of integration tests for the Claim endpoints. In each integration test, a clone of API will be create using WebApplicationFactory. Any requests that need to input personal information will be fake by Bogus.Faker.
This project's using ASP.NET Blazor Webassembly framework. I'm also using MudBlazor library to have better visualization on the component without much effort on CSS.
- Install the latest .NET 8 SDK
- Navigate to
InsuranceClaimSystem.APIand rundotnet runto launch the back end (ASP.NET Core Web API) or viadotnet run --project .\InsuranceClaimSystem.API\InsuranceClaimSystem.API.csproj - Open new powershell terminal, navigate to
InsuranceClaimSystem.Weband rundotnet runto launch the front end (ASP.NET Blazor Webassembly app) or viadotnet run --project .\InsuranceClaimSystem.Web\InsuranceClaimSystem.Web.csproj - To run integration test, navigate to
InsuranceClaimSystem.Api.Testsand rundotnet runto launch, or viadotnet run --project .\InsuranceClaimSystem.API.Tests\InsuranceClaimSystem.API.Tests.csproj
CLI commands executed from the root folder.
# build
dotnet build
# run
dotnet run --project .\InsuranceClaimSystem.API.\InsuranceClaimSystem.API.csproj
# launch website
dotnet run --project .\InsuranceClaimSystem.Web\InsuranceClaimSystem.Web.csproj
# run tests (required database up and running)
dotnet test tests/InsuranceClaimSystem.API.Tests/InsuranceClaimSystem.API.Tests.csproj
# publish API
dotnet publish src/InsuranceClaimSystem.API/InsuranceClaimSystem.API.csproj --configuration Release To run API locally, for example to debug them, you can use the VS Code (just open and press F5) or other IDE (VisualStudio, Rider). By default the project uses in-memory database.
To run the project from the terminal
dotnet run --project .\InsuranceClaimSystem.API.\InsuranceClaimSystem.API.csprojand you'll be good to go everything will be up and running. Go the the indicated URL http://localhost:5252/swagger and you'll see the API Swagger UI.
The project is configured to use an in-memory database by default.
This project is simplified due to shortage of time. But in the end, there still be several things to be concerned and improve later.
- Using real database instead of the in-memory version.
- Validation and unit test for domain model.
- API authorization and authentication.
- Pagination for getAllClaims endpoint.
- Caching.
- Security concern following OWASP.
- Complexity when a new feature added.