Skip to content

MalharBhatt-dev/BankingCore

Folders and files

NameName
Last commit message
Last commit date

Latest commit

ย 

History

77 Commits
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 

Repository files navigation

๐Ÿฆ Banking Core System

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.


๐Ÿ“Œ Overview

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.


๐Ÿ— System Architecture

The application follows a clean layered structure:

Interface Layer (CLI / REST)
        โ†“
Service Layer (Business Logic)
        โ†“
Repository Layer (Data Access)
        โ†“
SQLite Database

๐ŸŒ Dual Interface Support

๐Ÿ–ฅ CLI Interface

  • Console-driven interaction
  • Menu-based operation
  • Thin controller structure
  • Exception-aware handling

๐ŸŒ REST API (Flask)

  • JSON-based communication
  • Proper HTTP status codes
  • Centralized global error handling
  • Thread-safe SQLite configuration
  • Clean endpoint structure

๐Ÿ”น REST API Endpoints

Create Account

POST /accounts

View Balance

GET /accounts/<int:account_number>

Deposit

POST /accounts/<int:account_number>/deposit

Withdraw

POST /accounts/<int:account_number>/withdraw

View Transaction History

GET /accounts/<int:account_number>/transactions

All endpoints return structured JSON responses with proper HTTP status codes.


๐Ÿงฑ Application Layers

1๏ธโƒฃ Entities (Domain Models)

  • Account

  • Transaction

    Purpose:

    • Represent business objects
    • Decouple service layer from database schema
    • Improve readability and maintainability

2๏ธโƒฃ Service Layer (BankingServices)

Responsibilities:

  • Input validation
  • Business rule enforcement
  • Transaction coordination
  • Atomic commit / rollback control
  • Raising domain-specific exceptions

This layer contains zero SQL code.

3๏ธโƒฃ Repository Layer (AccountRepository)

Responsibilities:

  • 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.

4๏ธโƒฃ Interface Layer

CLI Controller (main.py)

  • Handles user interaction
  • Catches domain exceptions
  • Calls service methods only

REST Controller (api.py)

  • Receives HTTP requests
  • Delegates logic to service layer
  • Uses global error handlers

๐Ÿ’พ Database Design

SQLite is used for persistent storage.

accounts Table

| 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 |

transactions Table

| 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                |

This design provides:

  • Persistent storage
  • Full audit trail
  • Transaction history tracking
  • Migration-ready schema

๐ŸŽฏ Core Features

โœ… Account Creation

  • Validates account holder name (alphabet + spaces only)
  • Validates initial deposit โ‰ฅ 0
  • Auto-generates unique account number
  • Logs initial deposit transaction

โœ… Deposit

  • Validates account existence
  • Validates positive amount
  • Updates balance atomically
  • Logs transaction

โœ… Withdrawal

  • Validates account existence
  • Validates positive amount
  • Ensures sufficient balance
  • Updates balance atomically
  • Logs transaction

โœ… View Balance

  • Retrieves current balance from database

โœ… View Transaction History

  • Returns full transaction log
  • Includes type, amount, balance_after, timestamp

โš ๏ธ Exception Architecture

Custom domain exception hierarchy:

  • BankingException (Base)
  • AccountNotFoundException
  • InvalidAmountException
  • InsufficientBalanceException
  • InvalidAccountNameException

REST API uses global error handlers to convert exceptions into proper HTTP responses.


๐Ÿงช Validation Rules

  • 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

๐Ÿ“‚ Project Structure

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

๐Ÿš€ Development Evolution

Phase 1 โ€“ CLI Foundation

  • Basic operations with in-memory storage.

Phase 2 โ€“ SQLite Integration

  • Persistent database + transaction safety.

Phase 3 โ€“ Repository Pattern

  • Separation of business logic from SQL.

Phase 4 โ€“ Entity Modeling

  • Mapping DB rows to domain objects.

Phase 5 โ€“ Custom Exception Hierarchy

  • Domain-driven error handling.

###Phase 6 โ€“ REST API Implementation

  • Flask integration, JSON endpoints, HTTP status codes.

Phase 7 โ€“ Global Error Handling

  • Centralized exception management for clean API design.

๐Ÿง  Engineering Principles Applied

  • 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

๐ŸŽ“ Learning Outcomes

This project demonstrates:

  • Backend system architecture
  • Database persistence handling
  • Service-layer business modeling
  • Exception hierarchy design
  • REST API construction
  • Thread-aware SQLite integration
  • Clean layered engineering

๐Ÿ”ฎ Future Enhancements

  • PIN-based authentication
  • Account locking mechanism
  • Logging & monitoring layer
  • Unit & integration testing
  • Blueprint & App Factory refactor
  • MySQL/PostgreSQL migration
  • Dockerization
  • CI/CD pipeline integration

๐Ÿ“˜ Development Log

For full architectural evolution details:

docs/development_log.md

โšก Philosophy

Start simple. Refactor intentionally. Separate responsibilities. Persist safely. Design for evolution.


๐Ÿฆ Built as a structured backend architecture project demonstrating real-world engineering practices.

About

A modular backend banking system implementing core banking features such as account management, transactions, authentication, rate limiting, and security best practices. Designed with clean architecture principles and built for learning scalable financial system design.

Topics

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors