A production-style Bank Account Management API built with FastAPI, SQLAlchemy, and MySQL.
Designed to simulate real-world fintech backend systems with secure authentication, transactional integrity, and rule-based financial operations.
Watch Full Demo:- https://youtu.be/iex0donzgtE
- Frontend: https://fastapi-banking-system.vercel.app
- Backend API: https://fastapi-banking-system.onrender.com
- API Docs: https://fastapi-banking-system.onrender.com/docs
- JWT-based authentication
- Secure password hashing (bcrypt)
- Case-insensitive username handling
- Protected routes using dependency injection
- Create multiple accounts per user
- Unique account number enforcement
- Accounts initialized with zero balance (system-controlled)
- Fetch all user accounts securely
Accounts are not physically deleted. Instead, they are marked as:
ACTIVE→ usable accountCLOSED→ hidden from UI and blocked from operations
This ensures:
- Data integrity
- Transaction history preservation
- Real-world banking behavior
- Deposit funds
- Withdraw funds with balance validation
- Transfer money between accounts
Prevent overdraft (no negative balance)
- Prevent overdraft (no negative balance)
- Prevent self-transfers
- Only ACTIVE accounts can perform operations
- Atomic database transactions using commit/rollback
- Deposit limit per transaction
- Withdraw limit per transaction
- Transfer limit enforcement
Limits are centrally managed via a config module, making the system flexible and maintainable.
-
Every operation (deposit, withdraw, transfer) is recorded
-
Enables audit tracking and system transparency
-
Foundation for future features like:
- Statements
- Analytics
- Fraud detection
-
Strong input validation using Pydantic schemas
-
Backend-driven validation (never trusting frontend)
-
Ownership-based authorization
-
SClean separation of validation and business logic:
- Data validation (schemas)
- Business logic (routes/services)
| Layer | Technology |
|---|---|
| Backend | FastAPI |
| ORM | SQLAlchemy |
| Database | MySQL |
| Validation | Pydantic |
| Auth | JWT (python-jose) |
| Security | Passlib (bcrypt) |
| Config | python-dotenv |
fastapi-banking-system/
│
├── app/
│ ├── routes/ # API endpoints
│ (auth, accounts, transactions)
│ ├── models/ # Database models
│ ├── schemas/ # Request/response validation
│ ├── db/ # DB connection setup
│ ├── core/ # Security, config (JWT, hashing, limits)
│ └── dependencies/ # Auth middleware
│
├── main.py
├── requirements.txt
├── .env
└── .gitignore
git clone https://github.com/Dhruv-Cmds/fastapi-banking-system.git
cd fastapi-banking-systempython -m venv .venvWindows
.venv\Scripts\activateMac/Linux
source .venv/bin/activatepip install -r requirements.txtCreate a .env file:
DB_USER=root
DB_PASSWORD=your_password
DB_HOST=localhost
DB_NAME=bankaccountsystem
SECRET_KEY=your_secret_key
ALGORITHM=HS256
ACCESS_TOKEN_EXPIRE_MINUTES = your_time
IF You Want to go live:
MYSQL_PUBLIC_URL = your_url
SECRET_KEY=your_secret_key
ALGORITHM=HS256
ACCESS_TOKEN_EXPIRE_MINUTES = your_timeuvicorn main:app --reload (backend)
npm run dev (frontend)POST /signupPOST /login
POST /accountsGET /accountsDELETE /accounts/{id} → closes account
POST /accounts/{id}/depositPOST /accounts/{id}/withdrawPOST /transfer
- Tables auto-created at startup:
Base.metadata.create_all(bind=engine)- Account lifecycle:
Create account → balance = 0
Deposit → increases balance
Withdraw → decreases balance
Transfer → moves funds safely
Close account → status = CLOSED (not deleted)
- JWT authentication
- Password hashing (bcrypt)
- Environment-based secrets
- Ownership-based authorization checks
- Safe transaction handling using DB locks
- Protection against race conditions
- Clean, modular architecture
- Real-world banking logic implementation
- Soft-delete system (account lifecycle)
- Transaction safety (race-condition prevention)
- Rule-based financial system (limits + validation)
- Scalable backend design
This project demonstrates how to build a real-world backend system with:
- Authentication & authorization
- Database design & ORM usage
- Transaction safety & concurrency handling
- Business rule enforcement
- Clean architecture & scalability
It serves as a strong foundation for evolving into a full fintech platform 🚀
Dhruv Backend-focused developer building systems with strong fundamentals in API design, data integrity, and system thinking.