This commit is contained in:
Piotr Domański 2026-04-08 12:02:35 +02:00
parent 9ee27d70e2
commit f2ab3e0498
3 changed files with 47 additions and 41 deletions

View file

@ -2,51 +2,31 @@
Simple API for food diary application. It uses FastAPI and async postgres. Simple API for food diary application. It uses FastAPI and async postgres.
## Usage ## Overview and key points of configurating and deploying API
Simply build docker images with: API is maily suited for being run as docker container, either via docker compose or inside kubernetes/openshift, tho no configuration for those are provided in this repository. Example `docker-compose.yml` for deployment is provided in `doc/install/docker-compose.yml`.
```bash Configuration is passed through env variables. Sample configuration is provided in `doc/install/env.template`.
docker-compose build
```
And then start them up with: Database migrations are handled through alembic. For ease of use, `doc/install/Makefile` provides formula for `make migrate` that upgrades database to head migration.
```bash ## Development
docker-compose up -d
```
Create `.env` file with configuration by copying template `env.template`. *You have to generate secret keys!* They are stored under `SECRET_KEY` and `REFRESH_SECRET_KEY` Project architecture design was summarized in `ARCHITECTURE.md`, altho summary was generated with usage of AI for now so might not be perfect or informative ;)
in `.env` file and both could be generated with `openssl rand -hex 32`.
To initialize database exec: Overall, project consists of:
```bash - `fooder/alembic` - alembic python scripts, migrations, autogenerated
docker-compose exec api bash -c python -m fooder --create-tables - `fooder/context` - context with authorized session, repositories
``` - `fooder/domain` - sqlalchemy domain definitions
- `fooder/controller` - controllers for domain models, controllers hold logic linked with only one model
## Deployment - `fooder/repository` - repositories for domain models, again single repo per model, altho because of joins there are some methods that touch more than one model
- `fooder/model`- pydantic models
For deployment delete: - `fooder/view` - fastapi routes
- `fooder/utils` - utils
``` - `fooder/app` - fastapi app definitions
volumes: - `fooder/db` - sqlalchemy database core functionality
- ./fooder:/opt/fooder/fooder - `fooder/recaptcha` - recaptcha implementation
``` - `fooder/exc` - exceptions live there
- `fooder/router` - fastapi main router
and - `fooder/settings` - pydantic-settings for app
```
command: "uvicorn fooder.app:app --host 0.0.0.0 --port 8000 --reload"
```
lines from `docker-compose.yml`. This line makes app reload everytime code changes and is only recommended for development purposes.
I highly recommend using reverse proxy like nginx for HTTPS.
## Documentation
When api is started using docker, by default it runs on 8000 port on local machine (it can be changed within `docker-compose.yml` file). Swagger documentation is available
on `http://0.0.0.0:8000/docs` when you start the app.
Alternatively you can visit [my own instance of the API docs](https://fooderapi.domandoman.xyz/docs).

View file

@ -0,0 +1,26 @@
networks:
fooder:
driver: bridge
services:
database:
restart: unless-stopped
image: postgres
networks:
- fooder
env_file:
- .env
api:
restart: unless-stopped
image: registry.domandoman.xyz/fooder/api
build:
dockerfile: Dockerfile
context: .
platform: linux/amd64
networks:
- fooder
env_file:
- .env
ports:
- "8000:8000"