- Docker.
- Docker Compose.
- Poetry for Python package and environment management.
- Scripts Here are scripts which get exectuted inside the
docker-compose.override.yml
.- scripts come from template repository.
- Not touched for current development.
- Needed for the proper docker compose.
- Backend Actual backend code
backend.dockerfile
for the backend image- app folder for the actual code
- alembic: folder for alchemist framework for db management
env.py
:manages env for the DB- versions folder: revisiong of the DB versions
- app
- scripts
- alembic: folder for alchemist framework for db management
Docker compose is used to orchastrate 4 images. Traefik is used for service-to-service communication.
In dockercompose.yml
all four images are created
- backend (contained in ./backend)
- PostgreSQL (pull prebuild image)
- PGAdmin (pull prebuild image)
- Network proxy (pull prebuild image)
The .env
file contains the environment settings, which are passed in the dockercompose.yml
to the respective images. In the image itself the environment variables
can be accessed via
import os
os.environ.get("ENV_VAR")
- Build images and start the stack with Docker Compose:
docker-compose up -d
- Now you can open your browser and interact with these URLs:
Backend, JSON based web API based on OpenAPI: http://localhost/api/
Automatic interactive documentation with Swagger UI (from the OpenAPI backend): http://localhost/docs
Alternative automatic documentation with ReDoc (from the OpenAPI backend): http://localhost/redoc
PGAdmin, PostgreSQL web administration: http://localhost:5050
Note: The first time you start your stack, it might take a minute for it to be ready. While the backend waits for the database to be ready and configures everything. You can check the logs to monitor it.
To check the logs, run:
docker-compose logs
To check the logs of a specific service, add the name of the service, e.g.:
docker-compose logs backend
DB Schemas are maintained in app/app/models
. One files creates one table.
The folder structure is as follows:
app/app/models
: contains all table schemas which are relevant throught the whole appapp/app/models/<app-module>
: contains all table schemas which are relevant for the mentioned app-module
CRUD opterations are maintained in app/app/crud
.
base.py
: Parent class for all CRUD operations on specific tables. Contains the general logic which needs to be parameterized by the child classes for a given table- folder / file structure identical to
app/app/models
folder since it follows also the one files per table policy.
In the folder app/app/db
all tables need to be mentioned in order to be picked up and properly being updated.
base.py
:list all modelsinit_db.py
: update tables during deployment without creating a new revision
To execute the changes while the image is running, the following commands are needed:
cd <root>/service-main
docker-compose exec backend bash
alembic revision --autogenerate -m "<Comment for changes>"
API data models are maintained in app/app/schemas
. App-wide files are directly contained in this folder. Files, which are relevant for specific modules
are contained in a subfolder for that module. Follows the same file / folder structure as app/app/models
.
Functionality that is used in more than just one specific end-point is contained in the folder app/app/core
. In particular, this folder contains
- the recommendation logic
The API end-points are defined in the folder app/app/api
.
deps.py
: contains information about the current usersapi_v1/api.py
: contains the routers to the sub-areasapi_v1/endpoints
: folder containing the actual endpoints. Structure follows the folderapp/app/models
.
- The folder
app/app/email-templates
contains the functionality to reset the user token with email and password.