A comprehensive payment system built with ASP.NET Core 10 following Clean Architecture principles. This API provides user authentication, account management, card handling, and transaction processing capabilities.
The Payment System API is a robust backend service designed to manage financial operations including:
- User Authentication & Authorization - JWT-based security with role-based access control
- Customer Management - Create and manage customer profiles
- Account Management - Multi-currency bank accounts with balance tracking
- Card Management - Debit/credit card creation and lifecycle management
- Transaction Processing - Record and query financial transactions
- Admin Dashboard - Administrative oversight and reporting
This project demonstrates enterprise-grade API design with proper separation of concerns, dependency injection, and data persistence.
The project follows Clean Architecture with four distinct layers:
-
Domain Layer (
payment-system.Domain)- Core business entities and enums
- No dependencies on other layers
- Defines the fundamental domain logic
-
Application Layer (
payment-system.Application)- Business logic and use cases
- DTOs (Data Transfer Objects)
- Repository interfaces and service interfaces
- Mapping profiles (AutoMapper)
- Security utilities
-
Infrastructure Layer (
payment-system.Infrastructure)- Database context and configurations
- Repository implementations
- Database migrations
- Security implementations (JWT, password hashing with BCrypt)
-
API Layer (
payment-system.Api)- Controllers organized by feature
- Dependency injection setup
- Middleware configuration
- Swagger/OpenAPI documentation
- Repository Pattern - Abstracts data access through interfaces
- Dependency Injection - Loose coupling and testability
- DTO Pattern - Separates internal entities from external API contracts
- CQRS-Inspired - Controllers split into Query and Command operations (where applicable)
- Service Layer Pattern - Encapsulates business logic
payment-system/
βββ payment-system.Api/ # ASP.NET Core Web API
β βββ Controllers/
β β βββ Account/ # Account operations
β β βββ Admin/ # Admin dashboard & management
β β βββ Auth/ # Authentication (Login, Register)
β β βββ Card/ # Card management
β β βββ Customer/ # Customer CRUD operations
β β βββ Transaction/ # Transaction queries & creation
β βββ Extensions/ # Dependency injection setup
β βββ Program.cs # Application entry point
β βββ appsettings.json # Configuration
βββ payment-system.Application/ # Application layer
β βββ DTOs/ # Data transfer objects
β βββ Services/
β β βββ Interfaces/ # Service contracts
β β βββ Implementations/ # Service implementations
β βββ Repositories/ # Repository interfaces
β βββ Common/
β βββ Result.cs # Standardized result wrapper
β βββ Mappings/ # AutoMapper profiles
β βββ Security/ # Security utilities
βββ payment-system.Domain/ # Domain layer
β βββ Entities/ # Core business entities
β β βββ User.cs
β β βββ Customer.cs
β β βββ Account.cs
β β βββ Card.cs
β β βββ Transaction.cs
β βββ Enums/ # Domain enumerations
β β βββ UserRole.cs
β β βββ CardStatus.cs
β β βββ TransactionType.cs
β β βββ TransactionStatus.cs
β β βββ Currency.cs
β βββ Common/
β βββ BaseEntity.cs # Base entity with common properties
βββ payment-system.Infrastructure/ # Infrastructure layer
β βββ Persistence/
β β βββ Contexts/ # Database contexts
β β βββ Configurations/ # Entity configurations
β βββ Repositories/ # Repository implementations
β βββ Security/ # Security implementations
β βββ Migrations/ # Database migrations
βββ payment-system.Tests/ # Unit & integration tests
β βββ Services/ # Test suites
βββ payment-system.slnx # Solution file
- ASP.NET Core 10 - Modern web framework for building APIs
- .NET 10.0 - Latest .NET runtime
- Entity Framework Core 10.0.3 - ORM for database operations
- SQLite 10.0.3 - Default database (development)
- SQL Server 10.0.3 - Alternative database provider
- JWT Bearer Authentication - Token-based API security
- BCrypt.Net-Next 4.1.0 - Secure password hashing
- System.IdentityModel.Tokens.Jwt 8.17.0 - JWT token generation and validation
- Swashbuckle.AspNetCore 7.0.0 - Swagger/OpenAPI integration for interactive API docs
- AutoMapper - Object-to-object mapping for DTOs
- xUnit 2.6.2 - Unit testing framework
- Moq 4.18.4 - Mocking library for unit tests
- Microsoft.NET.Test.Sdk 17.8.0 - Test SDK
- Microsoft.EntityFrameworkCore.Proxies - Lazy loading support
- Microsoft.EntityFrameworkCore.Tools - EF Core CLI tools
- .NET 10.0 SDK - Download from microsoft.com/net
- Git - Version control system
-
Clone the repository
git clone https://github.com/js-lover/payment-system.git cd payment-system -
Restore dependencies
dotnet restore
-
Apply database migrations (creates SQLite database)
cd payment-system.Infrastructure dotnet ef database update --project ../payment-system.Infrastructure --startup-project ../payment-system.Api -
Build the solution
dotnet build
cd payment-system.Api
dotnet runThe API will start at:
- HTTP:
http://localhost:5000 - HTTPS:
https://localhost:5001 - Swagger UI:
http://localhost:5000/(when using development profile)
dotnet run --project payment-system.Api- Press
F5or select Run > Start Debugging - Select .NET 5+ and .NET Core as the environment
The application configuration is managed through appsettings.json:
{
"ConnectionStrings": {
"DefaultConnection": "Data Source=PaymentSystem.db"
},
"Logging": {
"LogLevel": {
"Default": "Information",
"Microsoft.AspNetCore": "Warning"
}
},
"JwtSettings": {
"Secret": "your-secret-key-minimum-32-characters",
"Issuer": "PaymentSystemAPI",
"Audience": "PaymentSystemClients",
"ExpiryInMinutes": 60
},
"AllowedHosts": "*"
}| Setting | Purpose |
|---|---|
ConnectionStrings:DefaultConnection |
Database connection string (SQLite by default) |
JwtSettings:Secret |
Secret key for signing JWT tokens (must be β₯ 32 characters) |
JwtSettings:Issuer |
Token issuer identifier |
JwtSettings:Audience |
Intended token audience |
JwtSettings:ExpiryInMinutes |
Token validity duration in minutes |
- Development (
appsettings.Development.json) - Used during development; overrides main settings - Production - Update connection strings and JWT secret before deployment
| Method | Endpoint | Description |
|---|---|---|
| POST | /api/auth/login |
User login (returns JWT token) |
| POST | /api/auth/register |
Register new user account |
| Method | Endpoint | Description |
|---|---|---|
| POST | /api/customers |
Create new customer |
| GET | /api/customers |
Get all customers |
| GET | /api/customers/{id} |
Get customer by ID |
| DELETE | /api/customers/{id} |
Delete customer |
| Method | Endpoint | Description |
|---|---|---|
| POST | /api/accounts |
Create new account |
| GET | /api/accounts |
Get all accounts |
| GET | /api/accounts/{id} |
Get account details |
| GET | /api/accounts/{id}/balance |
Get account balance |
| GET | /api/accounts/customer/{customerId} |
Get account by customer |
| GET | /api/accounts/balance-range |
Get accounts by balance range |
| PUT | /api/accounts/{id} |
Update account |
| DELETE | /api/accounts/{id} |
Delete account |
| Method | Endpoint | Description |
|---|---|---|
| POST | /api/cards |
Create new card |
| GET | /api/cards |
Get all cards |
| GET | /api/cards/{id} |
Get card by ID |
| GET | /api/cards/account/{accountId} |
Get cards by account |
| PUT | /api/cards/{id} |
Update card |
| DELETE | /api/cards/{id} |
Delete card |
| Method | Endpoint | Description |
|---|---|---|
| POST | /api/transactions |
Create new transaction |
| GET | /api/transactions |
Get all transactions |
| GET | /api/transactions/account/{accountId} |
Get transactions by account |
| GET | /api/transactions/date-range |
Get transactions by date range |
| GET | /api/transactions/type/{type} |
Get transactions by type |
| Method | Endpoint | Description |
|---|---|---|
| GET | /api/admin/dashboard |
Get admin dashboard data |
| GET | /api/admin/admins |
Get all admin users |
| POST | /api/admin/create |
Create new admin user |
Access interactive API documentation at:
http://localhost:5000/swagger/v1/swagger.json- OpenAPI specificationhttp://localhost:5000/- Swagger UI (development only)
The API uses JWT (JSON Web Tokens) for authentication:
- Login - User provides credentials to
/api/auth/login - Token Issued - Server returns JWT token valid for 60 minutes
- Include Token - Client includes token in
Authorization: Bearer {token}header - Validation - Server validates token signature, issuer, audience, and expiration
Users have roles defined in UserRole enum:
- User - Standard user with customer and account access
- Admin - Administrative access to dashboard and user management
Authorization: Bearer {jwt-token}- Required for protected endpoints- Passwords are hashed using BCrypt with salt rounds
- Tokens require HTTPS in production (
RequireHttpsMetadata = falsefor development)
# Run all tests
dotnet test
# Run tests with coverage
dotnet test /p:CollectCoverage=true
# Run specific test class
dotnet test --filter "TestClassName=YourTestClass"
# Run tests in verbose mode
dotnet test --verbosity detailed- xUnit - Test framework for unit tests
- Moq - Mocking framework for creating mock objects
- Coverlet - Code coverage tool
Tests are located in payment-system.Tests/Services/ and follow the Arrange-Act-Assert pattern:
[Fact]
public async Task CreateAccount_WithValidData_ReturnsSuccess()
{
// Arrange
var request = new CreateAccountRequest { /* ... */ };
// Act
var result = await _service.CreateAccount(request);
// Assert
Assert.NotNull(result);
}# Publish as self-contained deployment
dotnet publish -c Release -o ./publish
# Publish as framework-dependent deployment
dotnet publish -c Release -r win-x64 -o ./publish- Automatically created from migrations
- Located at
PaymentSystem.db - Good for development and small deployments
- Update connection string in
appsettings.json - Install SQL Server or use Azure SQL Database
- Run migrations on target database
Set ASPNETCORE_ENVIRONMENT before running:
export ASPNETCORE_ENVIRONMENT=Production
dotnet run --project payment-system.Api- Monitor logs in
Logging.LogLevel - JWT token expiration should be monitored
- Database connection health should be verified
- Fork the repository - Create your own copy
- Create a feature branch -
git checkout -b feature/your-feature - Follow code standards
- Use PascalCase for classes and public methods
- Use camelCase for local variables
- Add XML documentation for public APIs
- Keep methods focused and single-responsibility
- Add/Update Tests - Ensure new features have test coverage
- Commit with clear messages -
git commit -m "Add: description of changes" - Push and create a Pull Request - Include description and related issues
- Use nullable reference types (enabled by default)
- Use async/await for I/O operations
- Prefer LINQ over loops
- Add meaningful comments for complex logic
This project is licensed under the MIT License. See the LICENSE file for details.
- Report Issues - Use GitHub Issues for bug reports
- Feature Requests - Open a GitHub Discussion
- Security Vulnerabilities - Email privately (do not create public issues)
Built with β€οΈ using ASP.NET Core