This is the backend API for the Spends Tracker application, built with FastAPI and SQLAlchemy.
- RESTful API endpoints for managing purchases, warranties, retailers, and brands
- Analytics endpoints for spending insights
- Data import/export functionality
- SQLite database for local development (migratable to PostgreSQL)
- Language: Python 3.10+
- Framework: FastAPI
- Database: SQLite (development) → PostgreSQL (production)
- ORM: SQLAlchemy 2.0+
- Validation: Pydantic v2
- Migrations: Alembic
-
Clone the repository
git clone <repository-url> cd spends/backend
-
Create a virtual environment
python -m venv venv source venv/bin/activate # On Windows: venv\Scripts\activate
-
Install dependencies
pip install -r requirements.txt
-
Set up environment variables
cp .env.example .env # Edit .env file as needed -
Run database migrations
alembic upgrade head
-
Start the development server
python run_server.py
Or with uvicorn directly:
uvicorn app.main:app --reload
-
Access the API
- API root: http://localhost:8000
- Documentation: http://localhost:8000/docs
pytestWhen you're ready to switch to PostgreSQL:
-
Start PostgreSQL with Docker:
docker-compose up -d
-
Update your
.envfile to use PostgreSQL:DATABASE_URL=postgresql+asyncpg://spends_user:spends_password@localhost/spends_tracker
-
Run migrations again:
alembic upgrade head
The application is designed for easy deployment to cloud platforms. Here are guides for popular platforms:
- Create a new Web Service on Render
- Connect to your GitHub repository
- Set the build command to:
cd backend && pip install -r requirements.txt
- Set the start command to:
uvicorn app.main:app --host 0.0.0.0 --port $PORT - Add environment variables as needed (DATABASE_URL, etc.)
- Create a new project on Railway
- Connect to your GitHub repository
- Add a new service and select your repository
- Set the deploy command to:
cd backend && pip install -r requirements.txt && alembic upgrade head
- Set the start command to:
uvicorn app.main:app --host 0.0.0.0 --port $PORT
The application can be deployed to any cloud platform that supports Docker containers. Use the provided Dockerfile and docker-compose.yml as a starting point.
Auto-generated API documentation is available at /docs endpoint when the server is running.