Current repository is a backend part of comprehensive STT project, which is a working name for Seat Split consignment portal. Seat Split allows ticket season holders to sell their tickets to other fans. Currently, we support only sports events, but in the future we are planning to expand our business to other events like concerts, theaters, etc.
- Python
- Django
- Django Rest Framework
- PostgreSQL
- Redis
- Celery
- Docker
- Poetry
- Clone the repository from GitHub.
- Create
.env
in django-backend directory using.env.example
. - Install Docker and launch the daemon.
- Cd to project's root and run
docker compose up --build
.
- django-backend - contains all necessary files for Django backend.
- apps - contains all existing django applications and common (among them) files.
- config - contains standard Django settings files.
- templates - contains Django admin template settings as well as email templates.
- nginx - contains all necessary files for nginx configuration (in case we are the one who manage nginx).
- shell_scripts - contains all shell commands that can make our life much easier.
- create_requirements.sh - creates
dev-requirements.txt
andprod-requirements.txt
files. - docker_deploy.sh - builds docker container and pushes it to Heroku.
- run_tests.sh - runs all tests and creates html report.
- make_project_structure_tree.sh - creates project structure.
- heroku_backup.sh - contains all necessary commands to backup Heroku database.
- count_lines_of_code.sh - counts all lines of code in the project.
- create_requirements.sh - creates
- .dockerignore - list of files or directories that are excluded from getting into docker container.
- ruff.toml - just an extension of main
ruff
linter settings stored in pyproject.toml. - .gitignore - list of files or directories that are excluded from getting into git repository.
- .pre-commit-config.yaml - custom settings for ruff and isort linters hooks.
- docker-compose.yml - file-constructor, that allows to build docker containers. Used for local development only.
- Dockerfile - file-instruction of how to build docker image for services like Heroku and Railway.
- Dockerfile-dev - file-instruction of how to build docker image for local development. This is the file, that
docker-compose.yml
is using for building docker container to run it locally. - Dockerfile-prod - file-instruction of how to build docker image for production deployment in case we use VPS.
- pyproject.toml - custom project's settings. This file contains all necessary information about the project itself, dev and prod dependencies.
First of all, check out .env.example
file. It contains all necessary environment variables that are used in the project.
Here is the detailed explanation of some of them (the rest are self-explanatory):
ROLLBAR_ACCESS_TOKEN
- token for Rollbar service, which is used for error tracking.CELERY_AGGREGATED_SLACK_NOTIFICATION_COUNTDOWN
- countdown for Celery task, which aggregates all ticket created notifications and sends them to Slack.STT_NOTIFICATIONS_BOT_API_TOKEN
- token for Slack bot, which is used for sending notifications to Slack.STT_NOTIFICATIONS_CHANNEL_ID
andSTT_WEEKLY_ISSUES_REPORT_CHANNEL_ID
- ids of Slack channels, where notifications and weekly reports are sent. For test purposes we are using#test-channel
channel with idC06BH3YAPV4
.HEALTH_CHECK_TOKEN
- token for health check endpoint. Used for monitoring purposes. Basically you are the one who generates it and inputs as an environment variable. Then you use it while sending requests to health check endpoint.BUSINESS_TOTAL_EXPENSES
- percentage of total expenses that are used for business purposes. For example, if we list clint's ticket for $100 and our percentage is 20% (insert as 0.2), then client will get $80 and we will get $20.GENERATE_EMAILS_TOKEN
- token for/generate_random_data_with_provided_domain_or_state/
endpoint. Used for generating random emails with provided domain or state.GITHUB_ACCESS_TOKEN
- token for Weekly Issues Report. Used for getting all issues from Github and sending them to Slack.
We have a health check endpoint, which is used for monitoring purposes. It is located at api//health-check/
and requires HEALTH_CHECK_TOKEN
environment variable to be set. This is based on django-health-check
package, so all information about it can be found here. In order to call this endpoint, you need to provide Authorization
header with a value, which is equal to HEALTH_CHECK_TOKEN
environment variable:
"Authorization": "HEALTH_CHECK_TOKEN"
Example of the successful response:
Currently it checks the following services:
- Database (PostgreSQL)
- Cache (Redis)
- Celery
We are using PostgreSQL as our main database. The database structure is quite simple and can be found either by this link or you can create a new diagram at dbdiagram.io
by copying the code from this file. It contains all necessary information about tables, their fields and relations between them.
- Prepare correct Dockerfile
- Use this command to build the container:
docker build -t registry.heroku.com/<app_name>/web .
- Push the container to registry.heroku.com:
docker push registry.heroku.com/<app_name>/web
- Release the container to production:
heroku container:release -a <app_name> web
Also, you can simply run docker_deploy.sh
and script will complete these 3 commands for you.
Railway will automatically deploy the app in case main branch has been updated.
We are using simple Git workflow with main and develop branches. All new features should be developed in separate branches (feature/<relevant_feature_name>
) and then merged into develop branch after Pull Request is reviewed and approved.
The next step would be creating a Pull Request from develop to main branch and merge it.
- What does this PR do?
- Why are we doing this?
- How should this be manually tested?
- Any background context you want to provide?
- What are the relevant tickets?
- Screenshots (if appropriate).
- Questions.
A full instruction on how to get required data using SkyBox personal account and Postman can be found here.
- Heroku
python manage.py collectstatic
issue solution can be found here. - Django-tabulator-example is here.
- Responsive tables using Django and htmx. The main article is here. Github source code.
- Django-tables2 documentation.
- Django-filter documentation.
- Django-crispy-forms documentation.
- Django Model meta options.
- Detailed Django Form explanation.
- Django Widget Tweaks is here.
- Django permissions detailed article.
- If you ever you deleted Django migrations
- Git Cheat Sheet
- JWT decoding
- Using dictionary as filter value
- Super useful approaches of how to get user and group permissions is here
- Access project's bash:
heroku run bash -a <heroku app name>
- Check all releases:
heroku releases
- Check all info about particular release:
heroku releases:info <release version number>
- If ever we deployed buggy code or something goes wrong with current release:
git revert
and redeploy it again. - If we have some problems with heroku platform, then better to use:
heroku rollback <release version number (optional)>
- Heroku app logs:
heroku logs -n 1500
orheroku logs -t
to maintain them live - Safely delete all rows from database:
python manage.py truncate --apps <app_name> --models <model_name>
- Reset PK in postgresql DB (apply only after deleting all info from the table):
python manage.py sqlsequencereset <app_name> | python manage.py dbshell
- Safely delete an app:
python manage.py migrate <app_name> zero
After running this command we can delete an app from INSTALLED_APPS and delete a corresponding directory - Check project's files with flake8 and black before making commit:
pre-commit run --all-files