Connect is a Django + PostGIS web application: organizations create paid opportunities, community health workers learn and deliver services through CommCare apps, and Connect tracks their visits, verifies them and records payments. It integrates with CommCare HQ and ConnectID.
The developer docs site publishes this README together with the app and deployment docs.
This assumes you will use the docker compose file in this repo to run services. If that is not the case you may need to edit some settings.
Install uv to manage Python versions and dependencies:
curl -LsSf https://astral.sh/uv/install.sh | shCreate a virtual environment in .venv and install the requirements:
uv syncActivate it (or prefix commands with uv run):
source .venv/bin/activateInstall the git hooks and run them once:
prek installprek run -aCreate your env file and edit the settings as needed (or export settings directly):
cp .env_template .envConnect uses GeoDjango and PostGIS. To learn more about the required dependencies, see the Django documentation.
For macOS (Intel / Apple Silicon) – using Homebrew:
brew install gdal geos projDjango may struggle to find the GDAL and GEOS libraries even after they are installed. Get your local library paths:
ls $(brew --prefix gdal)/lib/libgdal.dylibls $(brew --prefix geos)/lib/libgeos_c.dylibThen set them in your .env file:
GDAL_LIBRARY_PATH=...
GEOS_LIBRARY_PATH=...
Install WeasyPrint:
brew install weasyprintFor Ubuntu / Debian Linux:
sudo apt-get install -y binutils libproj-dev gdal-binEnabling the PostGIS extension
No migration creates the postgis extension. The inv up setup works because the postgis/postgis image
enables it for you when it initialises the database.
If you are using your own PostgreSQL instead, create the extension in the target database before migrating, or the first spatial migration will fail:
psql -d commcare_connect -c "CREATE EXTENSION IF NOT EXISTS postgis;"Start the docker services (PostgreSQL/PostGIS and Redis):
inv upInstall the JS dependencies and build them (add -w to rebuild on changes):
npm ciinv build-jsMigrate the database and start Django:
./manage.py migrate./manage.py runserverTo work on several branches at once, give each one its own git worktree. The repository has
hooks for worktrunk (wt) in .config/wt.toml.
Set up the main checkout first (above): worktrees copy its .env, and the docker compose
services must be running.
By default, a worktree gets its own empty database and its own Redis database:
wt switch --create my-branchwt new my-branch does the same; it is a shorter alias defined in .config/wt.toml.
The database has no data in it; create a user with ./manage.py createsuperuser.
To use the main checkout's database and Redis database instead, for example to work with data
you already have, pass --share=1:
wt new my-branch --share=1Setup doesn't run migrate on a shared database. If the branch adds migrations, running them
changes the main checkout's schema too, so give that branch its own database instead.
To start Claude Code in the new worktree as soon as it is set up, add --execute claude:
wt switch --create --execute claude my-branchwt remove my-branchThis drops the databases created for the branch. A worktree created with --share=1 has none,
so the main checkout's database is left alone.
When a worktree is created, scripts/setup-worktree.sh:
- copies
.envfrom the main checkout, and runsuv syncandnpm ci - creates an empty PostgreSQL database for the branch,
connect_wt_<branch>_<hash>, and runsmigrate - picks a Redis database (1-14) that no other worktree's
.envuses, and pointsREDIS_URLandCELERY_BROKER_URLat it, so the branch's Celery worker never runs another branch's tasks - comments out
SECONDARY_DATABASE_URL, which would otherwise point at the main checkout's replica
With --share=1, it skips the database and Redis steps and copies DATABASE_URL, REDIS_URL
and CELERY_BROKER_URL from the main checkout's .env instead. Either way, the JS and CSS then
build in the background.
tasks.py defines invoke tasks for common jobs. List them with:
inv -lTo add a Python dependency, use uv add <pkg>; see
Dependency management
for the details.
You don't need the CommCare HQ social app to create local users. The "Log in with CommCare HQ" button stays
hidden until a commcarehq social app exists (see
Setting up auth with CommCare HQ).
To create a superuser, run the command below. --email is not accepted, because the custom User model sets
REQUIRED_FIELDS = []; set the address afterwards in the admin if you need one.
./manage.py createsuperuserTo create a normal user account, go to Sign Up and fill out the form. Local settings use
ACCOUNT_EMAIL_VERIFICATION = "optional", so you are logged straight in; the confirmation email is still printed to
the console if you want to verify the address.
To promote an existing user to superuser:
./manage.py promote_user_to_superuser <email>For convenience, you can keep your normal user logged in on Chrome and your superuser logged in on Firefox (or similar), so that you can see how the site behaves for both kinds of users.
To build local data that hangs together as if the app had been used, run a scenario. It drives the app's real forms, functions and APIs (with CommCare HQ, ConnectID and Twilio stood in for), so validation, visit flags, payment accrual and invoicing all run:
./manage.py run_scenario payments --admin-email you@example.com--admin-email must belong to an existing local user, who becomes admin of every organization the scenario
creates. The command doesn't create one, since that means picking a password; if you have no user yet, create one
with createsuperuser (above). Rerunning a scenario first deletes the organizations it built. The command prints
the pages worth opening. The scenarios and options are described in commcare_connect/simulation/README.md.
generate_sample_data writes rows directly with factories, so it does not go through the app's rules and its
records don't hang together. Use it only when you need volume, for example to look at report performance
(generate_sample_data <num_visits> <org_slug>):
./manage.py generate_sample_data 50 demo-orgThe organization is created if the slug does not already exist. Each run first deletes the existing
opportunities, visits, payments, programs and attachments belonging to the two organizations it is about to use,
including the attachment files under MEDIA_ROOT. Optional flags:
--invited_org_slug— reuse a specific organization as the invited org. Without it, a new invited org with a random slug is created on every run, and the previous one is left behind.--pm_opportunities— how many opportunities the invited org delivers under the primary org's programs (default 3)--image_percent— percentage of visits that get a photo (default 0, none)--audio_percent— percentage of visits that get one to three audio recordings, each with a stand-in transcript and translation (default 0, none)--media_dir— a directory to search (recursively) for image / audio files to use as the attachments for generated visits if requested. Otherwise placeholders are used.
Adding yourself to the generated organizations is a separate step, either through
/admin/organization/userorganizationmembership/ or the organization's own member admin pages. Note there are
two: the primary org from <org_slug> and the invited org, which delivers those opportunities — join only the
first and those stay hidden. Worker tabs list only workers whose OpportunityAccess is accepted, which the
generated ones are.
To seed an opportunity with work areas, groups, workers and visits for the Progress Map:
./manage.py generate_microplanning_data --fake-hqIt prints the Progress Map URL and creates the superuser mpadmin with password mpadmin. --help lists the
other options.
Assigning, unassigning, excluding and editing an assigned work area all update cases on CommCare HQ. --fake-hq
sends those calls to a stand-in for HQ on localhost:8001 and gives each worker an HQ user there. Run the
stand-in in its own terminal:
./manage.py run_fake_hqIt answers every case update and prints the request with its body, so you can see what Connect sends. Start it
with --fail to answer case updates with an error instead. To see the push notification that assignment sends to
ConnectID too, start the Celery worker with CONNECTID_URL=http://localhost:8001/connectid.
Expose your local service to the internet
- Create an account on ngrok and install ngrok
- Create a custom domain on ngrok using this link
- Run
ngrok http --url=[my-unique-subdomain].ngrok-free.app 8000 - Set
DJANGO_ALLOWED_HOSTS=[my-unique-subdomain].ngrok-free.appin your.envfile
Create an OAuth2 application on CommCare HQ
- Navigate to https://staging.commcarehq.org/oauth/applications/
- Create a new application with these settings:
| Setting | Value |
|---|---|
| Client Type | Confidential |
| Authorization Grant Type | Authorization Code |
| Redirect URIs | https://[my-unique-subdomain].ngrok-free.app/accounts/commcarehq/login/callback/ |
| Pkce required | False |
- Copy the Client ID and Client Secret
- Create a new SocialApp locally at http://localhost:8000/admin/socialaccount/socialapp/
Test the OAuth2 flow
- Confirm
COMMCARE_HQ_URLpoints athttps://staging.commcarehq.org. That is the default, so you only need to set it in.envif you have overridden it. - Navigate to http://[my-unique-subdomain].ngrok-free.app/accounts/login/
- Click the "Log in with CommCare HQ" button
- You should be redirected to CommCare HQ to log in
- After logging in, you should be redirected back to the app and logged in
Local settings run Celery tasks eagerly, inside the request (CELERY_TASK_ALWAYS_EAGER defaults to True in
config/settings/local.py), so you don't need a worker. That blocks the request and hides progress UIs, though.
To run tasks the way production does, set CELERY_TASK_ALWAYS_EAGER=False in .env and start a worker:
celery -A config.celery_app worker -l infoFor Celery's import magic to work, run the commands from the folder that holds manage.py.
To run periodic tasks, you'll need to start the celery beat scheduler service. You can start it as a standalone process:
celery -A config.celery_app beator embed the beat service inside a worker with the -B option (not recommended for production use):
celery -A config.celery_app worker -B -l infoRun the test suite:
pytestTo check your test coverage and generate an HTML coverage report:
coverage run -m pytestcoverage htmlThen open htmlcov/index.html.
inv build-js -wThe application runs as Docker containers on EC2, deployed with Kamal, and provisioned with Ansible. See deploy/README.md for deploying to staging and production, server access, logs, Django settings and logical replication.