A FastAPI-based expense splitting application inspired by Splitwise, with Docker support for easy development and deployment.
- User Management: Create and manage users
- Group Management: Create groups for expense sharing
- Expense Tracking: Add expenses and split them among group members
- RESTful API: Clean and documented API endpoints
- Database Support: PostgreSQL with SQLAlchemy ORM
- Docker Support: Complete containerized setup
- Comprehensive Testing: Unit, integration, and workflow tests
- Docker and Docker Compose installed on your system
- Python 3.13+ (for local development)
- Git (optional, for version control)
-
Clone the repository:
git clone <repository-url> cd splitter
-
Set up environment variables:
cp .env.example .env # Edit .env with your configuration -
Build and start the application:
docker compose up --build
-
Access the application:
- API: http://localhost:8000
- Interactive docs (Swagger): http://localhost:8000/docs
- Alternative docs (ReDoc): http://localhost:8000/redoc
-
Set up Python environment:
# Create virtual environment (outside project directory) python -m venv venv_splitter venv_splitter\Scripts\activate # On Windows # or source venv_splitter/bin/activate # On Unix # Install dependencies pip install -e .
-
Set up database:
# Start PostgreSQL (using Docker) docker run --name splitter_db -e POSTGRES_PASSWORD=your_password -e POSTGRES_DB=splitter_db -p 5432:5432 -d postgres:15-alpine # Or use local PostgreSQL instance
-
Configure environment:
cp .env.example .env # Edit .env with your database configuration -
Run the application:
python -m uvicorn src.app.main:app --reload --host 0.0.0.0 --port 8000
splitter/
├── src/ # Source code
│ └── app/
│ ├── core/ # Core configuration
│ │ ├── config.py # Application settings
│ │ └── database.py # Database setup
│ ├── models/ # SQLAlchemy models
│ │ ├── user.py
│ │ ├── group.py
│ │ ├── expense.py
│ │ └── ...
│ ├── schemas/ # Pydantic schemas
│ │ ├── user.py
│ │ ├── group.py
│ │ ├── expense.py
│ │ └── ...
│ ├── main.py # FastAPI application
│ └── __init__.py
├── tests/ # Test suite
│ ├── test_unit.py # Unit tests
│ ├── test_api.py # API tests
│ ├── test_integration.py # Integration tests
│ ├── test_workflows.py # Workflow tests
│ └── test_complete.py # Complete test runner
├── alembic/ # Database migrations
├── .env.example # Environment variables template
├── compose.yml # Docker Compose configuration
├── Dockerfile # Docker configuration
├── pyproject.toml # Python project configuration
└── README.md # This file
GET /- Root endpointGET /health- Health checkGET /config- Configuration infoGET /hello/{name}- Greeting endpoint
- Swagger UI: http://localhost:8000/docs
- ReDoc: http://localhost:8000/redoc
# Using the complete test runner
python tests/test_complete.py
# Or using pytest directly
pytest tests/ -v# Unit tests
python tests/test_unit.py
# API tests
pytest tests/test_api.py -v
# Integration tests
pytest tests/test_integration.py -v
# Workflow tests
pytest tests/test_workflows.py -vThe test suite includes:
- Unit Tests: Model validation, schema validation, configuration
- API Tests: Endpoint testing, request/response validation
- Integration Tests: Database operations, model relationships
- Workflow Tests: Complete user workflows, expense splitting
Copy .env.example to .env and configure:
# Database
POSTGRES_USER=postgres
POSTGRES_PASSWORD=your_secure_password
POSTGRES_DB=splitter_db
DATABASE_URL=postgresql://postgres:your_secure_password@db:5432/splitter_db
# Application
ENVIRONMENT=development
DEBUG=True
SECRET_KEY=your-secret-key-here
# CORS (if needed)
CORS_ORIGINS=http://localhost:3000,http://localhost:8000# Generate migration
alembic revision --autogenerate -m "Description"
# Apply migrations
alembic upgrade head
# Downgrade migrations
alembic downgrade -1# Install development dependencies
pip install -e ".[dev]"
# Code formatting
black src/ tests/
# Linting
flake8 src/ tests/
# Type checking
mypy src/# Start in development mode with hot reload
docker compose up --build
# Start in detached mode
docker compose up -d --build
# View logs
docker compose logs -f
# Stop services
docker compose down# Build and start production containers
docker compose -f compose.yml -f compose.prod.yml up --build -d
# Scale services
docker compose up --build --scale web=2# Access database
docker compose exec db psql -U postgres -d splitter_db
# Create database backup
docker compose exec db pg_dump -U postgres splitter_db > backup.sql
# Restore database
docker compose exec -T db psql -U postgres splitter_db < backup.sql# Create venv in parent directory (recommended)
cd .. # Go to parent directory of splitter
python -m venv venv_splitter
venv_splitter\Scripts\activate
cd splitter
pip install -e .# Create venv in parent directory (recommended)
cd .. # Go to parent directory of splitter
python3 -m venv venv_splitter
source venv_splitter/bin/activate
cd splitter
pip install -e .# Start development server
python -m uvicorn src.app.main:app --reload --host 0.0.0.0 --port 8000
# Run tests
python tests/test_complete.py
# Check application health
curl http://localhost:8000/health# Initialize database
python -c "from src.app.core.database import engine; from src.app.models import Base; Base.metadata.create_all(bind=engine)"
# Test database connection
python -c "from src.app.core.database import engine; engine.connect()"- Fork the repository
- Create a feature branch
- Make your changes
- Run tests:
python tests/test_complete.py - Submit a pull request
-
Database Connection Error
- Check
.envfile configuration - Ensure PostgreSQL is running
- Verify database URL format
- Check
-
Import Errors
- Ensure virtual environment is activated
- Install dependencies:
pip install -e . - Check Python path includes project root
-
Docker Issues
- Clear Docker cache:
docker system prune -a - Rebuild containers:
docker compose down && docker compose up --build - Check logs:
docker compose logs -f
- Clear Docker cache:
-
Test Failures
- Ensure test database is accessible
- Check environment variables
- Run tests individually to identify issues
- Check the logs:
docker compose logs -f - Run health check:
curl http://localhost:8000/health - Verify configuration:
curl http://localhost:8000/config
This project is licensed under the MIT License - see the LICENSE file for details.