A simple backend RESTful service to process orders and notify customers.
This repo demonstrates a simple REST-centered backend service exposing
endpoints to clients to create customer and order resources. It integrates
with common third-party providers to serve notifications to customers and
manage user authentication. All comments, feedback, and contributions are
highly encouraged. I always eager to learn and hear from the communityβ€
Learn more about the Django framework from the official documentation.
π§ Simple layout overview that highlights essential areas of the project for quick reference.
.
βββ .github # Hosts workflows and actions (CI/CD)
βββ db # Hosts db related config files.
βΒ Β βββ config
βΒ Β βΒ Β βββ connection-params.yaml
βΒ Β βββ secrets
βΒ Β βββ storage.yaml
βββ requirements # Hosts all project dependencies.
βββ src # Hosts project source code (implicit namespace package).
βΒ Β βββ config # The Django project (package).
βΒ Β βΒ Β βββ settings # Django project environment settings (package).
βΒ Β βββ Dockerfile
βΒ Β βββ manage.py
βββ test_utils # Importable test utilities (package).
βββ tests # Host all project tests (implicit namespace package).
βββ Makefile # Base project automation recipes.
βββ README.md
βββ compose.yaml # Base local compose app model.
βββ pyproject.toml # Hosts project tooling configs.
βββ tox.ini # Automated test orchestration and interface.This is an overview of the minimal setup needed to get started.
- Git
- Docker Desktop (latest version)
- IDE/Code/Text editor (PyCharm, VScode, Vim, etc)
Follow these tutorials to set up Docker and Compose on either Mac
or Linux.
I'd recommend Microsoft's documentation to set up Docker on WSL2 if you're on Windows.
The following setup was run on Ubuntu focal (20.04.6 LTS)
You can clone this repo with the following command.
- Clone repository
# cd your/desired/target/dir
git clone git@github.com:apexDev37/Agizo.git my-project
cd my-projectπ This will clone the repository to a target dir on your host machine with a custom name
my-project/and navigate into its root dir.
The following commands assume execution occurs at the project root.
Before running your application with Compose, configure environment variables
and secrets expected by the Compose app model. Sample env and secret
files are provided to configure the following services: web and db. You can
create the required config files with the following make target commands.
After the config files are created, replace the placeholders and empty txt
files with your custom values.
π
secretfiles should store sensitive or confidential data, whereasenvfiles can contain other environment-related config.
- Create required config files
make envs && make secrets # idempotent operations.π This will create and output all config files generated from available sample files in their target directory (ie.
django.env.example->django.env).
- Update placeholder config values
π‘
secretfiles intended to store keys or passwords are auto-populated with a random, cryptographic, base64-encoded value.
You're all set to run your Django application. Spin up your Django and Postgres instances with the following command.
- Spin up containers
docker compose down
docker compose up -dπ This will create and start the Django and Postgres instances in the same network defined in the base
composefile.
Once the containers have been created and started, you can access the
application at http://localhost:8000/
This is an overview to prepare working with this repo locally.
You can use any tool of your choice to create a PEP 405 compliant virtual
environment. The following example uses virtualenvwrapper to create and
manage virtual environments.
- Create a virtual environment
mkvirtualenv -p python3.12 agizo-py312π This will create a fully managed venv and activate the virtual environment by default.
If your environment is not activated from the above command or you encounter any issue, manually activate it with the following command.
- Activate the virtual environment
workon agizo-py312β All following commands assume execution occurs with an active virtual env at the project root.
- Install requirements for development.
make requirementsπ This will install and sync the active environment with the pinned versions for your development dependencies,
requirements/dev.txt.
- Set up
pre-commithooks
pre-commit install --install-hooksπ This one time setup installs the
pre-commitscript in your hiddengit/hooksdirectory and installs all hook environments defined in the config file.
Run the process for the Django development server in the web service. You can
use the following make target command to run the develop compose override
model, which supports hot-reload by watching and syncing your local files
into the container.
- Run Compose services in watch (develop) mode.
make -f compose.Makefile watch.devYou can also choose to spin up a more light-weight web service to handle only
test-related concerns.
- Run Compose services in watch (testing) mode.
make -f compose.Makefile watch.testThis is an overview to running and writing tests for this repo locally.
This project uses the test framework pytest, which is a powerful tool for
writing and running tests. By design, this project highly encourages and only
supports running tests in container environments. This promotes test runs in an
environment that closely mirrors a production environment - the published
image. Spin up a test or develop compose target with the following to get
started.
- Spin up
testingcompose app model
make -f compose.Makefile watch.testπ This will run all core compose services in
testingmode to provide all test dependencies and support both running and syncing tests written locally into yourwebsvc.
- Discover and run all project tests with
pytest
# Run tests in web service container.
docker compose exec --user appuser -it web pytest tests/π This runs all project tests defined in
tests/in interactive mode to output the test results in your terminal.
This project adopts a Test-Driven Development (TDD) design approach to write
project specifications. All tests should be written and defined in the tests/
directory. Each test script should live in a directory that maps to a
corresponding Django app. Each test script should follow this naming convention
to prevent module resolution conflicts: test_<app>_<module_under_test>.
- Example
.
βββ tests
βΒ Β βββ accounts # Maps to accounts app (package).
βΒ Β βΒ Β βββ test_account_serializers.py
βΒ Β βΒ Β βββ test_account_views.py
βΒ Β βββ config # Maps to Django project (package).
βΒ Β βΒ Β βββ test_utils.py
βΒ Β βββ orders # Maps to orders app (package).
βΒ Β βββ test_order_models.py
βΒ Β βββ test_order_services.py
βΒ Β βββ test_order_views.pyβπ Given that pytest recommends not making tests importable (packages), but standalone scripts, the chosen naming convention prevents name resolution conflicts during test discovery that may have been averted by using a
__init__.pyfile.
This repo supports coverage checks which should ideally be run frequently,
especially prior to pushing your changes to a remote branch. Find or
optionally modify this repo's coverage config defined in pyproject.toml. You
can run project-wide coverage metrics in the web svc with the following
command.
- Measure and report coverage metrics
# Run coverage in web service container.
docker compose exec --user root -it web \
pytest --cov --cov-config=pyproject.toml tests/π The
--userflag is currently required to givenSQLiteread/write permissions in the container's working dir to define the data file.coverageused bycoverageto store metrics and derive report data.
You can access a live version of the application using the URL provided in
the repository About section. The project is deployed to the PaaS (Platform
as a Service), Render, using their IaC (Infrastructure as code) model called
blueprints. Blueprints enables for resources to be defined in a single config
file, render.yaml, to support reproducible and versioned deployment and
infrastructure specs.
To make a repositoryΒ open source, you must license it so that others may freely use, modify, and distribute the software. Using the MIT license, this project ensures this. The full original text version of the license may be seen here.