Backend Ledger API

A secure, scalable ledger management REST API with JWT authentication, account management & atomic transactions.

Node.js + Express MongoDB Atlas JWT Auth

https://backend-ledger-8to4.onrender.com
๐Ÿ”

JWT Authentication

Secure token-based auth with bcrypt password hashing & token blacklisting on logout.

๐Ÿ’ฐ

Ledger-Based Balances

Double-entry bookkeeping with immutable ledger entries. Balances derived from credit/debit aggregation.

โšก

Atomic Transactions

MongoDB sessions ensure ACID compliance. Idempotency keys prevent duplicate processing.

๐Ÿ“ง

Email Notifications

Automated emails via Gmail OAuth2 for registration confirmations and transaction alerts.

โšก Try It Live

๐Ÿ”‘
Authentication
POST /api/auth/register Register a new user

Request Body

{
  "name": "John Doe",
  "email": "john@example.com",
  "password": "securepassword123"
}

Response 201

{
  "user": { "_id": "...", "email": "...", "name": "..." },
  "token": "jwt_token_here"
}
POST /api/auth/login Login & get token

Request Body

{
  "email": "john@example.com",
  "password": "securepassword123"
}

Response 200

{
  "user": { "_id": "...", "email": "...", "name": "..." },
  "token": "jwt_token_here"
}
POST /api/auth/logout Logout & blacklist token ๐Ÿ”’

Headers

Authorization: Bearer <token>

Response 200

{ "message": "User logged out successfully" }
๐Ÿฆ
Accounts
POST /api/accounts/ Create account ๐Ÿ”’

Headers

Authorization: Bearer <token>

Response 201

{
  "account": {
    "_id": "...", "user": "...",
    "status": "ACTIVE", "currency": "INR"
  }
}
GET /api/accounts/ Get user accounts ๐Ÿ”’

Headers

Authorization: Bearer <token>

Response 200

{ "accounts": [ { "_id": "...", "status": "ACTIVE", ... } ] }
GET /api/accounts/balance/:accountId Get account balance ๐Ÿ”’

Headers

Authorization: Bearer <token>

Response 200

{ "accountId": "...", "balance": 1000 }
๐Ÿ’ธ
Transactions
POST /api/transactions/ Transfer funds ๐Ÿ”’

Request Body

{
  "fromAccount": "account_id_1",
  "toAccount": "account_id_2",
  "amount": 500,
  "idempotencyKey": "unique_key_123"
}

Response 201

{
  "message": "Transaction completed successfully",
  "transaction": { "_id": "...", "status": "COMPLETED", ... }
}
POST /api/transactions/system/initial-funds System: add initial funds โš™๏ธ๐Ÿ”’

Headers

Authorization: Bearer <system_token>

Request Body

{
  "toAccount": "account_id",
  "amount": 10000,
  "idempotencyKey": "unique_key_456"
}

Response 201

{
  "message": "Initial funds transaction completed successfully",
  "transaction": { ... }
}