A Django-based banking system that allows users to manage accounts, perform transactions (deposits, withdrawals, transfers), and track balances computed from transaction history.
- ✅ User account management with authentication
- ✅ Real-time balance calculation from transaction history
- ✅ Secure money transfers between users
- ✅ Deposit and withdrawal operations
- ✅ Complete transaction audit trail
- ✅ Token-based authentication
- ✅ Admin panel for staff operations
- ✅ Historical balance queries (bonus feature)
- Install dependencies:
pip install -r requirements.txt- Run migrations:
python manage.py migrate
python manage.py createsuperuser- Start server:
python manage.py runserverAll endpoints except user creation and login require authentication. Include the token in the Authorization header:
Authorization: Token <your_token_here>
POST /users
Content-Type: application/json
{
"username": "testuser",
"email": "[email protected]",
"password": "testpass123",
"first_name": "Test",
"last_name": "User"
}Response:
{
"id": 1,
"username": "testuser",
"email": "[email protected]",
"first_name": "Test",
"last_name": "User",
"date_joined": "2025-08-16T10:30:00Z",
"is_active": true
}POST /auth/login
Content-Type: application/json
{
"username": "testuser",
"password": "testpass123"
}Response:
{
"token": "abc123def456...",
"user_id": 1,
"username": "testuser",
"message": "Login successful"
}POST /auth/logout
Authorization: Token abc123def456...Response:
{
"message": "Successfully logged out"
}POST /accounts
Authorization: Token abc123def456...
Content-Type: application/json
{
"bank_name": "Savings Bank",
"branch": "Main Branch"
}Response:
{
"id": 1,
"bank_name": "Savings Bank",
"branch": "Main Branch",
"user_id": 1,
"username": "testuser",
"balance": "0.00",
"created_at": "2025-08-16T10:30:00Z"
}GET /accounts/{account_id}
Authorization: Token abc123def456...Response:
{
"name": "Test User",
"bank": "Savings Bank",
"branch": "Main Branch",
"balance": "1000.00"
}GET /accounts/all
Authorization: Token abc123def456...Response:
[
{
"id": 1,
"user_id": 1,
"bank_name": "Savings Bank",
"branch": "Main Branch",
"created_at": "2025-08-16T10:30:00Z"
}
]GET /accounts/{account_id}/balance
Authorization: Token abc123def456...Response:
{
"balance": "1000.00"
}POST /transactions/deposit
Authorization: Token abc123def456...
Content-Type: application/json
{
"account_id": 1,
"amount": "100.00",
"note": "Initial deposit"
}Response:
{
"id": 1,
"account_id": 1,
"amount": "100.00",
"transaction_type": "DEPOSIT",
"status": "SUCCESS",
"note": "Initial deposit",
"created_at": "2025-08-16T10:30:00Z",
"new_balance": "100.00"
}POST /transactions/withdraw
Authorization: Token abc123def456...
Content-Type: application/json
{
"account_id": 1,
"amount": "50.00",
"note": "ATM withdrawal"
}Response:
{
"id": 2,
"account_id": 1,
"amount": "50.00",
"transaction_type": "WITHDRAWAL",
"status": "SUCCESS",
"note": "ATM withdrawal",
"created_at": "2025-08-16T10:35:00Z",
"new_balance": "50.00"
}POST /transactions/transfer
Authorization: Token abc123def456...
Content-Type: application/json
{
"from_account_id": 1,
"to_account_id": 2,
"amount": "25.00",
"note": "Payment for services"
}Response:
{
"debit_transaction": {
"id": 3,
"account_id": 1,
"amount": "25.00",
"transaction_type": "TRANSFER",
"status": "SUCCESS",
"note": "Transfer to user2: Payment for services",
"created_at": "2025-08-16T10:40:00Z"
},
"credit_transaction": {
"id": 4,
"account_id": 2,
"amount": "25.00",
"transaction_type": "TRANSFER",
"status": "SUCCESS",
"note": "Transfer from testuser: Payment for services",
"created_at": "2025-08-16T10:40:00Z"
},
"from_account_balance": "25.00",
"to_account_balance": "25.00",
"transfer_amount": "25.00"
}GET /transactions/{account_id}
Authorization: Token abc123def456...Response:
[
{
"id": 1,
"account_id": 1,
"amount": "100.00",
"transaction_type": "DEPOSIT",
"status": "SUCCESS",
"note": "Initial deposit",
"created_at": "2025-08-16T10:30:00Z"
}
]All endpoints return consistent error responses:
{
"error": "Error message description"
}Common HTTP status codes:
400- Bad Request (validation errors, insufficient balance)401- Unauthorized (missing or invalid token)404- Not Found (account/user doesn't exist)500- Internal Server Error
- Create a user account:
curl -X POST http://localhost:8000/users \
-H "Content-Type: application/json" \
-d '{"username": "alice", "email": "[email protected]", "password": "pass123", "first_name": "Alice", "last_name": "Smith"}'- Login to get token:
curl -X POST http://localhost:8000/auth/login \
-H "Content-Type: application/json" \
-d '{"username": "alice", "password": "pass123"}'- Create bank account:
curl -X POST http://localhost:8000/accounts \
-H "Authorization: Token YOUR_TOKEN_HERE" \
-H "Content-Type: application/json" \
-d '{"bank_name": "My Bank", "branch": "Downtown"}'- Make a deposit:
curl -X POST http://localhost:8000/transactions/deposit \
-H "Authorization: Token YOUR_TOKEN_HERE" \
-H "Content-Type: application/json" \
-d '{"account_id": 1, "amount": "1000.00", "note": "Initial deposit"}'- Check balance:
curl -X GET http://localhost:8000/accounts/1/balance \
-H "Authorization: Token YOUR_TOKEN_HERE"