Digital Wallet Backend API
A secure REST API for digital wallet operations built with Node.js, Express, PostgreSQL, Redis, and JWT.
Features
- User registration & login with JWT (access + refresh tokens)
- Password hashing with bcrypt
- Wallet creation with balance constraint (DB-level check)
- Idempotent fund transfers (prevents double spending)
- Transaction history with pagination
- Admin monitoring endpoints
- Rate limiting with Redis
- Comprehensive test suite (Jest + Supertest)
Tech Stack
- Runtime: Node.js
- Framework: Express
- Database: PostgreSQL (ACID transactions)
- Cache: Redis (rate limiting, idempotency)
- Authentication: JWT
- Validation: Joi
- Testing: Jest, Supertest
Getting Started
Prerequisites
- Node.js 18+
- PostgreSQL 14+
- Redis 6+
- Docker (optional, for quick setup)
Installation
- Clone the repository
git clone https://github.com/yourusername/wallet-backend.git cd wallet-backend
- Docker and Docker Compose installed
- Clone the repository
- Create a
.envfile (see.env.example) and set your email SMTP credentials (optional for testing) - Run:
docker-compose up -d
📁 Project Structure
project-root/ ├── .env.example ├── .gitignore ├── package.json ├── prisma/ │ └── schema.prisma ├── src/ │ ├── app.js │ ├── server.js │ ├── config/ │ │ ├── constants.js │ │ └── environment.js │ ├── database/ │ │ └── client.js │ ├── email/ │ │ ├── emailService.js │ │ ├── nodemailerService.js │ │ └── templates/ │ │ └── transferNotification.js │ ├── middleware/ │ │ ├── auth.js │ │ ├── errorHandler.js │ │ ├── rateLimiter.js │ │ ├── role.js │ │ └── validation.js │ ├── modules/ │ │ ├── admin/ │ │ │ ├── admin.controller.js │ │ │ ├── admin.routes.js │ │ │ └── admin.service.js │ │ ├── auth/ │ │ │ ├── auth.controller.js │ │ │ ├── auth.routes.js │ │ │ ├── auth.service.js │ │ │ └── auth.validation.js │ │ ├── transactions/ │ │ │ ├── transactions.controller.js │ │ │ ├── transactions.routes.js │ │ │ ├── transactions.service.js │ │ │ └── transactions.validation.js │ │ ├── users/ │ │ │ ├── users.controller.js │ │ │ ├── users.routes.js │ │ │ ├── users.service.js │ │ │ └── users.validation.js │ │ └── wallet/ │ │ ├── wallet.controller.js │ │ ├── wallet.routes.js │ │ ├── wallet.service.js │ │ └── wallet.validation.js │ ├── services/ │ │ └── email/ │ │ ├── email.interface.js │ │ ├── mockEmailService.js │ │ └── nodemailerEmailService.js │ └── utils/ │ ├── hash.js │ ├── jwt.js │ └── logger.js └── tests/ ├── integration/ │ └── transfer.test.js ├── unit/ │ └── transfer.service.test.js └── setup.js