This guide covers setting up a local development environment for PKPDApp, including both the Django backend and React frontend.
- Python 3.x
- Node.js (install via
snapon Ubuntu 20.04 LTS:sudo snap install node --classic) - Yarn package manager:
npm install --global yarn - Docker and docker-compose (optional, for production deployments)
- System dependencies (Ubuntu):
sudo apt-get install build-essential libsasl2-dev python3-dev libldap2-dev libssl-dev libsundials-dev memcached- Clone the repo, make sure you have the prerequisites installed, and navigate to the project directory
- Run the
start-server-dev.shscript to set up and run the backend and frontend. This will show you the URLs for both servers and any errors that occur during setup.
For a more detailed manual setup, follow the instructions below.
Create a Python virtual environment in the venv folder:
python3 -m venv venv
source venv/bin/activateAlways use this virtual environment when working with the backend.
Edit the .env.prod file in the root of the repository to configure environment variables. The most important variables to alter are those corresponding to secret keys and passwords.
Ubuntu:
apt-get install build-essential libsasl2-dev python3-dev libldap2-dev libssl-dev libsundials-dev memcachedWith your virtual environment activated:
pip install -r requirements.txtcd pkpdapp
python manage.py migratepython manage.py runserverThe backend API will be available at http://127.0.0.1:8000.
python manage.py createsuperuserNavigate to the frontend directory and install Node.js dependencies:
cd frontend-v2
yarn installyarn startThe frontend will be available at http://127.0.0.1:3000.
Run Django tests:
cd pkpdapp
python manage.py testRun a specific test file:
python manage.py test pkpdapp.tests.test_modelsRun code style checks:
flake8Run copyright tests:
python run-tests.py --copyrightThe frontend uses Storybook and Vitest for component testing.
Open a development Storybook (including a GUI for running tests) in your browser:
cd frontend-v2
yarn storybookRun tests from the command line:
yarn testRun the linter:
yarn lintFrom the backend directory:
cd pkpdapp
python manage.py spectacular --color --file schema.ymlThe frontend uses Redux Toolkit RTK Query to automatically generate an API client from the OpenAPI spec.
From the frontend directory:
cd frontend-v2
npx @rtk-query/codegen-openapi openapi-config.jsonThis creates the frontend-v2/src/app/backendApi.ts file with the generated client.
Some reference data is defined once in the backend and consumed by both sides. The
body-weight population data lives in
pkpdapp/pkpdapp/utils/weight_populations.json (the single source of truth; the
backend reads it directly). After editing that JSON, regenerate the committed
frontend copy:
cd frontend-v2
yarn sync:weight-populationsThis regenerates frontend-v2/src/shared/weightPopulations.ts (a generated file —
do not edit it by hand).
Memcached is installed as part of the system dependencies. Run memcached:
memcached -p 11211- Create feature branches from the
developbranch - Use conventional commits for commit messages
- Create pull requests against the
developbranch (notmaster) - Use git worktrees for working on multiple features simultaneously
The Django app has a custom management command for snapshot testing all models in the database:
cd pkpdapp
git checkout master
python manage.py test_snapshots
git checkout develop
python manage.py test_snapshots
git clean -dfThe custom command is located in pkpdapp/pkpdapp/management/commands/test_snapshots.py.