Banking MongoDB (Mongoose) Schema A detailed look at the MongoDB schema for a modern banking application.
Installation Guide
To add these schemas to your project, run:
npx servercn-cli@latest add schema banking-app
1. User Schema
The User schema stores essential information about the customer. This includes personal details and security credentials.
MVC Path: src/models/user.model.ts
Feature Path: src/modules/auth/user.model.ts
import mongoose, { Document, Model, Schema } from "mongoose" ;
export interface IAvatar {
public_id : string ;
url : string ;
size : number ;
}
export interface IUser extends Document {
_id : mongoose . Types . ObjectId ;
name : string ;
email : string ;
password ?: string ;
role : "user" | "admin" ;
isEmailVerified : boolean ;
lastLoginAt ?: Date ;
failedLoginAttempts : number ;
lockUntil ?: Date ;
avatar ?: IAvatar ;
provider : "local" | "google" | "github" ;
providerId ?: string ;
isDeleted : boolean ;
deletedAt ?: Date | null ;
reActivateAvailableAt ?: Date | null ;
createdAt : Date ;
updatedAt : Date ;
}
const userSchema = new Schema < IUser >(
{
name: {
type: String,
required: [ true , "Name is required" ],
trim: true
},
email: {
type: String,
required: [ true , "Email is required" ],
unique: true ,
lowercase: true ,
trim: true
},
password: {
type: String,
select: false ,
default: null
},
provider: {
type: String,
enum: [ "local" , "google" , "github" ],
default: "local"
},
providerId: {
type: String,
default: null
},
role: {
type: String,
enum: [ "user" , "admin" ],
default: "user"
},
avatar: {
public_id: String,
url: String,
size: Number
},
isEmailVerified: {
type: Boolean,
default: false
},
lastLoginAt: {
type: Date
},
failedLoginAttempts: {
type: Number,
required: true ,
default: 0
},
lockUntil: {
type: Date
},
isDeleted: {
type: Boolean,
default: false
},
deletedAt: {
type: Date,
default: null
},
reActivateAvailableAt: {
type: Date,
default: null
}
},
{
timestamps: true
}
);
// Performance Indexes
userSchema. index ({ provider: 1 , providerId: 1 }); // Quick lookup for OAuth
userSchema. index ({ role: 1 });
userSchema. index ({ isDeleted: 1 }); // Optimized for soft-delete queries
const User : Model < IUser > =
mongoose.models.User || mongoose. model < IUser >( "User" , userSchema);
export default User;
Installation
npx servercn-cli@latest add schema banking-app/user
2. Account Schema
The Account schema stores user bank accounts (e.g., savings, current). A user can own multiple accounts with different types, currencies, and statuses.
MVC Path: src/models/account.model.ts
Feature Path: src/modules/account/account.model.ts
Installation
npx servercn-cli@latest add schema banking-app/account
3. Transaction Schema
The Transaction schema records money movements between accounts, including transfers, deposits, and withdrawals.
MVC Path: src/models/transaction.model.ts
Feature Path: src/modules/transaction/transaction.model.ts
Installation
npx servercn-cli@latest add schema banking-app/transaction
5. Ledger Schema
The Ledger schema records all financial movements such as deposits, withdrawals, and transfers. Each entry represents a finalized financial event.
Ledger entries are immutable.
All update and delete operations are blocked to preserve audit integrity.
Path
MVC: src/models/ledger.model.ts
Feature: src/modules/ledger/ledger.model.ts
Installation
npx servercn-cli@latest add schema banking-app/ledger
Notes:
Ledger entries are immutable
All update and delete operations are blocked to preserve audit integrity
File & Folder Structure Model-View-Controller (MVC) Feature-Based (Module, Shared)
Installation npx servercn-cli@latest add sc banking-app