A learning project built with NestJS simulating a simplified banking system. The goal of this project is to explore clean architecture, good practices, database transactions, and modular design while implementing realistic banking operations such as deposits, withdrawals, and transfers.
-
User Management: Create and manage users with associated accounts.
-
Accounts:
- Each user can own one or more bank accounts.
- Accounts maintain a balance and unique account number (validated with the Luhn algorithm).
-
Transactions:
- Deposits: Increase balance on a destination account.
- Withdrawals: Decrease balance on a source account (validating sufficient funds).
- Transfers: Move funds between two accounts atomically.
- All operations use database transactions with locks to ensure data consistency.
-
Audit Fields: Each transaction stores who performed it (
performedBy) and supports possible reversals or references for rollback-like behavior. -
JWT Authentication: With access and refresh tokens for secure endpoints.
- Backend Framework: NestJS
- Database ORM: TypeORM
- Database: PostgreSQL
- Authentication: JWT (access & refresh tokens)
- Validation & Pipes: Class-validator + Class-transformer
- Error Handling: Custom helpers for DB errors and global exception filters
src
├── accounts/ # Account entity, service, controller
├── auth/ # Auth entity, service, controller
├── transactions/ # Transaction entity, service, controller
├── users/ # User entity, service, controller
├── roles/ # Role entity, service, controller
├── common/ # Shared modules: entities, interceptors, filters, helpers
├── app.module.ts # Root module
└── main.ts # Application bootstrap
The app requires a .env file at the project root with the following configuration:
NODE_ENV=development
ALLOWED_ORIGINS=http://localhost:3000
PORT=2001
DB_HOST=localhost
DB_NAME=banking_system
DB_USER=postgres
DB_PASSWORD=postgres
DB_PORT=5432
JWT_SECRET=your_jwt_secret
JWT_REFRESH_SECRET=your_jwt_refresh_secret- Clone repository
git clone https://github.com/RamssCR/banking-system.git
cd banking-system- Install dependencies
npm install- Setup environment
- Create
.envfile at project root with variables above.
- Start development server
npm run start:devThe app will run at: http://localhost:2001
POST /accounts→ Create accountGET /accounts→ List accounts (with transactions)
POST /transactions/deposit→ Deposit fundsPOST /transactions/withdraw→ Withdraw fundsPOST /transactions/transfer→ Transfer funds
POST /auth/register→ Register new userPOST /auth/login→ Login user
This project was built as a learning path to NestJS, focusing on:
- Clean architecture & dependency injection.
- Using database transactions and pessimistic locks for financial operations.
- Writing code that is testable and scalable.
- Applying realistic banking concepts to better understand how critical systems work.