Skip to content

jcheese54/financial_transaction_api

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

14 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Financial Transaction API

A simple FastAPI-based financial transaction API built as part of a crash-course project to demonstrate API design, layered architecture, database persistence, validation, and testing.

Overview

This project provides a basic financial transaction system that supports:

  • Creating accounts
  • Preventing duplicate accounts
  • Depositing funds
  • Withdrawing funds
  • Transferring funds between accounts
  • Basic idempotency protection for transfers
  • Persistent data storage using SQLite
  • Automated testing with Pytest

The goal of this project is to showcase clean API structure, separation of concerns, and core financial transaction behaviors in a beginner-friendly but professional way.

Tech Stack

  • Python 3
  • FastAPI
  • Uvicorn
  • SQLAlchemy
  • SQLite
  • Pydantic
  • Pytest

Project Structure

financial_transaction_api/
│
├── app/
│   ├── main.py
│   ├── controller/
│   ├── service/
│   ├── repository/
│   ├── schema/
│   ├── model/
│   └── database/
│
├── tests/
├── financial_api.db
├── requirements.txt
├── README.md
└── .gitignore

Features

Account Management

  • Create new financial accounts
  • Prevent duplicate account creation

Transactions

  • Deposit money into an account
  • Withdraw money from an account
  • Prevent withdrawals that exceed available balance
  • Transfer money from one account to another

Reliability

  • Persist data in SQLite so records remain after restart
  • Support idempotent transfer behavior to avoid accidental duplicate processing

Testing

The test suite covers core API behavior, including:

  • Health check
  • Create account
  • Duplicate account handling
  • Deposit
  • Withdrawal
  • Insufficient funds
  • Transfer workflow
  • Transfer idempotency

Setup Instructions

1. Clone the repository

git clone https://github.com/YOUR-USERNAME/financial_transaction_api.git
cd financial_transaction_api

2. Create and activate a virtual environment

Mac/Linux

python3 -m venv venv
source venv/bin/activate

Windows

python -m venv venv
venv\Scripts\activate

3. Install dependencies

pip install -r requirements.txt

4. Run the API

uvicorn app.main:app --reload

The API should now be available locally at:

http://127.0.0.1:8000

Interactive Swagger docs:

http://127.0.0.1:8000/docs

Running Tests

Run the test suite with:

pytest -v

Example Workflow

Typical usage flow:

  1. Create an account
  2. Deposit funds into the account
  3. Withdraw funds if balance allows
  4. Transfer funds between accounts
  5. Verify correct responses through the API or tests

API Design Notes

This project follows a layered architecture to keep responsibilities separated:

  • Controller layer handles incoming API requests and responses
  • Service layer contains business logic
  • Repository layer handles database access
  • Schema layer defines request and response models
  • Model layer defines database tables

This structure makes the project easier to maintain, test, and expand.

Development Notes

Some key concepts practiced in this project include:

  • Building RESTful endpoints with FastAPI
  • Structuring a Python API project into clear layers
  • Using Pydantic for validation
  • Persisting data with SQLite and SQLAlchemy
  • Writing automated tests with Pytest
  • Handling duplicate requests and transaction edge cases

.gitignore Recommendations

Common files and folders to exclude:

venv/
__pycache__/
*.pyc
*.db
.env
.DS_Store
.pytest_cache/

Future Improvements

Possible next enhancements:

  • Authentication and authorization
  • Transaction history endpoint
  • Account balance lookup endpoint
  • Improved error handling and standardized responses
  • PostgreSQL integration for production readiness
  • Docker support
  • CI/CD pipeline integration

Author

Jeremy Cheeseborough

GitHub: https://github.com/jcheese54 LinkedIn: www.linkedin.com/in/jcheeseborough

About

Enterprise-style FastAPI financial transaction API with deposits, withdrawals, transfers, idempotency protection, and automated tests.

Topics

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors

Languages