2024-05-23 12:00:13 +00:00
|
|
|
Meal planner backend
|
|
|
|
|
|
2025-10-19 13:12:16 +00:00
|
|
|
## Quickstart
|
|
|
|
|
|
|
|
|
|
First time setup:
|
|
|
|
|
```bash
|
|
|
|
|
make install
|
|
|
|
|
```
|
|
|
|
|
|
|
|
|
|
Run the development server:
|
|
|
|
|
```bash
|
|
|
|
|
make dev
|
|
|
|
|
```
|
|
|
|
|
|
|
|
|
|
Run tests:
|
|
|
|
|
```bash
|
|
|
|
|
make test
|
|
|
|
|
```
|
|
|
|
|
|
|
|
|
|
Run all quality checks (lint, typecheck, test, format check, OpenAPI export):
|
|
|
|
|
```bash
|
|
|
|
|
make all-checks
|
|
|
|
|
```
|
|
|
|
|
|
2025-10-18 03:26:42 +00:00
|
|
|
## Structure
|
|
|
|
|
|
|
|
|
|
- `main.py`: FastAPI app with all HTTP endpoints.
|
2025-10-19 09:24:23 +00:00
|
|
|
- `db.py`: aiosqlite connection + schema bootstrap across subpackages (calls each feature's `repository.create`).
|
2025-10-18 03:26:42 +00:00
|
|
|
- Domain packages with models and persistence:
|
2025-10-19 09:24:23 +00:00
|
|
|
- `products/` (models.py, repository.py, scrapers for Woolworths/Coles)
|
|
|
|
|
- `ingredients/` (models.py, repository.py)
|
|
|
|
|
- `recipes/` (models.py, repository.py, scraping.py)
|
|
|
|
|
- `meals/` (models.py, repository.py, service.py)
|
|
|
|
|
- `persons/` (models.py, repository.py)
|
|
|
|
|
- `shopping/` (models.py, repository.py)
|
2025-10-18 03:26:42 +00:00
|
|
|
- `tests/`: unit and API tests with sample HTTP fixtures.
|
|
|
|
|
|
|
|
|
|
## Getting started
|
|
|
|
|
|
2025-10-19 13:12:16 +00:00
|
|
|
### Manual setup (alternative to make install)
|
|
|
|
|
|
|
|
|
|
Create and activate virtual environment:
|
|
|
|
|
```bash
|
|
|
|
|
python3 -m venv .venv
|
|
|
|
|
source .venv/bin/activate # On Windows: .venv\Scripts\activate
|
2024-05-23 12:00:13 +00:00
|
|
|
```
|
2025-10-19 13:12:16 +00:00
|
|
|
|
|
|
|
|
Install packages:
|
|
|
|
|
```bash
|
2024-05-23 12:00:13 +00:00
|
|
|
pip install -r ./requirements.txt
|
2025-10-19 13:12:16 +00:00
|
|
|
pip install -r ./dev-requirements.txt
|
2024-05-23 12:00:13 +00:00
|
|
|
```
|
|
|
|
|
|
2025-10-19 13:12:16 +00:00
|
|
|
Install pre-commit hooks:
|
|
|
|
|
```bash
|
|
|
|
|
pip install pre-commit
|
|
|
|
|
pre-commit install
|
2025-10-18 03:26:42 +00:00
|
|
|
```
|
|
|
|
|
|
2025-10-19 13:12:16 +00:00
|
|
|
### Running the application
|
|
|
|
|
|
|
|
|
|
Run API (dev):
|
|
|
|
|
```bash
|
|
|
|
|
make dev
|
|
|
|
|
# or: uvicorn main:app --reload
|
2025-10-18 03:26:42 +00:00
|
|
|
```
|
2025-10-19 13:12:16 +00:00
|
|
|
|
|
|
|
|
Run tests:
|
|
|
|
|
```bash
|
|
|
|
|
make test
|
|
|
|
|
# or: pytest -q
|
2025-10-18 03:26:42 +00:00
|
|
|
```
|
|
|
|
|
|
2025-10-19 13:12:16 +00:00
|
|
|
### Available Make targets
|
|
|
|
|
|
|
|
|
|
- `make install` - Create venv and install all dependencies
|
|
|
|
|
- `make dev` - Run development server
|
|
|
|
|
- `make test` - Run tests
|
|
|
|
|
- `make format` - Format code with ruff
|
|
|
|
|
- `make lint` - Lint code with ruff
|
|
|
|
|
- `make typecheck` - Type check with mypy
|
|
|
|
|
- `make openapi` - Export OpenAPI schema
|
|
|
|
|
- `make all-checks` - Run all quality checks
|
|
|
|
|
- `make clean` - Remove venv and caches
|
|
|
|
|
|
2025-10-18 03:26:42 +00:00
|
|
|
## Tooling
|
|
|
|
|
|
|
|
|
|
This repo includes baseline configs in `pyproject.toml`:
|
2025-10-19 13:12:16 +00:00
|
|
|
- ruff (format and lint)
|
2025-10-18 03:26:42 +00:00
|
|
|
- mypy (type check)
|
|
|
|
|
|
2025-10-19 13:12:16 +00:00
|
|
|
Pre-commit hooks are configured to run:
|
|
|
|
|
- ruff (lint + format)
|
|
|
|
|
- mypy
|
|
|
|
|
- trailing whitespace fixer
|
|
|
|
|
- end-of-file fixer
|
|
|
|
|
|
|
|
|
|
Quality checks (run locally):
|
|
|
|
|
```bash
|
|
|
|
|
make format # Format code
|
|
|
|
|
make lint # Lint code
|
|
|
|
|
make typecheck # Type check
|
|
|
|
|
make all-checks # Run all checks
|
2024-05-23 12:00:13 +00:00
|
|
|
```
|
2025-10-18 05:44:36 +00:00
|
|
|
|
|
|
|
|
## Environment variables
|
|
|
|
|
|
2025-10-19 13:12:16 +00:00
|
|
|
Copy `.env.example` to `.env` and customize as needed:
|
|
|
|
|
|
2025-10-18 05:44:36 +00:00
|
|
|
- DOOF_DB: Path to sqlite database (default: `./data/doof.sqlite`)
|
2025-10-19 13:12:16 +00:00
|
|
|
- DOOF_PROD: Set to `true` in production (default: `false`)
|
|
|
|
|
- FRONTEND_DEV_URL: Frontend dev server URL for reverse proxy (default: `http://localhost:8080/`)
|
2025-10-18 05:44:36 +00:00
|
|
|
- DOOF_PORT: Port the server listens on when containerized; align Dockerfile `EXPOSE` accordingly.
|
|
|
|
|
|
|
|
|
|
## OpenAPI schema
|
|
|
|
|
|
|
|
|
|
- Generate the schema artifact used by the frontend and CI checks:
|
|
|
|
|
```
|
|
|
|
|
python scripts/export_openapi.py
|
|
|
|
|
```
|
|
|
|
|
|
|
|
|
|
This writes `openapi.json` to the repo root. Versioned endpoints live under `/api/v1`, legacy under `/api` (deprecated with `Deprecation` header).
|
|
|
|
|
|
|
|
|
|
## Schema lint/diff (manual)
|
|
|
|
|
|
|
|
|
|
Optionally, lint and compare schemas locally using Node tools:
|
|
|
|
|
```
|
|
|
|
|
npx -y @stoplight/spectral-cli lint openapi.json
|
|
|
|
|
npx -y openapi-diff --fail-on-changed --fail-on-incompatible path/to/baseline.json openapi.json
|
|
|
|
|
```
|
|
|
|
|
|
|
|
|
|
Keep a `baseline.json` on release branches to detect breaking changes.
|