- Generic Backend
The Generic Backend is the generic part of the Semper-KI platform where users can submit their 3D printing requirements and find suitable service providers. It can be used as a baseline for other django-based backends since it includes multiple parts that almost every backend needs at some point.
- Language: Python 3.11
- Backend: Django, Django REST Framework, Channels
- Auth & Security: Authlib
- Database: PostgreSQL
- Caching: Redis
- Task Queue: Celery (Redis as broker)
- Storage: MinIO, S3 compatible
- API Documentation: Swagger UI (DRF Spectacular)
- Testing & Debugging: pytest, Django Test Framework
- Deployment: Gunicorn, Uvicorn, Nginx
- Containerization: Docker
- Code Quality: Pylint
Make sure you have the following installed on your machine:
Docker: Latest version- (
Python: 3.11)
Make sure you have the following .env files
-
.env.local_container: For local development with Docker -
.env.staging: For a deployed staging environment on a server -
.env.production: For a deployed production environment on a server -
If you don't have any .env file:
- Ask someone who does on your team
- Create one yourself based on the .env template
exampleEnv.txt
Clone the repository:
git clone git@github.com:KMI-KPZ/Generic_Backend.git
cd Generic_BackendOptional:
- Install packages to your local machine
python -m pip install -r requirements.txt
To run the application, you can use our docker compose starting script in the root of the project.
The Script starts both the services and the backend inside Docker containers.
start_local_dev.bat -m local_container
- Make the script executable:
chmod +x start_local_dev.sh
- Run the script
./start_local_dev.sh -m local_container
Note:
The backend container supports hot reloading β changes to files are reflected automatically after saving.
In debug mode, the current request handler must complete before the worker restarts.
There may be a slight delay before the changes take effect, but the logs will indicate when the reload occurs.
Make sure you have the following installed on your machine:
Docker: Latest versionPython: 3.11
Make sure you have the following .env files
.env.dev: For local debugging via VS Code.env.local: For local development of the backend without docker (services always run inside docker)
Follow installation in Getting Started (clone project and install submodules)
- Install packages to your local machine
python -m pip install -r requirements.txt
- Run the services in Docker containers:
# Windows
start_local_dev.bat -m local
# Linux / macOS
chmod +x start_local_dev.sh
./start_local_dev.sh -m local- Create the database:
python manage.py create_db --env local
- Migrate the database to the latest state:
python manage.py migrate --env local
- Run the backend locally:
python manage.py runserver --env local
There are a couple of docker and docker-compose files in the root folder. Regarding the docker files:
Dockerfile: Used by local docker-compose files, uses caching for faster buildsDockerfile.Server: Used for compose files that run on a server (no caching for example)
As for the compose files:
docker-local-dev-container-backend.yml: For the backend container when running in local_container modedocker-local-dev-services.yml: Every other container like redis, postgres and so on for local usedocker-compose.test.yml: For running the tests, can be called via docker-compose up directly, usable by GitHub Actionsdocker-compose.staging.yml: Used on the server for stagingdocker-compose.production.yml: Same as above albeit for production
.: The main folder contains the manage.py file of django and docker files as well as the .env files.devcontainer: Contains the json needed for running the service containers together with the debug container.vscode: Everything necessary to run the debug-mode of VS CodeBenchy: A small tool to fire calls to certain pathscode_General: The main codeconfigs: Contains the auth0 configurationconnections: Connections to internal and external services like ID management (auth0 in our case), redis, ...postgresql: Specific code for the models using the postgres database
handlers: API Paths handling callslogics: Logics to these handlersmigrations: Migrations done by djangomodelFiles: Database modelssettings: Setting files specific to the GB modulestatic: Static files (only a testpicture currently)templates: HTML templatesutilities: Helper functions
docker: Docker scripts for redis and miniologs: Log filesmain: Main django apphelper: Helper functions like checking connections to other containersmanagement: Command line toolscommands:
settings: Settings for django
minio: Folder containing the locally saved filespostgres: Folder that holds the databaseredis: Folder that holds snapshots of redisrun: Run scripts
If backend is running:
- Project Documentation: Available at
http://127.0.0.1:8000/private/doc - Swagger UI (API reference): Available at
http://127.0.0.1:8000/public/api/schema/swagger-ui/
- dev: Where all branches derive from and will be pushed to
- main: publish/forkable branch, only pull requests from dev go here
Please refer to the Code style guide.
A .pylintrc configuration file is located in the main folder and can be used with the Pylint extension in VS Code.
This ensures consistent linting across the project.
- Pylint
- Pip Manager
- Docker
This project is licensed under the MIT License.
You are free to use, modify, and distribute this software, provided that you comply with the terms of the license.
For more details, see the LICENSE file in this repository.