Skip to content

Folders and files

NameName
Last commit message
Last commit date

Latest commit

Β 

History

10 Commits
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 

Repository files navigation

Review Assignment Due Date

🏦 RevoBank API

A Modern Banking REST API built with NestJS


Live Demo API Docs


NestJS TypeScript Prisma PostgreSQL Swagger


A secure, scalable, and feature-rich banking API for managing users, accounts, and transactions.


Getting Started β€’ API Documentation β€’ Features β€’ Tech Stack


πŸ“‹ Table of Contents


✨ Features

πŸ” Authentication & Authorization

  • JWT-based authentication with secure token generation
  • Password hashing using bcrypt
  • Role-based access control (Customer/Admin)
  • Protected routes with Guards

πŸ‘€ User Management

  • User registration and login
  • Profile management (view, update)
  • Secure password storage

πŸ’³ Account Management

  • Create multiple bank accounts (Savings/Checking)
  • View account details and balance
  • Update account information
  • Delete accounts (with balance validation)
  • Auto-generated unique account numbers

πŸ’Έ Transaction Operations

  • 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

πŸ“š API Documentation

  • Interactive Swagger UI at /api
  • Complete OpenAPI specification
  • Request/Response examples

πŸ›  Tech Stack

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

πŸš€ Getting Started

Prerequisites

Before you begin, ensure you have the following installed:

Installation

  1. Clone the repository

    git clone https://github.com/Revou-FSSE-Jun25/milestone-4-afprakasa.git
    cd milestone-4-afprakasa
  2. Install dependencies

    npm install
  3. Set up environment variables (see Environment Variables)

  4. Set up the database (see Database Setup)

  5. Start the development server

    npm run start:dev

Environment Variables

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 .env file. It's already included in .gitignore.

πŸ”‘ Generating JWT Secret

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 64

Option 3: Using Python

python -c "import secrets; print(secrets.token_hex(64))"

Option 4: Online Generator

πŸ’‘ Tip: Use at least 64 characters for production environments.

Database Setup

  1. Create the database

    # Using psql
    createdb revobank
    
    # Or using SQL
    CREATE DATABASE revobank;
  2. Generate Prisma Client

    npx prisma generate
  3. Run database migrations

    npx prisma migrate dev
  4. Optional: View database with Prisma Studio

    npx prisma studio

πŸƒ Running the Application

# Development mode (with hot-reload)
npm run start:dev

# Production mode
npm run build
npm run start:prod

# Debug mode
npm run start:debug

Once running, the API will be available at:

  • API: http://localhost:3000
  • Swagger Docs: http://localhost:3000/api

πŸ“– API Documentation

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

πŸ”— API Endpoints

Authentication (/auth)

Method Endpoint Description Auth
POST /auth/register Register a new user ❌
POST /auth/login Login and get JWT token ❌

Users (/user)

Method Endpoint Description Auth
GET /user/profile Get current user profile βœ…
PATCH /user/profile Update user profile βœ…

Accounts (/account)

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 βœ…

Transactions (/transactions)

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


πŸ“ Project Structure

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

πŸ—„ Database Schema

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
    }
Loading

Models

Model Description
User Customer/Admin with authentication
Account Bank accounts (Savings/Checking)
Transaction Transaction history (Deposit/Withdraw/Transfer)

πŸ§ͺ Testing

# 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

πŸ“ Scripts

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

🀝 Contributing

  1. Fork the repository
  2. Create your feature branch (git checkout -b feature/amazing-feature)
  3. Commit your changes (git commit -m 'Add some amazing feature')
  4. Push to the branch (git push origin feature/amazing-feature)
  5. Open a Pull Request

πŸ“„ License

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

About

milestone-4-afprakasa created by GitHub Classroom

Resources

Stars

0 stars

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages