A secure and scalable Ledger Management System built using Node.js, Express.js, MongoDB, and Mongoose that supports account-based transactions, immutable ledger entries, idempotent payments, JWT authentication, email notifications, and ACID-compliant database transactions.
This project simulates how modern payment systems and banking backends maintain transaction consistency and prevent duplicate processing.
- JWT-based Authentication
- Protected Routes using Middleware
- System User Authorization
- Secure Password Hashing using bcryptjs
- Cookie & Bearer Token Support
- Logout using Token Blacklisting
- User Registration
- User Login
- Secure Password Storage
- Email Validation
- Create Accounts
- Active/Inactive Account Status
- Account Ownership
- Dynamic Balance Calculation
- Money Transfer between Accounts
- Idempotency Key Support
- Duplicate Transaction Prevention
- Transaction Status Tracking
Supported Transaction Status:
PENDINGCOMPLETEDFAILEDREVERSED
Every transaction creates immutable ledger entries:
- DEBIT Entry → Sender Account
- CREDIT Entry → Receiver Account
Ledger entries cannot be modified or deleted, ensuring auditability and financial consistency.
Uses MongoDB Sessions & Transactions to ensure:
- Atomic Operations
- Data Consistency
- Rollback on Failure
- Safe Multi-document Transactions
Automatic email notifications for:
- User Registration
- Successful Transactions
Account balance is derived from ledger entries:
Balance = Total Credits - Total Debits
No direct balance mutation ensures higher reliability.
- Node.js
- Express.js
- MongoDB Atlas
- Mongoose
- JSON Web Token (JWT)
- bcryptjs
- Nodemailer
- Google OAuth2
- dotenv
project3/
│── src/
│ ├── controllers/
│ │ ├── account.controller.js
│ │ ├── auth.controller.js
│ │ └── transaction.controller.js
│ │
│ ├── db/
│ │ └── db.js
│ │
│ ├── middleware/
│ │ └── auth.middleware.js
│ │
│ ├── models/
│ │ ├── account.model.js
│ │ ├── blackList.model.js
│ │ ├── ledger.model.js
│ │ ├── transaction.model.js
│ │ └── user.model.js
│ │
│ ├── routes/
│ │ ├── account.routes.js
│ │ ├── auth.routes.js
│ │ └── transaction.routes.js
│ │
│ ├── services/
│ │ └── email.service.js
│ │
│ └── app.js
│
│── .env
│── .gitignore
│── package.json
│── package-lock.json
│── server.jsgit clone <your-repository-url>
cd project3npm installCreate a .env file in the root directory:
PORT=3000
MONGODB_URI=your_mongodb_connection_string
JWT_SECRET=your_secret_key
EMAIL_USER=your_email@gmail.com
CLIENT_ID=your_google_client_id
CLIENT_SECRET=your_google_client_secret
REFRESH_TOKEN=your_refresh_tokenDevelopment Mode:
npm run devProduction Mode:
npm startPOST /api/auth/registerRequest Body:
{
"name": "Abhishek",
"email": "abhishek@test.com",
"password": "123456"
}POST /api/auth/loginRequest Body:
{
"email": "abhishek@test.com",
"password": "123456"
}POST /api/auth/logoutPOST /api/account/createGET /api/account/balance/:accountIdPOST /api/transaction/createRequest Body:
{
"fromAccount": "account_id",
"toAccount": "account_id",
"amount": 2000,
"idempotencyKey": "unique-id"
}If a request is sent multiple times using the same:
"idempotencyKey"Then:
{
"message": "Transaction already processed."
}{
"message": "Transaction is still processing."
}This prevents duplicate money transfer issues.
- JWT Authentication
- Password Hashing using bcrypt
- Token Blacklisting
- Immutable Ledger Entries
- Transaction Rollback
- Authorization Middleware
- Environment Variable Protection
- Input Validation
You can test APIs using:
- Postman
- Thunder Client
- Hoppscotch
- Transaction History
- Pagination
- Rate Limiting
- Redis Queue for Async Processing
- Transaction Reversal APIs
- Admin Dashboard
- Docker Deployment
- Swagger API Documentation
Abhishek Goyal
This project is licensed under the MIT License.