# PBPS MIS V2 backend

Each business area is one folder in `src/modules`; a module is used by others only through its `index.ts` (checked by `src/architecture.test.ts`).

| Folder | Holds |
|---|---|
| `src/modules/identity` | Login, sessions, 2FA, password reset, invitations |
| `src/modules/access` | Roles, permissions, memberships, scopes |
| `src/modules/projects` | Project profile, settings, locations, durations, regions |
| `src/modules/providers` | Training providers, contracts, staff, onboarding |
| `src/modules/delivery` | Trainings, sites, classes, holidays, breakdowns, calendars |
| `src/modules/registration` | Field schema, trainees, imports, roster freeze and changes |
| `src/modules/duplicates` | Matching keys, candidates, review |
| `src/modules/attendance` | Sessions, marks, corrections, summaries, coverage |
| `src/modules/outcomes` | Report types, templates, submissions, trainee statuses |
| `src/modules/indicators` | Registry, targets, metrics, KPI snapshots |
| `src/modules/activities` | Definitions, schedules, obligations, submissions, reviews |
| `src/modules/verification` | Plans, frames, draws, subjects, results, Kobo |
| `src/modules/grievance` | Public intake, cases, replies, SLA, satisfaction |
| `src/modules/notifications` | In-app notices, mail settings, reminders, digests |
| `src/modules/reporting` | Dashboards and PDF/DOCX/CSV/XLSX exports |
| `src/modules/audit` | Audit browsing, integrity check, export bundle |
| `src/modules/datahealth` | Scheduled data-quality checks |
| `src/modules/backups` | Daily backup, restore test, retention |
| `src/core` | Infrastructure only: database, errors, jobs, files, mail |
| `src/shared` | Pure helpers with no I/O |
| `migration` | V1 to V2 data migration, archive and reconciliation |
| `parity` | Reads V1's source and reports every endpoint V2 does not replace yet |

## Commands
- `npm run dev` starts the API, `npm test` runs the tests, `npm run typecheck` checks types.
- `npm run parity` rewrites `parity/PARITY.md`. Add `-- --release` to fail while anything is missing.
- `npm run migrate:rehearse` **drops and rebuilds V2 and its archive** from V1. The names come from `.env.migration`: `MIGRATION_DATABASE_URL`, `SOURCE_DB` and `ARCHIVE_DB`. It refuses when V2 holds trainees V1 lacks, unless `--discard-test-data` is given. Never run it once V2 holds new data.
