A RESTful API for personal finance management, built with FastAPI and SQLAlchemy. This API allows you to track accounts, transactions, budget categories, and savings goals.
- Account management (create, read, update, delete)
- Transaction tracking with filtering
- Budget category management
- Savings bucket/goal tracking
- Built with FastAPI and SQLAlchemy
- Comprehensive test coverage
- Containerized with Docker
- Python 3.8+
- PostgreSQL (for production)
- Docker (optional, for containerization)
- pip (Python package manager)
git clone <repository-url>
cd finance-apiCreate a .env file in the root directory with the following variables:
# Database Configuration
DATABASE_URL=postgresql://user:password@localhost:5432/finance_db
# For testing
TESTING=falseFor local development, you can also create a .env.local file which will override the .env file.
python -m venv venv
source venv/bin/activate # On Windows use: venv\Scripts\activatepip install -r requirements.txt
pip install -r requirements-test.txt # For development and testingFor development, you can use SQLite by setting the following in your .env.local:
DATABASE_URL=sqlite:///./finance.db- Install PostgreSQL if you haven't already
- Create a new database:
createdb finance_db
- Update the
DATABASE_URLin your.envfile with your PostgreSQL credentials
uvicorn src.main:app --reloadThe API will be available at http://127.0.0.1:8000
uvicorn src.main:app --host 0.0.0.0 --port 8000-
Build the Docker image:
docker build -t finance-api . -
Run the container:
docker run -d --name finance-api -p 8000:8000 --env-file .env finance-api
Once the application is running, you can access the following:
- Interactive API Docs (Swagger UI):
http://127.0.0.1:8000/docs - Alternative API Docs (ReDoc):
http://127.0.0.1:8000/redoc - OpenAPI Schema:
http://127.0.0.1:8000/openapi.json
pytest -vpytest --cov=src --cov-report=htmlThe coverage report will be available in the htmlcov directory.
pytest tests/test_models.py -vpytest tests/test_models.py::test_create_account -vfinance-api/
├── src/ # Source code
│ ├── __init__.py
│ ├── main.py # FastAPI application
│ ├── models.py # SQLAlchemy models
│ ├── schemas.py # Pydantic models
│ ├── crud.py # Database operations
│ ├── database.py # Database configuration
│ └── routers/ # API route handlers
│ ├── __init__.py
│ ├── accounts.py
│ ├── budgets.py
│ ├── savings_buckets.py
│ └── transactions.py
├── tests/ # Test files
│ ├── __init__.py
│ ├── conftest.py
│ ├── test_api.py
│ ├── test_crud.py
│ ├── test_database.py
│ └── test_models.py
├── .env.example # Example environment variables
├── .gitignore
├── Dockerfile
├── requirements.txt # Production dependencies
├── requirements-test.txt # Development dependencies
└── README.md
- Fork the repository
- Create a feature branch (
git checkout -b feature/AmazingFeature) - Commit your changes (
git commit -m 'Add some AmazingFeature') - Push to the branch (
git push origin feature/AmazingFeature) - Open a Pull Request
This project is licensed under the MIT License - see the LICENSE file for details.