Skip to content

asadzaheer/account-managment-backend

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

1 Commit
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Striga Account Management Backend

A Node.js backend service for managing financial accounts with support for large number transactions and real-time updates.

Features

  • 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

Prerequisites

  • Node.js (v14 or higher)
  • MongoDB (v4.4 or higher)
  • npm or yarn

Setup

  1. Clone the repository
  2. Install dependencies:
    npm install
  3. 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
    
  4. Start the development server:
    npm run dev

API Endpoints

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.

Account Management

  • POST /api/accounts/register - Register a new account
  • POST /api/accounts/deposit - Deposit funds
  • POST /api/accounts/withdraw - Withdraw funds
  • GET /api/accounts/:id/balance - Get account balance
  • GET /api/accounts/:id/transactions - Get transaction history (paginated)

WebSocket Events

The server emits real-time updates for account balance changes:

  • Event: balance:{accountId}
  • Payload: { type: 'CREDIT' | 'DEBIT', amount: string }

Testing Concurrent Operations

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:

  1. Connect to MongoDB
  2. Clean the database (if --clean-db flag is set)
  3. Use existing account or create a new one
  4. Execute multiple concurrent deposits and withdrawals
  5. Verify the final balance
  6. Show performance metrics

Error Handling

The API uses standard HTTP status codes and returns errors in the following format:

{
  "status": "error",
  "message": "Error description"
}

Performance Considerations

  • 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

Security

  • Input validation for all endpoints
  • Error handling and sanitization
  • No external big number libraries (custom implementation)
  • Environment variable configuration
  • CORS protection

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published