Base URL: https://digital-wallet-management-system-kappa.vercel.app/api/v1
Swager(local): http://localhost:5000/api-docs/
A secure, role-based digital wallet API built with Express.js (TypeScript) and MongoDB (Mongoose). The system supports three roles: Users, Agents, and Admins. Users can manage their wallets (top-up, send, withdraw), agents can perform cash-in/out transactions (with commission), and admins have full control over users, agents, wallets, and transaction records. The API enables features like user registration/login, wallet management, transaction history, agent verification, and account blocking. All endpoints enforce authentication (JWT) and role-based authorization.
- Node.js & Express.js (TypeScript): Backend framework for building RESTful APIs.
- MongoDB (Mongoose): NoSQL database for storing users, wallets, transactions.
- Authentication: JSON Web Tokens (JWT) for stateless auth; passwords hashed with bcrypt.
- Validation: express-validator to check request payloads.
- Email & Media: Nodemailer for sending emails (e.g. password reset links); Cloudinary for optional media (image) storage.
- Configuration: dotenv for environment variables.
- Admin Credentials: Environment-configured admin account (email/phone/password) for initial setup.
ADMIN_EMAIL=admin@example.com
ADMIN_PASSWORD=supersecurepassword
USER_EMAIL=yaxelop525@devdigs.com
ADMIN_PASSWORD=StrongP@ssw0rd
USER_EMAIL=caditir829@coursora.com
ADMIN_PASSWORD=StrongP@ssw0rd
POST /api/v1/auth/register
Request Body (form data):
{
"name": "Jane Doe",
"email": "jane@example.com",
"phone": "017XXXXXXXX", // or +880xxxxxxxxxx(unique)
"password": "strongPassword",
"identifier": "NID", // NID or BIRTH_CERTIFICATE
"identifier_image": "", // Image less than 2 MB for KYC (Required)
"profile_picture": "", // Image less than 2 MB(Optional)
"role": "USER" // or "AGENT" (agent accounts start as "pending")
}- Creates a new User or Agent account. Agents are marked pending until approved by an admin.
POST /api/v1/auth/login
Request Body (JSON):
{
"email": "jane@example.com",
"password": "strongPassword"
}Response (JSON):
{
"accessToken": "<JWT access token>",
"refreshToken": "<JWT refresh token>"
}- Validates credentials and returns an access token (short-lived) and refresh token (long-lived) for authenticated requests.
- Automatically set into the cookies. No need to set manual Authorization Headers.
POST /api/v1/auth/refresh-token
- Accepts a valid refresh token (from cookies or request body).
- Returns a new access token and refresh token for continued authentication.
- Use this endpoint to maintain user sessions without requiring re-login.
- Requires the refresh token to be valid and not expired.
- No body required.
Request.cookies (JSON):
{
"refreshToken": "<JWT refresh token>"
}Response (JSON):
{
"accessToken": "<new JWT access token>",
"refreshToken": "<new JWT refresh token>"
}POST /api/v1/auth/logout
- Invalidates the user's refresh token and clears authentication cookies, effectively logging the user out.
- Requires a valid refresh token in the request cookies or body.
- Recommended for secure session termination.
POST /api/v1/auth/forgot-password
- Forgot Password: Agents or users who forget their password can use
POST /api/v1/auth/forgot-passwordwith their email to receive a reset link via email. Request Body (JSON):
{
"email": "yaxelop525@devdigs.com"
}Response (JSON):
{
"statusCode": 200,
"success": true,
"message": "Email Sent Successfully",
"data": null
}- Reset Password: A separate endpoint (e.g.
POST /api/v1/auth/reset-password) would accept a token and new password. (Implementation depends on front-end flow and is supported by thesendEmailutility.) Request Body (JSON):
{
"newPassword": "StrongP@ssw0rd"
}Response (JSON):
{
"statusCode": 200,
"success": true,
"message": "Password Changed Successfully",
"data": null
}checkAuth(...roles): Verifies JWT and enforces that the authenticated userβs role matches one of the allowed roles.isAuthenticated: Checks for a valid JWT in the request (for any logged-in user).
These middleware functions protect all routes so that only properly authenticated users (and/or specific roles) can access them.
All of the following endpoints require an admin role.
-
Get All Users & Agents:
GET /api/v1/user- Returns a list of all user and agent accounts (excluding sensitive fields like passwords).
-
Approve Agent or User:
PATCH /api/v1/user/:id/approve- Marks an agent or user as verified/approved (depending on role).
- Use this to activate pending agents or verify new user accounts.
-
Suspend Agent or User:
PATCH /api/v1/user/:id/suspend- Suspends an agent or user (sets status to suspended, preventing login or transactions).
-
Block/Unblock Wallet:
PATCH /api/v1/user/:id/blockβ Block userβs wallet (freeze transactions).PATCH /api/v1/user/:id/unblockβ Unblock userβs wallet (re-enable transactions).
These actions allow the admin to control who can transact. For example, blocking an account disables its wallet entirely.
Authenticated Users (and agents, where applicable) can manage their wallets. Admins can list all wallets.
-
Get Own Wallet:
GET /api/v1/wallet/me- Returns the authenticated userβs wallet details (balance, status, etc.).
-
Top-up Wallet:
PATCH /api/v1/wallet/top-upBody:{ "amount": 500 }- Adds the specified amount to the userβs wallet balance. (E.g. a user deposits money into their account.)
-
Withdraw from Wallet:
PATCH /api/v1/wallet/withdrawBody:{ "amount": 200 }- Subtracts the specified amount from the wallet (if sufficient balance). This could represent transferring money to a bank or external account.
-
Send Money:
PATCH /api/v1/wallet/sendBody:{ "receiverPhone": "01812345678", "amount": 100 }- Transfers the specified amount from the senderβs wallet to another userβs wallet (identified by phone number).
-
Admin: Get All Wallets:
GET /api/v1/wallet- Admin endpoint that returns all wallets in the system. Useful for monitoring and audits.
This tracks all wallet transactions. Roles:
-
User/Agent (self) Transaction History:
GET /api/v1/transaction/me- Returns all transactions (cash-in, cash-out, sends, etc.) related to the authenticated user or agent. Agents see transactions they facilitated; users see their own history.
-
Admin: Get All Transactions:
GET /api/v1/transaction- Returns every transaction in the system (across all users and agents).
-
Cash-in (Agent):
POST /api/v1/transaction/cash-inBody:{ "userPhone": "01712345678", "amount": 300 }- Agent deposits cash into a userβs wallet. The agentβs own wallet balance decreases (by amount + commission), and the userβs balance increases by the amount. A small commission is deducted.
-
Cash-out (Agent):
POST /api/v1/transaction/cash-outBody:{ "userPhone": "01712345678", "amount": 200 }- Agent withdraws cash from a userβs wallet. The userβs balance decreases by the amount, and the agentβs balance increases by (amount β commission).
- Blocked Accounts: No operations (top-up, send, withdraw, cash-in/out) can be performed if the userβs wallet is blocked.
- Sufficient Funds: You cannot withdraw or send more than the current balance.
- Positive Amounts: Zero or negative transaction amounts are not allowed (must be positive).
- Agent Commission: Every cash-in/out transaction by an agent applies a commission (e.g. a percentage fee). The commission is deducted appropriately.
| Endpoint | Method | Role | Expected Status | Description |
|---|---|---|---|---|
/auth/register |
POST | β | 201 | Register a new user or agent |
/auth/login |
POST | β | 200 | Login and return JWT tokens |
/auth/forgot-password |
POST | β | 200 | Send password reset email |
/wallet/me |
GET | user | 200 | View own wallet details |
/wallet/top-up |
PATCH | user | 200 | Add funds to own wallet |
/wallet/withdraw |
PATCH | user | 200 | Withdraw funds from own wallet |
/wallet/send |
PATCH | user | 200 | Send funds to another user |
/wallet |
GET | admin | 200 | List all wallets (admin only) |
/user |
GET | admin | 200 | List all users and agents |
/user/:id/block |
PATCH | admin | 200 | Block a userβs wallet |
/user/:id/unblock |
PATCH | admin | 200 | Unblock a userβs wallet |
/user/:id/approve |
PATCH | admin | 200 | Approve a pending agent or user |
/user/:id/suspend |
PATCH | admin | 200 | Suspend an agent or user |
/transaction/me |
GET | user/agent | 200 | View own transaction history |
/transaction |
GET | admin | 200 | List all transactions (admin only) |
/transaction/cash-in |
POST | agent | 200 | Agent deposits cash into user |
/transaction/cash-out |
POST | agent | 200 | Agent withdraws cash for user |
Each test case assumes valid authentication (JWT) and, where applicable, the correct role. For example, only admins can call /users or /wallets (all users), and only agents can call /transaction/cash-in or /cash-out.
Create a .env file (or use .env.example) with the following keys. Replace placeholder values as needed:
PORT=5000
DB_URL=<your-mongodb-connection-string>
NODE_ENV=development
# Optional: Frontend URL (for CORS or email links)
FRONTEND_URL=http://localhost:3000
# Cloudinary (if used for media uploads)
CLOUDINARY_CLOUD_NAME=<your-cloudinary-cloud-name>
CLOUDINARY_API_KEY=<your-cloudinary-api-key>
CLOUDINARY_API_SECRET=<your-cloudinary-api-secret>
# JWT Settings
JWT_ACCESS_SECRET=<your-jwt-access-token-secret>
JWT_REFRESH_SECRET=<your-jwt-refresh-token-secret>
JWT_ACCESS_EXPIRES=1d
JWT_REFRESH_EXPIRES=30d
# Bcrypt (password hashing)
BCRYPT_SALT_ROUND=10
# Admin Credentials (example)
ADMIN_EMAIL=admin@example.com
ADMIN_PASSWORD=supersecurepassword
ADMIN_PHONE=01800000000
# Email (SMTP) Configuration for sending emails
SMTP_HOST=smtp.gmail.com
SMTP_PORT=587
SMTP_USER=your-email@example.com
SMTP_PASS=your-email-password-or-app-password
SMTP_FROM=your-email@example.com
These settings configure the server port, database connection, authentication secrets, and email/Cloudinary services.
sarwarhridoy4-digital_wallet_management_system/
βββ README.md
βββ Digital Wallet Management.postman_collection.json
βββ eslint.config.mjs
βββ package.json
βββ Project_plan.md
βββ tsconfig.json
βββ vercel.json
βββ .env.example
βββ src/
βββ app.ts
βββ constants.ts
βββ server.ts
βββ app/
βββ config/
β βββ cloudinary.config.ts
β βββ db.ts
β βββ env.ts
β βββ multer.config.ts
βββ errorHelpers/
β βββ AppError.ts
βββ helpers/
β βββ handleCastError.ts
β βββ handleDuplicateError.ts
β βββ handlerValidationError.ts
β βββ handlerZodError.ts
βββ interfaces/
β βββ error.types.ts
β βββ index.d.ts
βββ middlewares/
β βββ authCheck.ts
β βββ globalErrorHandler.ts
β βββ notFound.ts
β βββ validateRequest.ts
βββ modules/
β βββ auth/
β β βββ auth.controller.ts
β β βββ auth.routes.ts
β β βββ auth.service.ts
β βββ transaction/
β β βββ transaction.constant.ts
β β βββ transaction.controller.ts
β β βββ transaction.interface.ts
β β βββ transaction.model.ts
β β βββ transaction.routes.ts
β β βββ transaction.service.ts
β β βββ transaction.validation.ts
β βββ user/
β β βββ user.constant.ts
β β βββ user.controller.ts
β β βββ user.interface.ts
β β βββ user.model.ts
β β βββ user.routes.ts
β β βββ user.service.ts
β β βββ user.validation.ts
β βββ wallet/
β βββ wallet.constant.ts
β βββ wallet.controller.ts
β βββ wallet.interface.ts
β βββ wallet.model.ts
β βββ wallet.routes.ts
β βββ wallet.service.ts
βββ routes/
β βββ index.ts
βββ types/
β βββ index.ts
βββ utils/
βββ catchAsync.ts
βββ jwt.ts
βββ QueryBuilders.ts
βββ seedAdmin.ts
βββ sendMail.ts
βββ sendResponse.ts
βββ setCookie.ts
βββ userToken.ts
βββ templates/
βββ forgotPassword.ejs
This modular layout separates each feature (auth, user, wallet, transaction) into its own directory.
## π₯ **Demo Video Outline β Digital Wallet API (Total: \~40 min)**
### 1. **π¬ Introduction (1 min)**
- Briefly introduce the project
- Technologies used (Express.js, MongoDB, TypeScript, etc.)
- Purpose and key features of the system
### 2. **π Folder Structure Overview (3 min)**
- Show the overall file and folder layout
- Explain the `modules/`, `middlewares/`, `utils/`, and `config/` folders
- Highlight separation of concerns and scalability approach
### 3. **π Authentication Flow (4 min)**
- Walk through user registration and login
- Explain JWT token generation and middleware for route protection
- Role-based access control (User, Agent, Admin)
### 4. **π€ User Features (5 min)**
- View profile and update basic info
- Wallet balance view and transaction history
- Send money (if implemented)
### 5. **π§βπΌ Agent Features (5 min)**
- Perform **Cash-In** to user
- Perform **Cash-Out** from user
- View own transaction history
### 6. **π οΈ Admin Features (5 min)**
- View all users, agents, and wallets
- Approve/reject KYC documents
- Block/unblock users or agents
- View/filter all transactions
### 7. **π§ͺ Postman Live Test Run (15 min)**
- Hit all major API endpoints (User, Agent, Admin)
- Demonstrate request/response and error handling
- Show JWT protected route handling
- Include edge case tests (invalid token, unauthorized access, etc.)
### 8. **π¦ Optional: Deployment Highlights (1β2 min)**
- Show live deployment (Vercel, Render, etc.)
- MongoDB Atlas and environment setup tips (optional)
### 9. **β
Wrap-Up (1 min)**
- Recap major features demonstrated
- Share any limitations or upcoming features
- Thank the viewer and invite feedback
* Postman collection given
* Import it into your postman to test
**Project Brief**: https://drive.google.com/drive/folders/10CFDoUGXCilPGk2QSthCdndW2tjztmpS?usp=sharing
**Live Deployed**: https://digital-wallet-management-system-kappa.vercel.app