This project aims to demonstrate the implementation of the following architectural patterns in Python.
- Model-View-Controller (MVC)
- Frontend/Backend segregation
- 15Factor
- Test-Driven Development
The project is based on two main services:
- frontendservice: Frontend mixing ASGI (FastAPI) and WSGI (Flask/Dash) applications.
- backendservice: Restful API connected to a database running in a PostgreSQL compatible CockroachDB cluster.
Architecture | Instrumentation |
---|---|
Docker Desktop est également requis.
Install Micromamba
Copy the .env.example file and name it .env
.
Update the variables inside the .env
file, the run the following command line to create the Python environment dedicated to the project.
source .env
micromamba create --name ${PROJECT_NAME} --channel conda-forge python=3.10 --yes
Activate the environment.
source .env
micromamba activate ${PROJECT_NAME}
|-- deploy
| |-- envoy # Envoy Proxy manifests
|-- docs # Documentation
|-- hack # local execution scripts
|-- specs # Open API definitions
|-- src
| |-- backend # "backendservice" source code
| |-- frontend # "frontendservice" source code
|-- tests
| |-- unit # Unit tests
| |-- integration # Integration tests
|-- .env # Local variables required for local development
|-- docker-compose.yml # Local execution environment
|-- pytest.ini # PyTest configuration
|-- VERSION # Application version
The hack contains scripts to managed the application lifecyle from the developer workstation.
- hack/init.sh Initialze the development environment (i.e. Environment variable, Python environment, etc.)
- hack/run.sh Build and locally executes the containerized using Docker Compose
Two type of tests can be executed:
- src/backend/src/tests/unit: Unitest written using Pytest to validated the models and controllers
- tests/integration: Test written using Thundclient (Postman equivalent for VsCode)
Run the following command to start the Docker Compose environment.
hack/run.sh
From a second terminal session, run the following command to start and interactive session in the backend
container.
docker compose exec -it --user 'root' backend /bin/bash
Run the following commands to run the unit tests.
# Modèles uniquement
pytest tests/unit/test_models.py
# Routes/Contrôlleurs uniquement
pytest tests/unit/test_route.py
# Tous les tests unitaires
pytest
Don't forget to initialize the environment variables (i.e. source .env
)
Unit tests are using a SqlAlchemy fixed that load/unload the data in the database
Run the following command to populate
hack/run.sh
docker compose exec -it --user 'root' backend /bin/bash
python3 tests/populate.py
Explore the various Web UIs.
- CockroachDB: http://localhost:8080
- Jaeger ui: http://localhost:16686
- Envoy admin: http://localhost:8081
- FastAPI swagger: http://localhost:8001/v1/docs
- Webui: http://localhost:8000