A Node.js backend service for managing financial accounts with support for large number transactions and real-time updates.
- Account registration and management
- Deposit and withdrawal operations
- Real-time balance updates via WebSocket
- Support for large numbers (beyond JavaScript's MAX_SAFE_INTEGER)
- Paginated transaction history
- Concurrent operation handling
- MongoDB aggregation for balance calculation
- Node.js (v14 or higher)
- MongoDB (v4.4 or higher)
- npm or yarn
- Clone the repository
- Install dependencies:
npm install
- Create a
.env
file in the root directory with the following variables:PORT=5000 MONGODB_URI=mongodb://<username>:<password>@<cluster-url> FRONTEND_URL=http://localhost:3000 NODE_ENV=development
- Start the development server:
npm run dev
More details can be found in docs
folder, API.md
for detailed information on API requests and responses.
Also includes import for postman collection in docs
folder, Striga-Account-Management.postman_collection.json
.
POST /api/accounts/register
- Register a new accountPOST /api/accounts/deposit
- Deposit fundsPOST /api/accounts/withdraw
- Withdraw fundsGET /api/accounts/:id/balance
- Get account balanceGET /api/accounts/:id/transactions
- Get transaction history (paginated)
The server emits real-time updates for account balance changes:
- Event:
balance:{accountId}
- Payload:
{ type: 'CREDIT' | 'DEBIT', amount: string }
Run the concurrent operations test with various options:
# Run test with new account (default)
npm run test:concurrent
# Run test with existing account
npm run test:concurrent -- --account-id YOUR_ACCOUNT_ID
# Run test with database cleanup
npm run test:concurrent -- --clean-db
# Run test with both options
npm run test:concurrent -- --account-id YOUR_ACCOUNT_ID --clean-db
Note: The double -- --
is required when passing arguments through npm run. The first --
is for npm, and the second one is for the actual script arguments. I.E npm run test:concurrent -- -- --clean-db
Test Options:
--account-id
: Use an existing account instead of creating a new one--clean-db
: Clean the database before running tests (default: false)
The test will:
- Connect to MongoDB
- Clean the database (if --clean-db flag is set)
- Use existing account or create a new one
- Execute multiple concurrent deposits and withdrawals
- Verify the final balance
- Show performance metrics
The API uses standard HTTP status codes and returns errors in the following format:
{
"status": "error",
"message": "Error description"
}
- Uses MongoDB indexes for efficient querying
- Implements string-based big number operations
- Handles concurrent transactions safely
- Uses WebSocket for real-time updates
- Implements pagination for large datasets
- Input validation for all endpoints
- Error handling and sanitization
- No external big number libraries (custom implementation)
- Environment variable configuration
- CORS protection