A secure, scalable, and feature-rich banking API for managing users, accounts, and transactions.
Getting Started β’ API Documentation β’ Features β’ Tech Stack
- Features
- Tech Stack
- Getting Started
- Running the Application
- API Documentation
- API Endpoints
- Project Structure
- Database Schema
- Testing
- License
- JWT-based authentication with secure token generation
- Password hashing using bcrypt
- Role-based access control (Customer/Admin)
- Protected routes with Guards
- User registration and login
- Profile management (view, update)
- Secure password storage
- Create multiple bank accounts (Savings/Checking)
- View account details and balance
- Update account information
- Delete accounts (with balance validation)
- Auto-generated unique account numbers
- Deposit - Add funds to your account
- Withdraw - Remove funds (with balance validation)
- Transfer - Send money between accounts
- Transaction history with reference numbers
- Atomic transactions using Prisma's
$transaction
- Interactive Swagger UI at
/api - Complete OpenAPI specification
- Request/Response examples
| Category | Technology |
|---|---|
| Framework | NestJS v11 |
| Language | TypeScript v5 |
| ORM | Prisma v6 |
| Database | PostgreSQL |
| Authentication | JWT + Passport |
| Validation | class-validator + class-transformer |
| Documentation | Swagger/OpenAPI |
| Testing | Jest + Supertest |
Before you begin, ensure you have the following installed:
- Node.js (v18 or higher) - Download
- npm (v9 or higher) or yarn
- PostgreSQL (v14 or higher) - Download
- Git - Download
-
Clone the repository
git clone https://github.com/Revou-FSSE-Jun25/milestone-4-afprakasa.git cd milestone-4-afprakasa -
Install dependencies
npm install
-
Set up environment variables (see Environment Variables)
-
Set up the database (see Database Setup)
-
Start the development server
npm run start:dev
Create a .env file in the root directory:
# Database
DATABASE_URL="postgresql://username:password@localhost:5432/revobank?schema=public"
DIRECT_URL="postgresql://username:password@localhost:5432/revobank?schema=public"
# JWT
JWT_SECRET="your-super-secret-jwt-key-here"
# Server
PORT=3000
β οΈ Important: Never commit your.envfile. It's already included in.gitignore.
You need a strong, random secret for JWT. Here are several ways to generate one:
Option 1: Using Node.js (Recommended)
node -e "console.log(require('crypto').randomBytes(64).toString('hex'))"Option 2: Using OpenSSL
openssl rand -hex 64Option 3: Using Python
python -c "import secrets; print(secrets.token_hex(64))"Option 4: Online Generator
- Visit RandomKeygen and use a "Fort Knox Password"
π‘ Tip: Use at least 64 characters for production environments.
-
Create the database
# Using psql createdb revobank # Or using SQL CREATE DATABASE revobank;
-
Generate Prisma Client
npx prisma generate
-
Run database migrations
npx prisma migrate dev
-
Optional: View database with Prisma Studio
npx prisma studio
# Development mode (with hot-reload)
npm run start:dev
# Production mode
npm run build
npm run start:prod
# Debug mode
npm run start:debugOnce running, the API will be available at:
- API:
http://localhost:3000 - Swagger Docs:
http://localhost:3000/api
Interactive API documentation is available via Swagger UI:
http://localhost:3000/api
The Swagger UI provides:
- π Complete endpoint documentation
- π JWT authentication testing
- π€ Request/Response examples
- π§ͺ Try-it-out functionality
| Method | Endpoint | Description | Auth |
|---|---|---|---|
POST |
/auth/register |
Register a new user | β |
POST |
/auth/login |
Login and get JWT token | β |
| Method | Endpoint | Description | Auth |
|---|---|---|---|
GET |
/user/profile |
Get current user profile | β |
PATCH |
/user/profile |
Update user profile | β |
| Method | Endpoint | Description | Auth |
|---|---|---|---|
POST |
/account |
Create a new account | β |
GET |
/account |
Get all user accounts | β |
GET |
/account/:id |
Get account by ID | β |
PATCH |
/account/:id |
Update account | β |
DELETE |
/account/:id |
Delete account | β |
| Method | Endpoint | Description | Auth |
|---|---|---|---|
POST |
/transactions/deposit |
Deposit funds | β |
POST |
/transactions/withdraw |
Withdraw funds | β |
POST |
/transactions/transfer |
Transfer between accounts | β |
GET |
/transactions |
Get all transactions | β |
GET |
/transactions/:id |
Get transaction by ID | β |
β = Requires JWT Bearer Token
revobank/
βββ prisma/
β βββ migrations/ # Database migrations
β βββ schema.prisma # Prisma schema
βββ src/
β βββ auth/ # Authentication module
β β βββ dto/ # Data Transfer Objects
β β βββ guards/ # JWT Guards
β β βββ strategies/ # Passport strategies
β β βββ auth.controller.ts
β β βββ auth.module.ts
β β βββ auth.service.ts
β βββ user/ # User module
β β βββ dto/
β β βββ user.controller.ts
β β βββ user.module.ts
β β βββ user.service.ts
β βββ account/ # Account module
β β βββ dto/
β β βββ account.controller.ts
β β βββ account.module.ts
β β βββ account.service.ts
β βββ transaction/ # Transaction module
β β βββ dto/
β β βββ transaction.controller.ts
β β βββ transaction.module.ts
β β βββ transaction.service.ts
β βββ prisma/ # Prisma service
β β βββ prisma.module.ts
β β βββ prisma.service.ts
β βββ app.module.ts # Root module
β βββ main.ts # Application entry point
βββ test/ # E2E tests
βββ .env # Environment variables
βββ package.json
βββ tsconfig.json
erDiagram
User ||--o{ Account : has
Account ||--o{ Transaction : has
User {
string id PK
string email UK
string password
string name
string role
datetime createdAt
datetime updatedAt
}
Account {
string id PK
string userId FK
string accountNumber UK
string accountType
decimal balance
datetime createdAt
datetime updatedAt
}
Transaction {
string id PK
string accountId FK
string type
decimal amount
string description
string referenceNumber UK
string relatedAccountId
datetime createdAt
}
| Model | Description |
|---|---|
| User | Customer/Admin with authentication |
| Account | Bank accounts (Savings/Checking) |
| Transaction | Transaction history (Deposit/Withdraw/Transfer) |
# Unit tests
npm run test
# Unit tests with watch mode
npm run test:watch
# E2E tests
npm run test:e2e
# Test coverage
npm run test:cov| Script | Description |
|---|---|
npm run start |
Start the application |
npm run start:dev |
Start with hot-reload |
npm run start:prod |
Start in production mode |
npm run build |
Build the application |
npm run lint |
Run ESLint |
npm run format |
Format code with Prettier |
npm run test |
Run unit tests |
npm run test:e2e |
Run E2E tests |
- Fork the repository
- Create your feature branch (
git checkout -b feature/amazing-feature) - Commit your changes (
git commit -m 'Add some amazing feature') - Push to the branch (
git push origin feature/amazing-feature) - Open a Pull Request
This project is licensed under the MIT License - see the LICENSE file for details.
Built with β€οΈ by x-s-a
RevoU FSSE Jun25 - Milestone 4