Fidelity First Brokers (FFB) Backend is a secure, high-performance API server built to power the FFB financial platform. It provides comprehensive functionality for investment services, trading operations, user account management, and administrative controls.
- Secure JWT-based authentication system
- Role-based access control (user, admin, superadmin)
- Firebase authentication integration
- Password encryption with bcrypt
- API key management for third-party integrations
- User registration and profile management
- KYC verification workflow
- Security settings and login activity tracking
- Payment method management
- Deposit and withdrawal processing
- Investment plans and user investments
- Trading functionality
- Transaction history and reporting
- Referral program management
- Complete administrative functions
- User management and oversight
- Transaction processing and monitoring
- KYC verification administration
- Support ticket system
- System settings management
- Comprehensive analytics
- Real-time cryptocurrency price data
- Trading view data integration
- Market news API
- Price alerts system
- Rate limiting to prevent abuse
- Circuit breaker for external API protection
- Validation for all inputs
- Detailed error handling
- API access logging
- Performance monitoring
- Framework: Node.js with Express
- Database: MongoDB with Mongoose ODM
- Authentication: JWT and Firebase Auth
- API Documentation: Swagger/OpenAPI
- External Integrations: Binance API, Trading View
- Logging: Winston logger with daily rotation
- Caching: Redis (optional) for performance
- Testing: Jest for unit and integration tests
The backend application follows an MVC-like architecture with the following structure:
ffbBackend/
├── app.js # Express application setup
├── index.js # Application entry point
├── config/ # Configuration files
│ └── config.js # Application configuration
├── controllers/ # API controllers
│ ├── Admin/ # Admin-specific controllers
│ └── User/ # User-specific controllers
├── middleware/ # Express middleware
│ ├── auth.js # Authentication middleware
│ ├── errorHandler.js # Error handling middleware
│ ├── validate.js # Validation middleware
│ └── ... # Other middleware
├── models/ # Mongoose data models
│ ├── User.js # User model
│ ├── Transaction.js # Transaction model
│ └── ... # Other models
├── routes/ # API routes
│ ├── admin.js # Admin routes
│ ├── auth.js # Authentication routes
│ └── ... # Other routes
├── services/ # External service integrations
│ ├── binanceService.js # Binance API integration
│ └── websocket.js # WebSocket service
├── utils/ # Utility functions
│ ├── apiHelper.js # API response helpers
│ ├── dbConnect.js # Database connection
│ └── ... # Other utilities
├── scripts/ # Utility scripts
│ └── checkAndCreateAdmin.js # Admin user creation script
├── logs/ # Application logs
└── uploads/ # File uploads directory
└── kyc/ # KYC document uploads
- Node.js (v14 or higher)
- MongoDB (v4.4 or higher)
- npm or yarn package manager
- Redis (optional, for caching)
-
Clone the repository
-
Install dependencies:
npm install -
Configure environment variables:
- Create a
.envfile based on.env.example - Set the MongoDB connection string
- Configure JWT secret key
- Add other required API keys
- Create a
-
Start the development server:
npm run dev -
Run database initialization (if needed):
npm run init-db
npm run build
The application is configured for deployment on Vercel, AWS, or traditional servers.
Key environment variables include:
PORT: Server port (default: 5000)NODE_ENV: Environment (development, production, test)MONGODB_URI: MongoDB connection stringJWT_SECRET: Secret key for JWT tokensJWT_EXPIRY: JWT token expiration timeBINANCE_API_KEY: Binance API keyBINANCE_API_SECRET: Binance API secretUSE_REDIS: Enable Redis caching (true/false)REDIS_URL: Redis connection URLLOG_LEVEL: Logging level
The API follows RESTful conventions and includes the following main endpoints:
POST /api/auth/register: Register a new userPOST /api/auth/login: User loginPOST /api/auth/refresh-token: Refresh JWT tokenPOST /api/auth/forgot-password: Password recovery
GET /api/users/profile: Get user profilePUT /api/users/profile: Update user profileGET /api/users/transactions: Get user transactionsGET /api/dashboard: Get user dashboard data
POST /api/deposits: Create deposit requestGET /api/deposits: Get deposit historyPOST /api/withdrawals: Create withdrawal requestGET /api/investments: Get investment optionsPOST /api/investments: Make new investment
GET /api/admin/users: Get all usersGET /api/admin/transactions: Get all transactionsPUT /api/admin/transactions/:id: Process transactionGET /api/admin/kyc: Get KYC requestsPUT /api/admin/kyc/:id: Process KYC requestGET /api/admin/analytics: Get admin analytics
The API uses consistent error responses with the following format:
{
"success": false,
"error": {
"code": "validation_error",
"message": "Invalid input data",
"details": [
{
"field": "email",
"message": "Must be a valid email address"
}
]
}
}- All passwords are hashed using bcrypt
- JWT tokens with limited validity period
- HTTPS-only in production
- Rate limiting to prevent brute force attacks
- Input validation on all endpoints
- Sanitization of user-provided data
- Comprehensive error logging
- Fork the repository
- Create a feature branch
- Commit your changes
- Push to the branch
- Open a pull request
[License Information]
For inquiries and support, please contact support@fidelityfirstbrokers.com