Django REST Framework backend for the SAATHI case-coordination prototype. The
canonical API prefix is /api/v1/; PostgreSQL is the production system of
record and Redis/Celery handle asynchronous work.
Safety status: this is a controlled prototype, not an approved emergency dispatch system or a validated clinical/AI product. Production settings keep the synthetic AI adapters and demo endpoints disabled.
Prerequisites: Python 3.12 and a local virtual environment.
python3 -m venv .venv
.venv/bin/pip install -r requirements.txt
.venv/bin/python manage.py migrate
.venv/bin/python manage.py runserver 127.0.0.1:8000Development uses SQLite unless PostgreSQL is explicitly configured. Do not put real personal, location, health, legal, or audio data in the development database.
The API schema is available at /api/v1/schema/; interactive documentation is
at /api/v1/docs/. The checked-in contract is openapi.yaml.
The peer saathi repository uses /api/v1 and its Vite development server
proxies /api to http://127.0.0.1:8000. Start this backend before the
frontend. Live authentication uses the credential login, refresh, current-user,
and logout endpoints. Demo identities exist only when both DEBUG and the
explicit demo flag are enabled.
POST /api/v1/cases/ creates a pseudonymous case for district officers, state
administrators, and national administrators. The caller submits a visible
district UUID; the backend derives its state, restricts new cases to Complaint
or Investigation, and accepts only an active same-district counsellor. The
request contract and examples are available in /api/v1/docs/.
Copy .env.example to a local, ignored environment file and replace every
placeholder. Then run the Compose stack behind a controlled TLS reverse proxy.
The backend port binds only to host loopback; PostgreSQL and Redis have no host
ports.
docker compose up --buildSet NUM_PROXIES to the number of controlled proxy hops and list only direct
proxy peers in TRUSTED_PROXY_IPS. The database-backed health endpoint is
/api/v1/health/; plain HTTP access is allowed only from container loopback so
the internal probe works while other production routes redirect to HTTPS.
.venv/bin/python manage.py test
.venv/bin/python manage.py check
.venv/bin/python manage.py makemigrations --check --dry-run
.venv/bin/python manage.py spectacular --file openapi.yaml --validate
.venv/bin/bandit -q -r apps config ai -x '*/migrations/*,*/tests.py,*/test_*.py'
.venv/bin/pip-audit -r requirements.txtPostgreSQL/Redis integration, concurrency, load, restore, and disaster-recovery tests remain release gates; the SQLite unit suite does not replace them.