Kelvin-programmer/bank-account-system
0
Bank Account System
Production-grade OOP banking API modeling savings and checking accounts with tiered interest rates and overdraft logic. Built around a clean class hierarchy (BankAccount → SavingsAccount, CheckingAccount) exposed via a FastAPI REST service with a transaction-ledger UI.

Architecture
Client ──▶ FastAPI REST API ──▶ Bank Service ──▶ Account Domain
│ │
▼ ▼
JSON Persistence BankAccount
(atomic write) ├── SavingsAccount (tiered interest)
└── CheckingAccount (overdraft + fee)Domain model:
BankAccount— base class: deposit, withdraw, immutable transaction historySavingsAccount— applies tiered interest (3% ≤ $1K · 5% ≤ $5K · 7% > $5K)CheckingAccount— overrideswithdraw()to allow overdraft up to-$500and assess a$25fee when balance goes negativeTransaction— frozen dataclass; every mutation appends an immutable ledger entry (open,deposit,withdrawal,interest,overdraft_fee)
Features
- Clean OOP hierarchy — inheritance, encapsulation, polymorphism with a base
BankAccountand two specialized subclasses - Tiered interest engine — balance-aware rate selection (3 / 5 / 7%) configurable via environment
- Overdraft logic — configurable limit and fee with balance validation
- Immutable transaction ledger — every deposit, withdrawal, interest accrual, and fee is logged with a timestamp
- REST API — FastAPI with auto-generated OpenAPI/Swagger docs
- Persistent storage — atomic JSON writes survive container restarts
- Thread-safe —
RLock-guarded operations for concurrent access - Rate limiting — sliding-window middleware
- Beautiful dark UI — dashboard with account list, transaction history, and live stats
- Docker — multi-stage build with health checks
- CI/CD — GitHub Actions: lint, test (Python 3.10–3.12), Docker build
- Type-safe config — Pydantic Settings with
.envsupport
Quick Start
Prerequisites
- Python 3.10+
Install & Run
git clone https://github.com/kelvinasiedu-programmer/bank-account-system.git
cd bank-account-system
python -m venv venv
source venv/bin/activate # Windows: venv\Scripts\activate
pip install -r requirements.txt
cp .env.example .env
uvicorn src.main:app --reloadDashboard: http://localhost:8000 · Swagger docs: http://localhost:8000/docs
Docker
cp .env.example .env
docker compose up -dAPI Endpoints
Example
# Open a savings account
curl -X POST http://localhost:8000/api/v1/accounts \
-H "Content-Type: application/json" \
-d '{"account_type":"savings","account_holder":"Jane Doe","initial_balance":1500}'
# Apply interest (will credit 5% → +$75)
curl -X POST http://localhost:8000/api/v1/accounts/{id}/apply-interestResponse Format
{
"account_id": "f3c...",
"account_type": "savings",
"account_holder": "Jane Doe",
"balance": 1575.00,
"history": [
{ "type": "open", "amount": 1500, "balance_after": 1500, "timestamp": "..." },
{ "type": "interest", "amount": 75, "balance_after": 1575, "note": "Tiered interest applied @ 5.0%" }
]
}Configuration
All settings are configurable via environment variables or .env:
Testing
pip install -r requirements-dev.txt
make testCovers domain invariants (tier boundaries, overdraft edge cases), persistence round-trips, and end-to-end API flows.
Project Structure
bank-account-system/
├── src/
│ ├── main.py # FastAPI app, routes, rate limiter, static UI mount
│ ├── config.py # Pydantic Settings
│ ├── accounts.py # BankAccount / SavingsAccount / CheckingAccount
│ ├── bank.py # Registry, persistence, thread-safe service layer
│ ├── schemas.py # Pydantic request/response models
│ └── static/index.html # Dark-theme dashboard
├── tests/
│ ├── conftest.py
│ ├── test_accounts.py # Domain invariants + tier boundaries
│ ├── test_bank.py # Persistence & service layer
│ └── test_api.py # End-to-end FastAPI TestClient
├── .github/workflows/ci.yml
├── Dockerfile
├── docker-compose.yml
├── Makefile
├── pyproject.toml
├── requirements.txt
└── requirements-dev.txtTech Stack
License
MIT
