A secure, multi-user API service using FastAPI and SQLModel that manages user ingredient inventories and shopping lists with authentication.
- Language: Python 3.10+
- Web Framework: FastAPI
- ORM/Data Modeling: SQLModel
- Database: PostgreSQL
- Authentication: fastapi-users
- Database Migrations: Alembic
- Containerization: Docker
src/
├── main.py # Application entry point
├── config.py # Global configuration
├── database.py # Database connection setup
├── migrations/ # Alembic migrations
├── auth/ # Authentication module
│ ├── models.py # User model
│ ├── schemas.py # Pydantic schemas
│ ├── dependencies.py # Auth dependencies
│ ├── router.py # Auth endpoints
│ └── service.py # Auth business logic
├── ingredients/ # Ingredients module
│ ├── models.py
│ ├── schemas.py
│ ├── dependencies.py
│ ├── router.py
│ └── service.py
├── shopping_lists/ # Shopping lists module
│ ├── models.py
│ ├── schemas.py
│ ├── dependencies.py
│ ├── router.py
│ └── service.py
└── utils/ # Shared utilities
├── exceptions.py # Custom exceptions
└── pagination.py # Pagination helpers
- Python 3.10+
- Docker and Docker Compose (optional)
- PostgreSQL (if not using Docker)
- Clone the repository
- Create a
.env
file based onexample.env
:
cp example.env .env
- Update the environment variables in
.env
with your values
docker-compose up -d
- Create a virtual environment and activate it
python -m venv venv
source venv/bin/activate # On Windows: venv\Scripts\activate
- Install dependencies
pip install -r requirements/dev.txt
- Run the application
uvicorn src.main:app --reload
Initialize migrations (first time):
alembic revision --autogenerate -m "Initial migration"
alembic upgrade head
Apply migrations:
alembic upgrade head
When the application is running, visit:
- Swagger UI:
http://localhost:8000/docs
- ReDoc:
http://localhost:8000/redoc
To set up pre-commit hooks:
pip install pre-commit
pre-commit install
To manually format code:
black src
isort src
flake8 src
pytest