A clean and modular banking web API built using .NET 5, Hexagonal Architecture, and key open-source tools like Dapper, PostgreSQL, AutoMapper, and NUnit.
BankingApp.sln
β
βββ BankingApp.WebApi/ β Driving Adapter (API)
β βββ Adapters/Input/Controllers/ β REST Controllers
β βββ Startup.cs / Program.cs
β βββ appsettings.json
β
βββ BankingApp.Application/ β Application Layer
β βββ DTOs/ β Input/Output Models
β βββ UseCases/ β Service Logic
β βββ Validation/ β Validation Logic
β βββ Ports/Input/ β Input Ports (Interfaces)
β βββ Common/ β Result wrappers
β
βββ BankingApp.Core/ β Domain Layer
β βββ Entities/ β Core domain entities
β βββ Ports/Output/ β Output Ports (Repository Interfaces)
β
βββ BankingApp.Infrastructure/ β Driven Adapter (DB)
β βββ Adapters/Output/Repositories/ β Dapper-based Repos
β βββ Config/ConnectionFactory.cs β PostgreSQL Connection Factory
β
βββ BankingApp.Tests/ β Unit Tests
β βββ UseCases/
β βββ Validation/
β βββ Adapters/Input/Controllers/
β βββ Adapters/Output/Repositories/
This project follows Hexagonal (Ports and Adapters) architecture:
- Core (Domain) β contains
EntitiesandRepository interfaces - Application β contains use cases, validation, DTOs, and input port interfaces
- Infrastructure β database interaction using Dapper and PostgreSQL
- Web API β the input adapter, exposes REST endpoints
- Tests β unit test projects for all layers using NUnit and Moq
| Layer | Stack / Tool |
|---|---|
| Framework | .NET 5 Web API |
| ORM | Dapper |
| Database | PostgreSQL |
| Mapping | AutoMapper |
| Validation | Manual + Fluent-style (custom logic) |
| Testing | NUnit + Moq |
| Logging | ILogger with file-based logging |
| Architecture | Hexagonal (Clean Ports and Adapters) |
| DI/Startup | Microsoft.Extensions.DependencyInjection |
- Create, Read, Update, Delete (CRUD) for Bank Accounts
- Validation for:
- Name, Email, Mobile, PAN, AccountNumber uniqueness
- Date of Birth presence
- Uses
Result/Result<T>pattern for uniform API responses - AutoMapper-powered mapping between DTOs and Entities
- Unit-tested business logic and validation
- Logging integrated using
ILogger<T>
dotnet test- Ensure PostgreSQL is running (e.g. via Docker or local)
- Update
appsettings.jsonwith correct DB credentials - Run the app:
dotnet run --project BankingApp.WebApiVisit Swagger at: http://localhost:5000/swagger
CREATE TABLE bank_accounts (
id UUID PRIMARY KEY,
name TEXT NOT NULL,
account_number TEXT NOT NULL UNIQUE,
email TEXT NOT NULL UNIQUE,
date_of_birth DATE NOT NULL,
nominee TEXT,
mobile_number TEXT NOT NULL UNIQUE,
pan TEXT NOT NULL UNIQUE
);A single-click .bat file can automate the entire coverage pipeline:
Want to add Docker + docker-compose for PostgreSQL and the API? Open an issue or PR!
Feel free to fork and contribute. PRs are welcome!
This project is licensed under the MIT License.