This is a Django REST Framework project with setup instructions for creating a virtual environment and running the project on Windows and Linux.
PYTHON REST API requires Python and Redis.
-
If you use Python 3 or newer, you may need to configure the default interpreter.
sudo update-alternatives --install /usr/bin/python python /usr/bin/python3 1
-
Install the required system packages before continuing.
sudo apt install libpq-dev
-
Activate the virtual environment.
source venv/bin/activate -
Manage project dependencies. Use pip-compile for development-only dependency updates.
pip-compile requirements/base.in pip-compile requirements/dev.in pip-compile requirements/prod.in
Install dependencies for development or staging:
pip install -r requirements/dev.txt
Install dependencies for production:
pip install -r requirements/prod.txt
-
Start the development database with Docker:
docker-compose --file docker-compose.dev.yml up -d
This starts PostgreSQL, Redis, and pgAdmin (web UI at http://localhost:5050).
-
Copy .env.example to a new .env file:
cp .env.example .env
-
Edit the environment variables and configure the required values.
VARIABLE DESCRIPTION DEBUG In production this should be False. APP_ENV Can be dev, test, or prod. Staging servers should use test. DB_NAME Database name. DB_USERDATABASE Database user. DB_PASSWORD Database password. DB_PORT Database port. DB_HOST Database host. SECRET_KEY Generate it with python legata/utils/secret_key.py and copy the value. DOCUMENTATION_USER_MAIL User email used to view the documentation. DOCUMENTATION_PASSWORD_MAIL Password used to view the documentation. DOCUMENTATION_USER_USERNAME Username used to view the documentation. APP_BACKEND_URL Backend URL with a trailing slash. APP_FRONTEND_URL Frontend URL with a trailing slash. APP_URL_FRONT_ADMIN Admin frontend URL with a trailing slash. BREVO_API_KEY Brevo API key. BREVO_URL_API Brevo API URL. BREVO_SENDER_EMAIL Sender email for Brevo messages. BREVO_SENDER_NAME Sender name for Brevo messages. AWS_ACCESS_KEY_ID AWS access key ID. AWS_SECRET_ACCESS_KEY AWS secret access key. AWS_S3_REGION_NAME Region where the bucket was created. AWS_S3_BUCKET_NAME Bucket name. AWS_S3_PRESIGNED_URL_EXPIRATION Validity time in seconds for pre-signed URLs. AWS_S3_MAX_FILE_SIZE Maximum file size in bytes. AWS_SQS_REGION_NAME Region where the queue was created. AWS_SQS_QUEUE_NAME Queue name. AWS_SQS_EVENTS_QUEUE_URL Full SQS queue URL for domain events. Required for async event systems. DISCORD_WEBHOOK_URL Create the Discord webhook for notifications. ACCESS_TOKEN_LIFETIME Access token lifetime in minutes. REFRESH_TOKEN_LIFETIME Refresh token lifetime in minutes (1 day). ALLOWED_HOSTS Hostnames or IPs separated by commas. CORS_ALLOWED_ORIGINS Allowed origins separated by commas. THROTTLE_RATES_ANON Anonymous user throttle rate (format: "120/minute"). THROTTLE_RATES_PER_VIEW Per-endpoint throttle rate (format: "120/minute"). THROTTLE_RATES_FORGOT_PASSWORD Password recovery throttle (format: "3/5m"). INITIAL_PASSWORD Initial password for new superusers. Minimum 8 characters, with upper/lowercase, number, and special character. MAX_RECORDS_TO_PROCESS Maximum number of records to process in a batch. MAX_MINUTES_TO_FORGOT_PASSWORD_TOKEN Maximum token lifetime in minutes. EVENTS_EXECUTION_MODE Domain event execution mode: "inline" (sync) or "async" (queued). QUEUE_SERVICE_BACKEND Queue backend when EVENTS_EXECUTION_MODE=async: "sqs" (AWS SQS, production) or "database" (development/staging). ADMIN_ALLOWED_IPS Allowed admin IPs separated by commas. SESSION_COOKIE_AGE Session lifetime in seconds for Django admin. NUM_PROXIES Proxy count: 0 for direct, 1 for Nginx, 2 for ALB/Nginx, 3 for Cloudflare/ALB/Nginx. REVENIU_API_KEY Reveniu API key used as the Reveniu-Secret-Keyheader in requests and for webhook validation.REVENIU_BASE_URL Reveniu API base URL. -
Run the following command during continuous deployment:
python manage.py migrate
-
Run the following command during continuous deployment:
python scripts/main-transfer.py
-
Run the development server:
python manage.py runserver
Before deploying to production or staging, run collectstatic to gather all static assets (CSS, JavaScript, images) used by Django Admin, DRF, and other apps:
python manage.py collectstatic --noinput
What does this command do?
- Collects static files from Django apps (admin, DRF, drf-spectacular, etc.)
- Copies them to the
STATIC_ROOTdirectory (/staticfiles) - Includes around 432 files needed by Django Admin
Web Server Configuration (Nginx/Apache)
In production and staging, Django does not serve static files for performance and security reasons. Configure your web server (Nginx, Apache, etc.) to serve the staticfiles/ directory directly.
If you configured EVENTS_EXECUTION_MODE=async, run a worker to process the event queue according to the selected backend:
If you use QUEUE_SERVICE_BACKEND=sqs (recommended for production):
python manage.py process_sqs_queue
If you use QUEUE_SERVICE_BACKEND=database (recommended for development/staging):
python manage.py process_scheduled_notifications
This project includes automated tools to maintain code quality:
make install-dev
make pre-commit-install
List all commands:
make helpLinting:
make lint make lint-fix
Formatting:
make format
Type checking:
make type-check
Full quality check:
make quality
Testing:
make test
make test-quickDocker:
make docker-up make docker-down
- Ruff - Fast linter
- Black - Automatic formatter
- isort - Import organizer
- mypy - Static type checker
- pytest - Testing framework
- pre-commit - Automated Git hooks
make docker-up make quality make test git add . git commit -m "feat: new feature" git push