A production-structured backend banking system built using Python, SQLite, and Flask.
This project evolved from a simple CLI application into a layered backend architecture supporting both:
- ๐ฅ CLI Interface
- ๐ REST API Interface
It demonstrates clean architecture principles, database persistence, structured exception handling, and scalable backend design.
The Banking Core System simulates real-world banking operations while applying professional backend engineering practices.
The system supports:
- Account creation
- Deposit funds
- Withdraw funds
- View account balance
- View transaction history
Unlike basic tutorial projects, this system implements:
- Layered Architecture
- Repository Pattern
- Domain Entity Modeling
- Custom Exception Hierarchy
- SQLite Persistence
- Atomic Transaction Handling
- RESTful API Exposure
- Global Error Handling
All data is stored in SQLite, ensuring persistence across application restarts.
The application follows a clean layered structure:
Interface Layer (CLI / REST)
โ
Service Layer (Business Logic)
โ
Repository Layer (Data Access)
โ
SQLite Database- Console-driven interaction
- Menu-based operation
- Thin controller structure
- Exception-aware handling
- JSON-based communication
- Proper HTTP status codes
- Centralized global error handling
- Thread-safe SQLite configuration
- Clean endpoint structure
POST /accountsGET /accounts/<int:account_number>POST /accounts/<int:account_number>/depositPOST /accounts/<int:account_number>/withdrawGET /accounts/<int:account_number>/transactionsAll endpoints return structured JSON responses with proper HTTP status codes.
-
Account -
Transaction- Represent business objects
- Decouple service layer from database schema
- Improve readability and maintainability
- Input validation
- Business rule enforcement
- Transaction coordination
- Atomic commit / rollback control
- Raising domain-specific exceptions
This layer contains zero SQL code.
- SQLite connection management
- SQL execution
- CRUD operations
- Mapping DB rows โ Entity objects
- SQLite connection configured with:
sqlite3.connect(DB_PATH, check_same_thread=False)Ensures compatibility with Flask's multi-threaded environment.
- Handles user interaction
- Catches domain exceptions
- Calls service methods only
- Receives HTTP requests
- Delegates logic to service layer
- Uses global error handlers
| Column | Description |
| ------------------- | -------------------------- |
| id | Primary key |
| account_number | Unique account identifier |
| account_holder_name | Account owner name |
| balance | Current account balance |
| created_at | Account creation timestamp || Column | Description |
| -------------- | ------------------------------------ |
| id | Primary key |
| account_number | Foreign key reference |
| type | INITIAL DEPOSIT / DEPOSIT / WITHDRAW |
| amount | Transaction amount |
| balance_after | Balance after transaction |
| timestamp | Transaction timestamp |- Persistent storage
- Full audit trail
- Transaction history tracking
- Migration-ready schema
- Validates account holder name (alphabet + spaces only)
- Validates initial deposit โฅ 0
- Auto-generates unique account number
- Logs initial deposit transaction
- Validates account existence
- Validates positive amount
- Updates balance atomically
- Logs transaction
- Validates account existence
- Validates positive amount
- Ensures sufficient balance
- Updates balance atomically
- Logs transaction
- Retrieves current balance from database
- Returns full transaction log
- Includes type, amount, balance_after, timestamp
BankingException(Base)AccountNotFoundExceptionInvalidAmountExceptionInsufficientBalanceExceptionInvalidAccountNameException
- Account name must contain only letters and spaces
- Initial deposit must be โฅ 0
- Deposit amount must be > 0
- Withdrawal amount must be > 0
- Withdrawal must not exceed balance
- Account must exist before operation
banking-core/
โ
โโโ entities/
โ โโโ account.py
โ โโโ transaction.py
โ
โโโ repository/
โ โโโ account_repository.py
โ
โโโ services/
โ โโโ banking_services.py
โ
โโโ exceptions/
โ โโโ base_exception.py
โ โโโ account_not_found_exception.py
โ โโโ invalid_amount_exception.py
โ โโโ insufficient_balance_exception.py
โ โโโ invalid_account_name_exception.py
โ
โโโ database/
โ โโโ accounts.db
โ
โโโ docs/
โ โโโ development_log.md
โ
โโโ api.py
โโโ main.py
โโโ README.md- Basic operations with in-memory storage.
- Persistent database + transaction safety.
- Separation of business logic from SQL.
- Mapping DB rows to domain objects.
- Domain-driven error handling.
###Phase 6 โ REST API Implementation
- Flask integration, JSON endpoints, HTTP status codes.
- Centralized exception management for clean API design.
- Object-Oriented Programming
- Separation of Concerns
- Single Responsibility Principle
- Repository Pattern
- Layered Architecture
- Dependency Injection
- At mic Transactions
- Domain Modeling
- RESTful Design
- Centralized Error Handling
- Backend system architecture
- Database persistence handling
- Service-layer business modeling
- Exception hierarchy design
- REST API construction
- Thread-aware SQLite integration
- Clean layered engineering
- PIN-based authentication
- Account locking mechanism
- Logging & monitoring layer
- Unit & integration testing
- Blueprint & App Factory refactor
- MySQL/PostgreSQL migration
- Dockerization
- CI/CD pipeline integration
docs/development_log.mdStart simple. Refactor intentionally. Separate responsibilities. Persist safely. Design for evolution.
๐ฆ Built as a structured backend architecture project demonstrating real-world engineering practices.