Banking Application with MongoDB (Mongoose)

This guide covers the MongoDB-specific implementation of the Banking Application blueprint using Mongoose ODM. Learn about schema design, indexing strategies, and database operations specific to MongoDB.

Overview

The MongoDB version of the banking app uses Mongoose for schema validation, data modeling, and database operations. This implementation provides flexibility while maintaining data integrity through Mongoose schemas and middleware.

Installation

npx servercn-cli add bp banking-app

Architecture Support

The banking app follows the traditional Model-View-Controller pattern:

banking-app/
├── src/
│   ├── controllers/       # Request handlers
│   │   ├── auth.controller.ts
│   │   ├── account.controller.ts
│   │   ├── transaction.controller.ts
│   │   └── ledger.controller.ts
│   ├── models/           # MongoDB schemas
│   │   ├── User.ts
│   │   ├── Account.ts
│   │   ├── Transaction.ts
│   │   └── Ledger.ts
│   ├── services/         # Business logic layer
│   │   ├── auth.service.ts
│   │   ├── account.service.ts
│   │   └── transaction.service.ts
│   ├── routes/           # API route definitions
│   │   ├── auth.routes.ts
│   │   ├── account.routes.ts
│   │   └── transaction.routes.ts
│   ├── middlewares/      # Express middlewares
│   │   ├── auth.middleware.ts
│   │   ├── validation.middleware.ts
│   │   └── error.middleware.ts
│   ├── validators/       # Zod schemas
│   │   ├── auth.validator.ts
│   │   └── account.validator.ts
│   ├── utils/            # Utility functions
│   │   ├── apiResponse.ts
│   │   ├── catchAsync.ts
│   │   └── AppError.ts
│   ├── config/           # Configuration files
│   │   ├── database.ts
│   │   └── env.ts
│   └── app.ts            # Express app setup
├── package.json
└── tsconfig.json

For better scalability and maintainability:

banking-app/
├── src/
│   ├── modules/          # Feature modules
│   │   ├── auth/
│   │   │   ├── auth.controller.ts
│   │   │   ├── auth.service.ts
│   │   │   ├── auth.routes.ts
│   │   │   ├── auth.model.ts
│   │   │   └── auth.validator.ts
│   │   ├── account/
│   │   │   ├── account.controller.ts
│   │   │   ├── account.service.ts
│   │   │   ├── account.routes.ts
│   │   │   ├── account.model.ts
│   │   │   └── account.dto.ts
│   │   ├── transaction/
│   │   ├── ledger/
│   │   ├── otp/
│   │   └── oauth/
│   ├── shared/           # Shared utilities
│   │   ├── middlewares/
│   │   ├── utils/
│   │   └── constants/
│   ├── config/
│   ├── types/
│   └── app.ts
├── package.json
└── tsconfig.json

Scripts

# Start the development server
npm run dev
 
# Build the project for production
npm run build
 
# Start the production server
npm run start
 
# Run TypeScript type checking
npm run typecheck
 
# Generate api documentation
npm run docs
 
# Check for linting issues
npm run lint:check
 
# Automatically fix linting issues
npm run lint:fix
 
# Check code formatting
npm run format:check
 
# Automatically fix code formatting
npm run format:fix

API Documentation

Once running, access the interactive API documentation at: http://localhost:3000/api/docs

The Swagger UI provides:

  • Interactive API testing
  • Request/response examples
  • Authentication helpers
  • Schema definitions

API Endpoints

Base URL: http://localhost:3000/api/v1/health

MethodEndpointDescription
GET/Basic health check
GET/detailedDetailed health status

Base URL: http://localhost:3000/api/v1/auth

MethodEndpointDescription
POST/signupRegister a new user
POST/signinLogin user
POST/verify-otpVerify OTP
GET/profileGet user profile
PATCH/profileUpdate user profile
POST/refresh-tokenRefresh access token
POST/logoutLogout user
POST/forgot-passwordRequest password reset
POST/reset-passwordReset password
POST/change-passwordChange password
DELETE/delete-accountDelete account
PUT/reactivate-accountReactivate account

Base URL: http://localhost:3000/api/v1/accounts

MethodEndpointDescription
POST/Create a new account
GET/Get all user accounts
GET/:accountIdGet account details
GET/balance/:accountIdGet account balance

Base URL: http://localhost:3000/api/v1/transactions

MethodEndpointDescription
POST/system-initCreate system initial transaction
POST/Create a new transaction
GET/history/:accountIdGet transaction history

Base URL: http://localhost:3000/api/auth

MethodEndpointDescription
GET/githubGitHub OAuth login
GET/github/callbackGitHub OAuth callback
GET/googleGoogle OAuth login
GET/google/callbackGoogle OAuth callback

Security Considerations

  1. Password Hashing - bcrypt with salt rounds
  2. JWT Tokens - Short-lived access tokens, long-lived refresh tokens
  3. Rate Limiting - Per-IP and per-user limits
  4. Input Validation - All inputs validated with Zod
  5. SQL Injection Prevention - MongoDB prevents SQL injection
  6. XSS Protection - Helmet middleware
  7. CORS Configuration - Configurable allowed origins
  8. Request Sanitization - Mongo-sanitize for NoSQL injection prevention


Contributing

Found a bug or want to suggest improvements? Please contribute to the Servercn project!

Support

Need help? Join our Discord community or open an issue on GitHub.

File & Folder Structure

Loading files...

Installation

npx servercn-cli add bp banking-app