Skip to content

A lightweight banking API built with FastAPI and SQLAlchemy for account management, transactions, and financial tracking.

Notifications You must be signed in to change notification settings

inesruizblach/LiteBank

Folders and files

NameName
Last commit message
Last commit date

Latest commit

Β 

History

13 Commits
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 

Repository files navigation

LiteBank API 🏦

LiteBank is a modern, lightweight banking API built with FastAPI and SQLAlchemy β€” designed to handle user accounts, transactions, and secure financial operations with JWT authentication.


🌐 Live Deployment

LiteBank is now live and hosted on Render πŸš€
πŸ”— Live API: https://litebank.onrender.com
🩺 Health Check: https://litebank.onrender.com/healthz
πŸ“˜ Interactive Docs: https://litebank.onrender.com/docs

Deployed automatically via GitHub Actions β†’ Render CI/CD pipeline.

Features

  • πŸ‘€ Create and manage user profiles
  • πŸ’° Deposit and withdraw funds
  • πŸ”„ Transfer money between accounts
  • 🧾 View transaction history
  • πŸ” JWT-based authentication
  • 🐳 Dockerized for easy deployment

Tech Stack

Category Technology
Language Python 3.11
Framework FastAPI
ORM SQLAlchemy
Auth FastAPI-JWT-Auth
Database PostgreSQL / SQLite
Server Uvicorn
Migrations Alembic
Containerization Docker
Deployment Render (via GitHub Actions)

Getting Started (Local)

  1. Clone the repo
git clone https://github.com/inesruizblach/LiteBank.git
cd LiteBank
  1. Set up env

Option A: Create a virtual environment

python3 -m venv venv
source venv/bin/activate   # macOS/Linux
venv\Scripts\activate      # Windows

Option B: Create a conda environment

conda create -n litebank python=3.11
conda activate litebank
  1. Install dependencies
pip install -r requirements.txt
  1. Run the API locally
uvicorn app.main:app --reload
  1. Visit:

Example Endpoints

πŸ‘₯ Users

  1. List users
GET /users/
  1. Create new users
POST /users/

πŸ”‘ Authentication

  1. Login to get JWT token
POST /login

πŸ’΅ Accounts (JWT required)

  1. Create and list accounts
POST /accounts/
GET /accounts/

πŸ’Έ Transactions Endpoints (JWT required)

  1. Perform deposits, withdrawals, or transfers:
POST /transactions/
POST /transactions/transfer/
GET /transactions/

Local Run Test Cases - Example API calls

πŸ‘₯ Users

  1. List users
curl -X GET "http://127.0.0.1:8000/users/"
  1. Create new users
curl -X POST "http://127.0.0.1:8000/users/" \
-H "Content-Type: application/json" \
-d '{"name":"User1","email":"user1@example.com","password":"password123"}'
curl -X POST "http://127.0.0.1:8000/users/" \
-H "Content-Type: application/json" \
-d '{"name":"User2","email":"user2@example.com","password":"password123"}'

Expected response:

{"id":1,"name":"User1","email":"user1@example.com"}

πŸ”‘ Authentication

  1. Login to get JWT token
curl -X POST "http://127.0.0.1:8000/login" \
-H "Content-Type: application/json" \
-d '{"email":"user1@example.com","password":"password123"}'

Response:

{
  "access_token": "your_jwt_token",
  "token_type": "bearer"
}

πŸ’΅ Accounts (JWT required)

  1. Create accounts
curl -X POST "http://127.0.0.1:8000/accounts/" \
-H "Authorization: Bearer your_jwt_token" \
-H "Content-Type: application/json" \
-d '{"balance":100}'
curl -X POST "http://127.0.0.1:8000/accounts/" \
-H "Authorization: Bearer your_jwt_token" \
-H "Content-Type: application/json" \
-d '{"balance":50}'

Expected response:

{"id":1,"user_id":1,"balance":0}
  1. List accounts
curl -X GET "http://127.0.0.1:8000/accounts/" \
-H "Authorization: Bearer your_jwt_token"

Expected response (empty if no accounts yet):

[]

πŸ’Έ Transactions Endpoints (JWT required)

  1. Deposit funds
curl -X POST "http://127.0.0.1:8000/transactions/" \
-H "Authorization: Bearer your_jwt_token" \
-H "Content-Type: application/json" \
-d '{"account_id":1,"type":"deposit","amount":100}'

Expected response:

{"id":1,"account_id":1,"type":"deposit","amount":100,"created_at":"2025-10-16T12:00:00"}
  1. Withdraw funds
curl -X POST "http://127.0.0.1:8000/transactions/" \
-H "Authorization: Bearer your_jwt_token" \
-H "Content-Type: application/json" \
-d '{"account_id":1,"type":"withdraw","amount":50}'
  1. Transfer funds
curl -X POST "http://127.0.0.1:8000/transactions/transfer/" \
-H "Authorization: Bearer your_jwt_token" \
-H "Content-Type: application/json" \
-d '{"from_account_id":1,"to_account_id":2,"amount":30}'

Expected response:

{
  "message": "Transferred 50 from account 1 to 2.",
  "from_account_balance": 50,
  "to_account_balance": 50
}
  1. List transactions
curl -X GET "http://127.0.0.1:8000/transactions/" \
-H "Authorization: Bearer your_jwt_token"

Authentication Flow

  1. Signup β†’ Create user with /users/.
  2. Login β†’ Obtain JWT from /auth/login.
  3. Access Protected Routes β†’ Include header: Authorization: Bearer <access_token>

Project Structure

LiteBank/
│── app/
β”‚   β”œβ”€β”€ main.py              # FastAPI entrypoint
β”‚   β”œβ”€β”€ models.py            # SQLAlchemy models
β”‚   β”œβ”€β”€ schemas.py           # Pydantic schemas
β”‚   β”œβ”€β”€ crud.py              # Business logic and DB ops
β”‚   β”œβ”€β”€ database.py          # Database configuration
β”‚   β”œβ”€β”€ config.py            # App/JWT settings
β”‚   └── routers/
β”‚       β”œβ”€β”€ users.py
β”‚       β”œβ”€β”€ accounts.py
β”‚       └── transactions.py
β”‚
β”œβ”€β”€ alembic/                 # Database migrations
β”‚   └── versions/
β”‚
β”œβ”€β”€ .github/
β”‚   └── workflows/
β”‚       └── deploy.yml       # CI/CD pipeline for Render deployment
β”‚
β”œβ”€β”€ Dockerfile               # Docker build configuration
β”œβ”€β”€ docker-compose.yml       # Local dev environment
β”œβ”€β”€ requirements.txt         # Python dependencies
└── README.md


🧰 Development Tools

Command Description
uvicorn app.main:app --reload Run API locally
alembic upgrade head Run DB migrations
pytest Run test suite
docker compose up --build Start app with Docker

🌍 Deployment

LiteBank is automatically deployed to Render using a GitHub Actions workflow (.github/workflows/deploy.yml), which:

  1. Installs dependencies
  2. Runs Alembic migrations on the Render PostgreSQL database
  3. Triggers a new Render deploy

πŸ”— Production URL: https://litebank.onrender.com


πŸ“œ License

This project is open-source and available under the MIT License.


Developed by InΓ©s Ruiz Blach