- A secure, modular, and role-based backend API for a digital wallet system inspired by real-world platforms like bKash and Nagad. Built with Express.js and Mongoose, this system handles user authentication, wallet operations, and transaction management with robust business rules and validations.
https://neopay-api.vercel.app/
Admin:
email: admin@gmail.com,
password: Admin123@
Agent:
email: mukithossen7@gmail.com
password: Agent123@
User:
email: hossenmukit7@gmail.com
password: User123@
- JWT-based login and registration
- Role-based access control (
admin,agent,user) - Admin can retrieve all transaction history with support for pagination, sorting (by fields like amount, date), and filtering (by transaction type, status, user, etc.)
- Automatic wallet creation on registration.
- Add money, withdraw, send money, and view transaction history
- Agents can perform cash-in/out for users
- Admins can manage wallets, users, agents, and transactions
- Complete transaction tracking and validation
- Modular, scalable project structure
- If a user is not verified, they cannot log in. After verification, an email will be sent to the user, and then they can log in.
- Node.js
- Express.js
- TypeScript
- MongoDB
- Mongoose
- ts-node-dev
- dotenv
- bcryptjs
- cookie-parser
- http-status-codes
- jsonwebtoken
- cloudinary
- multer
- nodemailer
- multer-storage-cloudinary
- passport
- redis
git clone https://github.com/MukitHossen7/Digital_Wallet_API
cd Digital_Wallet_API
npm install
npm run dev
Make sure you have a MongoDB connection string set in your `.env` file:
src/
├── app/
│ ├── modules/
│ │ ├── auth/
│ │ │ ├── auth.controller.ts
│ │ │ ├── auth.routes.ts
│ │ │ ├── auth.service.ts
│ │
│ │ ├── user/
│ │ │ ├── user.controller.ts
│ │ │ ├── user.interface.ts
│ │ │ ├── user.model.ts
│ │ │ ├── user.routes.ts
│ │ │ ├── user.service.ts
│ │ │ └── user.zod.validation.ts
│ │
│ │ ├── wallet/
│ │ │ ├── wallet.controller.ts
│ │ │ ├── wallet.interface.ts
│ │ │ ├── wallet.model.ts
│ │ │ ├── wallet.routes.ts
│ │ │ ├── wallet.service.ts
│ │ │ └── wallet.zod.validation.ts
│ │
│ │ ├── transaction/
│ │ │ ├── transaction.controller.ts
│ │ │ ├── transaction.interface.ts
│ │ │ ├── transaction.model.ts
│ │ │ ├── transaction.routes.ts
│ │ │ ├── transaction.service.ts
│ │ │ └── transaction.zod.validation.ts
│
│ ├── routes/
│ │ └── routes.ts
│
│ ├── middlewares/
│ │ ├── checkAuth.ts
│ │ ├── globalErrorHandler.ts
│ │ └── notFound.ts
│
│ ├── utils/
│ │ ├── catchAsync.ts
│ │ ├── sendResponse.ts
│ │ └── setToken.ts
│
│ └── errorHelpers/
│ └── AppError.ts
│
├── config/
│ └── index.ts
│
├── app.ts
├── server.ts
└── .envPOST /api/v1/users/register
Request Body:
{
"name": "Toma",
"email": "toma@gmail.com",
"password": "Password@123",
"phone": "+8801706835770",
"address": "123 Gulshan Avenue, Dhaka, Bangladesh"
}
GET /api/v1/users?role=USER|AGENT
Response:
{
"success": true,
"message": "USER Retrieve Successfully",
"data": [ /* array of user or agent objects */ ]
}PATCH /api/v1/users/approve/:id
Response:
{
"success": true,
"message": "User has been promoted to AGENT",
"data": {
/* agent user object */
}
}PATCH /api/v1/users/suspend/:id
Response:
{
"success": true,
"message": "AGENT suspend Successfully",
"data": {
/* suspended agent user object */
}
}PATCH /api/v1/users/updateProfile
Request Body:
{
"name": "abc",
"phone": "01365479546",
"address":"Dhaka Bangladesh",
"image": "image.jpg"
}PATCH /api/v1/users/block/:id
Response:
{
"success": true,
"message": "User has been blocked",
"data": null
}PATCH /api/v1/users/unblock/:id
Response:
{
"success": true,
"message": "User has been unblock",
"data": null
}POST /api/v1/auth/login
Request Body:
{
"email": "admin@gmail.com",
"password": "Admin123@"
}POST /api/v1/auth/logout
Response:
{
"success": true,
"message": "User logged out successfully"
}POST /api/v1/auth/refresh-token
POST /api/v1/auth/change-password
Request Body:
{
"newPassword": "123456789",
"oldPassword": "Password@123",
}
GET /api/v1/auth/google
POST /api/v1/otp/send
POST /api/v1/otp/verify
GET /api/v1/wallets?role=USER|AGENT
Response:
"success": true,
"message": `All Wallets for role ${role} Retrieved Successfully`,
"data": [{}],GET /api/v1/wallets/me
Response:
"success": true,
"message": "Your Wallet Retrieved Successfully",
"data": {},PATCH /api/v1/wallets/block/:id
Response:
"success": true,
"message": "Wallet Blocked Successfully",PATCH /api/v1/wallets/unblock/:id
Response:
"success": true,
"message": "Wallet UnBlocked Successfully",POST /api/v1/transactions/add-money
Request Body:
{
"amount": 100,
"agent-email": "abc@gmail.com",
"type": "ADDMONEY"
}POST /api/v1/transactions/withdraw
Request Body:
{
"amount": 100,
"agent-email": "abc@gmail.com",
"type": "WITHDRAW"
}POST /api/v1/transactions/send-money
Request Body:
{
"amount": 100,
"user-email": "abc@gmail.com",
"type": "SENDMONEY"
}GET /api/v1/transactions/me
Response:
"success": true,
"message": "Transaction history retrieved successfully",
"data" : [{}]Admin can retrieve all transaction history with support for pagination, sorting (by fields like amount, date), and filtering (by transaction type, status, user, etc.)
GET /api/v1/transactions
GET/api/v1/transactions?type=ADD_MONEY&page=1&sort=-amount&limit=5
Response:
"success": true,
"message": "All transaction history retrieved successfully",
"data" : [{}]POST /api/v1/transactions/cash-in
Request Body:
{
"amount": 200,
"user-email": "hossenmukit7@gmail.com",
"type": "ADDMONEY"
}POST /api/v1/transactions/cash-out
Request Body:
{
"amount": 2000,
"user-email": "hossenmukit7@gmail.com",
"type": "WITHDRAW"
}- "bcryptjs": "^3.0.2",
- "cloudinary": "^1.41.3",
- "cookie-parser": "^1.4.7",
- "cors": "^2.8.5",
- "dotenv": "^17.2.0",
- "ejs": "^3.1.10",
- "express": "^5.1.0",
- "express-session": "^1.18.2",
- "http-status-codes": "^2.3.0",
- "jsonwebtoken": "^9.0.2",
- "mongoose": "^8.16.4",
- "multer": "^2.0.2",
- "multer-storage-cloudinary": "^4.0.0",
- "nodemailer": "^7.0.5",
- "passport": "^0.7.0",
- "passport-google-oauth20": "^2.0.0",
- "passport-local": "^1.0.0",
- "redis": "^5.8.2",
- "zod": "^3.25.76"
- "@types/cookie-parser": "^1.4.9",
- "@types/cors": "^2.8.19",
- "@types/express": "^5.0.3",
- "@types/express-session": "^1.18.2",
- "@types/jsonwebtoken": "^9.0.10",
- "@types/passport": "^1.0.17",
- "@types/passport-google-oauth20": "^2.0.16",
- "@types/passport-local": "^1.0.38",
- "ts-node-dev": "^2.0.0",
- "typescript": "^5.8.3",
- "@types/ejs": "^3.1.5",
- "@types/multer": "^2.0.0",
- "@types/nodemailer": "^7.0.1"