A comprehensive banking system built using a microservices architecture with Python and Flask.
MicroBank is a fully-featured banking system implemented using a microservices architecture. The application allows users to manage accounts, process transactions (deposits, withdrawals, transfers), and generate various financial reports. It also includes administrative tools for system-wide management.
-
User Authentication & Authorization
- Registration and login
- JWT-based authentication
- Role-based access control (customer/admin)
-
Account Management
- Create different account types
- View account details
- Close accounts
- Track account balances
-
Transaction Processing
- Deposits
- Withdrawals
- Account transfers
- Transaction history
-
Financial Reporting
- Account reports
- Transaction reports
- System-wide reports (admin only)
-
Admin Dashboard
- User management
- Account oversight
- System health monitoring
- Statistics and analytics
The system is built using a microservices architecture with the following components:
-
API Gateway (
main.py)- Entry point for all client requests
- Handles routing to appropriate microservices
- Manages authentication and session state
-
Auth Service (
auth_service/)- User authentication and authorization
- User account management
- Token generation and validation
-
Account Service (
account_service/)- Account creation and management
- Balance operations
- Account status handling
-
Transaction Service (
transaction_service/)- Process financial transactions
- Maintain transaction history
- Ensure transaction integrity
-
Reporting Service (
reporting_service/)- Generate account reports
- Generate transaction reports
- Provide system-wide analytics (for admin)
- Backend: Python 3.12, Flask 2.x
- Database: SQLite (with SQLAlchemy ORM)
- Frontend: HTML, Bootstrap 5, JavaScript
- Authentication: JWT (JSON Web Tokens)
- Inter-service Communication: RESTful APIs
- Process Management: Custom orchestration via
run_services.py - Package Management: Python's standard pip (with uv acceleration)
- Python 3.12 or higher
- pip (Python package manager)
- Consul (optional, for service discovery)
# Clone the repository
git clone git@github.com:ss-369/Banking_Microservices.git
cd Banking_Microservices
# Create and activate virtual environment
python3 -m venv venv
source venv/bin/activate # or venv\Scripts\activate on Windows
# Install dependencies
pip install -r requirements.txt
# Configure environment variables
export AUTH_SERVICE_URL="http://localhost:8001"
export ACCOUNT_SERVICE_URL="http://localhost:8002"
export TRANSACTION_SERVICE_URL="http://localhost:8003"
export REPORTING_SERVICE_URL="http://localhost:8004"
export SESSION_SECRET="your_secret_key_here"
export AUTH_DATABASE_URL="sqlite:///auth_service/auth.db"
export ACCOUNT_DATABASE_URL="sqlite:///account_service/account.db"
export TRANSACTION_DATABASE_URL="sqlite:///transaction_service/transaction.db"
export REPORTING_DATABASE_URL="sqlite:///reporting_service/reporting.db"
# Run all services
python run_services.pyThen visit http://localhost:5000 in your browser to access the application.
Here's a complete list of environment variables used by the system:
AUTH_SERVICE_URL="http://localhost:8001"
ACCOUNT_SERVICE_URL="http://localhost:8002"
TRANSACTION_SERVICE_URL="http://localhost:8003"
REPORTING_SERVICE_URL="http://localhost:8004"
AUTH_DATABASE_URL="sqlite:///auth_service/auth.db"
ACCOUNT_DATABASE_URL="sqlite:///account_service/account.db"
TRANSACTION_DATABASE_URL="sqlite:///transaction_service/transaction.db"
REPORTING_DATABASE_URL="sqlite:///reporting_service/reporting.db"
SESSION_SECRET="your_secret_key_here" # Used for JWT token signing
CONSUL_HOST="localhost"
CONSUL_PORT="8500"
USE_CONSUL="true" # Enable Consul service discovery
First, clone the repository:
git clone https://github.com/yourusername/microbank.git
cd microbank-
Create a virtual environment:
python3 -m venv venv source venv/bin/activate -
Install dependencies:
pip install -r requirements.txt
-
Create the database directory:
mkdir -p data
-
Set environment variables:
export AUTH_SERVICE_URL="http://localhost:8001" export ACCOUNT_SERVICE_URL="http://localhost:8002" export TRANSACTION_SERVICE_URL="http://localhost:8003" export REPORTING_SERVICE_URL="http://localhost:8004" export SESSION_SECRET="your_secret_key_here" export AUTH_DATABASE_URL="sqlite:///auth_service/auth.db" export ACCOUNT_DATABASE_URL="sqlite:///account_service/account.db" export TRANSACTION_DATABASE_URL="sqlite:///transaction_service/transaction.db" export REPORTING_DATABASE_URL="sqlite:///reporting_service/reporting.db"
-
Run the application:
python run_services.py
This will start all services in a coordinated manner.
-
Create a virtual environment:
python3 -m venv venv source venv/bin/activate -
Install dependencies:
pip install -r requirements.txt
-
Create the database directory:
mkdir -p data
-
Set environment variables:
export AUTH_SERVICE_URL="http://localhost:8001" export ACCOUNT_SERVICE_URL="http://localhost:8002" export TRANSACTION_SERVICE_URL="http://localhost:8003" export REPORTING_SERVICE_URL="http://localhost:8004" export SESSION_SECRET="your_secret_key_here" export AUTH_DATABASE_URL="sqlite:///auth_service/auth.db" export ACCOUNT_DATABASE_URL="sqlite:///account_service/account.db" export TRANSACTION_DATABASE_URL="sqlite:///transaction_service/transaction.db" export REPORTING_DATABASE_URL="sqlite:///reporting_service/reporting.db"
-
Run the application:
python run_services.py
-
Create a virtual environment:
python -m venv venv venv\Scripts\activate
-
Install dependencies:
pip install -r requirements.txt
-
Create the database directory:
mkdir data -
Set environment variables:
set AUTH_SERVICE_URL=http://localhost:8001 set ACCOUNT_SERVICE_URL=http://localhost:8002 set TRANSACTION_SERVICE_URL=http://localhost:8003 set REPORTING_SERVICE_URL=http://localhost:8004 set SESSION_SECRET=your_secret_key_here set AUTH_DATABASE_URL=sqlite:///auth_service/auth.db set ACCOUNT_DATABASE_URL=sqlite:///account_service/account.db set TRANSACTION_DATABASE_URL=sqlite:///transaction_service/transaction.db set REPORTING_DATABASE_URL=sqlite:///reporting_service/reporting.db
-
Run the application:
python run_services.py
The application can be configured using environment variables:
# Service URLs
export AUTH_SERVICE_URL="http://localhost:8001"
export ACCOUNT_SERVICE_URL="http://localhost:8002"
export TRANSACTION_SERVICE_URL="http://localhost:8003"
export REPORTING_SERVICE_URL="http://localhost:8004"
# Database URLs
export AUTH_DATABASE_URL="sqlite:///auth_service/auth.db"
export ACCOUNT_DATABASE_URL="sqlite:///account_service/account.db"
export TRANSACTION_DATABASE_URL="sqlite:///transaction_service/transaction.db"
export REPORTING_DATABASE_URL="sqlite:///reporting_service/reporting.db"
# Security
export SESSION_SECRET="your_secret_key_here"The system supports service discovery using Consul. If you want to use Consul:
-
Install and run Consul:
# On Linux/macOS wget -O- https://apt.releases.hashicorp.com/gpg | sudo gpg --dearmor -o /usr/share/keyrings/hashicorp-archive-keyring.gpg echo "deb [signed-by=/usr/share/keyrings/hashicorp-archive-keyring.gpg] https://apt.releases.hashicorp.com $(lsb_release -cs) main" | sudo tee /etc/apt/sources.list.d/hashicorp.list sudo apt update && sudo apt install consul # Start Consul consul agent -dev
-
Configure the application to use Consul:
export CONSUL_HOST="localhost" export CONSUL_PORT="8500" export USE_CONSUL="true" # Enable Consul service discovery
When Consul is enabled, services will register themselves with Consul at startup and query Consul for service discovery, providing a more production-ready setup.
For production-like environments, use the service orchestrator:
# Run all services with default settings
python run_services.py
# Run services with specific options
python run_services.py --no-auth # Skip auth service
python run_services.py --port 5001 # Run API Gateway on port 5001You can also run each service individually in separate terminals:
# Terminal 1 - Auth Service
source venv/bin/activate # or venv\Scripts\activate on Windows
python -m auth_service.auth_service
# Terminal 2 - Account Service
source venv/bin/activate # or venv\Scripts\activate on Windows
python -m account_service.account_service
# Terminal 3 - Transaction Service
source venv/bin/activate # or venv\Scripts\activate on Windows
python -m transaction_service.transaction_service
# Terminal 4 - Reporting Service
source venv/bin/activate # or venv\Scripts\activate on Windows
python -m reporting_service.reporting_service
# Terminal 5 - API Gateway
source venv/bin/activate # or venv\Scripts\activate on Windows
export AUTH_SERVICE_URL="http://localhost:8001"
export ACCOUNT_SERVICE_URL="http://localhost:8002"
export TRANSACTION_SERVICE_URL="http://localhost:8003"
export REPORTING_SERVICE_URL="http://localhost:8004"
export SESSION_SECRET="your_secret_key_here"
export AUTH_DATABASE_URL="sqlite:///auth_service/auth.db"
export ACCOUNT_DATABASE_URL="sqlite:///account_service/account.db"
export TRANSACTION_DATABASE_URL="sqlite:///transaction_service/transaction.db"
export REPORTING_DATABASE_URL="sqlite:///reporting_service/reporting.db"
python main.pyOnce all services are running, access the application at http://localhost:5000
To access admin features, use the following credentials:
- Username:
admin - Password:
admin123
Each microservice maintains its own SQLite database:
- Auth Service:
auth_service/auth.db - Account Service:
account_service/account.db - Transaction Service:
transaction_service/transaction.db - Reporting Service:
reporting_service/reporting.db
These databases are initialized automatically on first run.
-
Service connection errors
- Verify that all services are running on their expected ports
- Check that environment variables for service URLs are correctly set
- Look for firewall issues that might be blocking the ports
-
JWT authentication failures
- Ensure the
SESSION_SECRETenvironment variable is set consistently - Check that the token hasn't expired
- Verify that the token is correctly formatted in the request header
- Ensure the
-
Module not found errors
- Make sure all dependencies are installed with
pip install -r requirements.txt - Verify that you're running the commands from the project root directory
- Check that your virtual environment is activated
- Make sure all dependencies are installed with
If you encounter issues, check the service logs for more detailed error information. When running with run_services.py, logs are output to the console. You can redirect them to files for persistence:
python run_services.py > microbank.log 2>&1├── account_service/ # Account microservice
│ ├── account_models.py # Account-specific models
│ ├── account_service.py # Account API endpoints
│ ├── account_storage.py # Account data storage
│ └── account.db # Account SQLite database
├── auth_service/ # Authentication microservice
│ ├── auth_models.py # Auth-specific models
│ ├── auth_service.py # Auth API endpoints
│ ├── auth_storage.py # User data storage
│ └── auth.db # Auth SQLite database
├── reporting_service/ # Reporting microservice
│ ├── reporting_models.py # Report-specific models
│ ├── reporting_service.py # Reporting API endpoints
│ ├── reporting_storage.py # Report data storage
│ └── reporting.db # Reporting SQLite database
├── static/ # Static assets
│ ├── css/ # CSS stylesheets
│ └── js/ # JavaScript files
├── templates/ # HTML templates
├── transaction_service/ # Transaction microservice
│ ├── transaction_models.py # Transaction-specific models
│ ├── transaction_service.py # Transaction API endpoints
│ ├── transaction_storage.py # Transaction data storage
│ └── transaction.db # Transaction SQLite database
├── data/ # Additional data storage directory
├── api_gateway.py # API Gateway helper functions
├── main.py # API Gateway implementation
├── models.py # Core data models
├── run_services.py # Service orchestration
├── storage.py # Base storage functionality
├── utils.py # Utility functions
├── requirements.txt # Python dependencies
├── pyproject.toml # Python project metadata
└── uv.lock # Dependency lock file for uv
| Endpoint | Method | Description | Access |
|---|---|---|---|
/api/auth/register |
POST | Register new user | Public |
/api/auth/login |
POST | Authenticate user | Public |
/api/auth/verify_token |
GET | Verify JWT token | Private |
/api/auth/users |
GET | List all users | Admin |
/api/auth/verify_admin |
GET | Verify admin role | Private |
/api/health |
GET | Service health check | Public |
| Endpoint | Method | Description | Access |
|---|---|---|---|
/api/accounts/create |
POST | Create new account | Private |
/api/accounts/list |
GET | List user accounts | Private |
/api/accounts/details/<account_id> |
GET | Get account details | Private |
/api/accounts/close/<account_id> |
DELETE | Close account | Private |
/api/accounts/all |
GET | List all accounts | Admin |
/api/health |
GET | Service health check | Public |
| Endpoint | Method | Description | Access |
|---|---|---|---|
/api/transactions/deposit |
POST | Create deposit | Private |
/api/transactions/withdraw |
POST | Create withdrawal | Private |
/api/transactions/transfer |
POST | Create transfer | Private |
/api/transactions/list |
GET | List user transactions | Private |
/api/transactions/account/<account_id> |
GET | Get account transactions | Private |
/api/health |
GET | Service health check | Public |
| Endpoint | Method | Description | Access |
|---|---|---|---|
/api/reports/account/<account_id> |
GET | Generate account report | Private |
/api/reports/transactions |
GET | Generate transaction report | Private |
/api/reports/system |
GET | Generate system report | Admin |
/api/reports/list |
GET | List user reports | Private |
/api/health |
GET | Service health check | Public |
The system implements a multi-layered error handling approach:
-
Service-level error handling
- Try-except blocks for catching exceptions
- Appropriate HTTP status codes for different error conditions
- Structured error responses with clear messages
-
Gateway-level error handling
- Error response formatting for client consumption
- Error page rendering for user-friendly error display
- Logging of service failures
All error responses follow a standardized format:
{
"success": false,
"message": "Error description",
"error_code": "ERROR_CODE",
"details": {}
}Each service exposes a /api/health endpoint for monitoring. The API Gateway aggregates health status from all services at the /health endpoint.
- JWT-based Authentication: Secure user sessions with token-based auth
- Role-based Access Control: Different permissions for customer and admin roles
- Password Security: Password hashing with salt-based storage
- Microservice Isolation: Each service runs on a separate port
For a smoother development experience, consider setting up environment variables in a .env file:
AUTH_SERVICE_URL=http://localhost:8001
ACCOUNT_SERVICE_URL=http://localhost:8002
TRANSACTION_SERVICE_URL=http://localhost:8003
REPORTING_SERVICE_URL=http://localhost:8004
SESSION_SECRET=dev_secret_key
AUTH_DATABASE_URL=sqlite:///auth_service/auth.db
ACCOUNT_DATABASE_URL=sqlite:///account_service/account.db
TRANSACTION_DATABASE_URL=sqlite:///transaction_service/transaction.db
REPORTING_DATABASE_URL=sqlite:///reporting_service/reporting.db
Then use python-dotenv to load them:
pip install python-dotenvAnd at the top of your run script:
from dotenv import load_dotenv
load_dotenv()This project is licensed under the MIT License - see the LICENSE file for details.
- This project was developed as a demonstration of microservices architecture principles
- Built with Flask and Python, leveraging their simplicity and power