Banking Application with MongoDB (Mongoose)
This guide covers the MongoDB-specific implementation of the Banking Application blueprint using Mongoose ODM. Learn about schema design, indexing strategies, and database operations specific to MongoDB.
Overview
The MongoDB version of the banking app uses Mongoose for schema validation, data modeling, and database operations. This implementation provides flexibility while maintaining data integrity through Mongoose schemas and middleware.
Installation
npx servercn-cli add bp banking-appArchitecture Support
1. MVC
The banking app follows the traditional Model-View-Controller pattern:
2. Feature-Based(Modules)
For better scalability and maintainability:
Scripts
API Documentation
Once running, access the interactive API documentation at: http://localhost:3000/api/docs
The Swagger UI provides:
- Interactive API testing
- Request/response examples
- Authentication helpers
- Schema definitions
API Endpoints
Health Check
Base URL: http://localhost:3000/api/v1/health
| Method | Endpoint | Description |
|---|---|---|
| GET | / | Basic health check |
| GET | /detailed | Detailed health status |
Authentication
Base URL: http://localhost:3000/api/v1/auth
| Method | Endpoint | Description |
|---|---|---|
| POST | /signup | Register a new user |
| POST | /signin | Login user |
| POST | /verify-otp | Verify OTP |
| GET | /profile | Get user profile |
| PATCH | /profile | Update user profile |
| POST | /refresh-token | Refresh access token |
| POST | /logout | Logout user |
| POST | /forgot-password | Request password reset |
| POST | /reset-password | Reset password |
| POST | /change-password | Change password |
| DELETE | /delete-account | Delete account |
| PUT | /reactivate-account | Reactivate account |
Accounts
Base URL: http://localhost:3000/api/v1/accounts
| Method | Endpoint | Description |
|---|---|---|
| POST | / | Create a new account |
| GET | / | Get all user accounts |
| GET | /:accountId | Get account details |
| GET | /balance/:accountId | Get account balance |
Transactions
Base URL: http://localhost:3000/api/v1/transactions
| Method | Endpoint | Description |
|---|---|---|
| POST | /system-init | Create system initial transaction |
| POST | / | Create a new transaction |
| GET | /history/:accountId | Get transaction history |
OAuth
Base URL: http://localhost:3000/api/auth
| Method | Endpoint | Description |
|---|---|---|
| GET | /github | GitHub OAuth login |
| GET | /github/callback | GitHub OAuth callback |
| GET | Google OAuth login | |
| GET | /google/callback | Google OAuth callback |
Security Considerations
- Password Hashing - bcrypt with salt rounds
- JWT Tokens - Short-lived access tokens, long-lived refresh tokens
- Rate Limiting - Per-IP and per-user limits
- Input Validation - All inputs validated with Zod
- SQL Injection Prevention - MongoDB prevents SQL injection
- XSS Protection - Helmet middleware
- CORS Configuration - Configurable allowed origins
- Request Sanitization - Mongo-sanitize for NoSQL injection prevention
Contributing
Found a bug or want to suggest improvements? Please contribute to the Servercn project!
Support
Need help? Join our Discord community or open an issue on GitHub.