CONFIDENTIAL · ArrAI internal · MedR client review · not for distribution outside ArrAI
MedR · Knowledge Transfer · Deck 3 of 3

What There Is To Do

The work identified by reading the system end to end. This deck names and sizes the problems; it deliberately does not propose how to solve them. Everything here was verified against source, and the handful of things that could not be verified are marked as such rather than dropped or asserted.

8 workstreams 26 registered findings 3 items in the brief corrected

00The five things worth saying out loud

1 · Switching email on as it stands would send practitioner notifications to patients

All ten practitioner-facing referral emails overwrite the recipient address with the patient's before sending. The patient would receive three differently-templated emails per referral event, each carrying the other parties' names, roles, email addresses and phone numbers; the practitioners would receive nothing. This is a patient-data disclosure, not a cosmetic bug, and it sits directly in the path of the first agreed deliverable. It must be fixed before the switch is flipped, not after.

2 · Email is not a notifications feature — it gates registration

The only route to a verified practitioner account runs through the emailed verification link. No staff approval step exists anywhere. So on a production-mode deployment with email broken, no new practitioner can onboard at all, no one can reset a password, and no delegate can be invited. That reframes the email work from "nice to have before launch" to "the launch depends on it".

3 · The frontend in the brief is not the frontend that exists

The React workspace application described in the documentation was deleted in April 2026, along with the entire Cypress end-to-end suite. What ships is a design-tool export, developed in place ever since. It has no router, no tests, and no error boundary. This is not a reason to rewrite it — but every estimate, every onboarding note and every reference to "the frontend" needs to point at the right thing.

4 · Referral emails cannot link into the app even once they send

The app recognises four ?type= values, and type=referral — the one the referral emails are built to send — is not among them. Combined with the fact that all ten practitioner dispatch sites pass an empty host, the "view this referral" link is broken at both ends. Deep-linking is a prerequisite for the email work, not a separate nicety.

5 · Live-looking credentials are committed to the repository

backend/env.staging is tracked by git. The .gitignore pattern .env* does not match it, because the filename has no leading dot. It contains a Django secret key, an AWS access key ID and secret, Mailjet API key and secret, two Slack incoming webhooks, a Google Maps API key and a database password. They are in the history, so deleting the file is not sufficient — the keys need rotating.

Two notes. The client's own infrastructure summary says secrets were rotated out of this branch; it is worth confirming that these specific keys were included. And separately: the Mailjet credentials blocking our email work may simply be sitting here — worth raising with Anshul rather than assuming either way.

6 · The public demo is running with Django DEBUG = True

Confirmed live: any 404 on the demo returns Django's debug page, which states DEBUG = True and prints the complete URLconf — 105 URL patterns, i.e. the entire API surface. django-debug-toolbar is installed. With DEBUG on, an unhandled 500 renders a full traceback including source lines and settings values.

This compounds the nginx finding: on the demo box /api/ and /medr/ sit outside the basic-auth gate, so the debug page and the Django admin login are both reachable from the open internet.

The useful deduction: DEBUG, MAILJET_SEND_EMAILS and SEND_SLACK_NOTIFICATIONS are all derived from one predicate — is_production_env(ENV_TYPE) — with DEBUG as its inverse. So seeing DEBUG = True from outside the box proves the demo runs a non-production ENV_TYPE, which proves email and Slack are both switched off there by that same single lever. We now know the demo's configuration without needing shell access to it.

And the consequence for delivery: those three behaviours are welded to one variable. Enabling email on the demo by flipping ENV_TYPE would simultaneously turn DEBUG off and turn Slack notifications on. They cannot currently be moved independently, which makes a staged rollout of the email work awkward. Decoupling the flags is a small piece of work that unblocks the rest.

01Three things in our own brief that the code contradicts

Raised early because they change what deliverable 2 actually is. Each was checked by reading the code and then by executing it.

What the brief saysWhat the code doesConsequence
Users receive a 400 whose body is a raw stringified dump of internal ErrorDetail objects refuted Users receive {"detail": "Invalid input data."}. The base view intercepts its own HTTP handlers through a __getattribute__ override and wraps every one in the exception handler, which converts the validation error into that generic message. Confirmed by executing a real request against a real view: status 400, body {"detail":"Invalid input data."}. Removing the interception reproduces the raw dump the brief describes — so the description matches the code with one line deleted, not the code as it stands. Deliverable 2 is still real, but it is a different problem: not a leak of internals, but the opposite — every validation failure across the product collapses into one opaque sentence with no field-level detail.
handle_view_unknown_exceptions is dead code, applied nowhere refuted It is applied to get, post, put, patch and delete on every view inheriting the base class, dynamically at attribute-access time. A search for the @ decorator syntax finds nothing, which is presumably where the impression came from — but the coverage is broader than hand-decorating, not narrower. No work needed to "revive" it. The behaviour it produces is the thing to improve.
The tests asserting "Invalid input data." fail refuted as stated All eight of those assertions pass. The suite's overall health is a separate question with a genuine finding behind it — see D6 below. The failing-test symptom does not trace to the error fault in the way described.

02The workstreams

D1
Make the email service actually deliverThe first agreed deliverable. Four independent breakages, each of which alone is enough to stop delivery.
critical
  • Fix the recipient bug first. Ten referral email classes address the practitioner's notification to the patient. Nothing else in this workstream is safe to ship before this.
  • Author 18 missing Mailjet templates. 6 of 24 template IDs are real. The other 18 are the literal integers 1–18 and cover every referral email, both delegate emails and the staff error notification — that is, the entire core loop of the product.
  • Run a Celery worker. Worker and beat are commented out of both compose files. The worker command names the wrong application. Beat additionally references a package that is not a dependency — and since nothing schedules periodic work, beat should stay off rather than be fixed.
  • Reach the master switch. Sending is derived from ENV_TYPE alone; the MAILJET_SEND_EMAILS variable that appears in the env files is read by no code. Every env file in the repo says DEVELOPMENT.
  • Give links a real base URL. Ten dispatch sites pass an empty host. An EMAIL_LINK_BASE_DOMAIN variable exists in the env files and is read by nothing. Verification and reset links instead take their base from the request's Origin header.
  • Fix the subject lines. All fifteen referral emails, including rejections and did-not-attends, are titled "You have been referred by …".
  • Build post-send status handling. The EmailSent model, its migration and a complete status-transition manager exist; no code ever writes a row. Mailjet's returned message IDs are discarded and there is no inbound webhook. The de-duplication guard that reads this table is consequently a permanent no-op.
  • Honour the notification preferences. Four per-user switches are stored and editable in the UI; no dispatch site consults them. There is no unsubscribe link in any template payload.
  • Add retry and failure visibility. Neither task sets retries. The only alarm is a Slack card posted from inside the exception handler — if Slack is also failing, that call masks the original error.
Why it is bigger than "turn on Mailjet": the four break points are independent. Fixing the worker alone delivers eighteen invalid template IDs. Fixing the templates alone delivers them to patients. Fixing both without the base URL delivers mail whose links go nowhere. The order matters more than the individual pieces.
D2
User-facing error handlingReal, but a different problem from the one in the brief.
high
  • Every validation failure says the same thing. The backend collapses all field errors into {"detail": "Invalid input data."}. A user who mistypes one field in a fourteen-field referral form is told only that something is wrong.
  • The frontend then discards what little arrives. A small extractor is copy-pasted byte-identically into ten files and reads only detail. Roughly forty further error toasts ignore the backend reason entirely and hardcode a generic string.
  • The diagnostic log line is destroyed. A malformed logging call means the serializer errors never reach the log — only a logging-internal traceback does. When a 400 is investigated, the record of which field failed is missing.
  • One path genuinely 500s on bad input. Password reset with a malformed email returns a server error rather than a validation error — verified against the live demo.
  • No error boundary anywhere in the frontend. A render-time exception blanks the application.
  • Validation rules are hand-rolled per form and are not shared with the backend serializers. A validation library is a dependency but is used by exactly one unused file.
  • A success path shows a red error toast when a referral is denied.
Reframing: the brief describes a leak of internals. The actual defect is the mirror image — internals are suppressed so completely that nothing useful reaches the user. The fix direction is field-level errors surfaced next to fields, which is a larger and more valuable piece of work than sanitising a dump.
D3
Routing and deep linksA prerequisite for D1, not an independent nice-to-have.
high
  • No routing library. Navigation is one React state value switched over in a single component. The address bar shows / on every screen.
  • Email links cannot target a referral. Four ?type= values are recognised; type=referral is not one of them, and it is exactly what the referral emails emit.
  • Back exits the application. No history entry is ever pushed and there is no popstate listener.
  • Refresh loses everything — screen, filters, tabs, form drafts, pagination, open modals.
  • Nothing can be bookmarked or shared — no referral, no patient, no practitioner profile.
  • Query parameters are actively stripped from the URL on mount, so even the three policy pages that accept one cannot be re-shared from the address bar.
  • Two conflicting definitions of the page-name type are both exported under the same name and imported across the codebase, so some screens cannot legally navigate to pages their siblings can.
Sequencing note: referral emails are worth little until a link in one can open the referral it is about. Whatever shape the fix takes, this lands before or alongside D1's referral templates.
D4
Unwired features that look finishedScreens and controls a user can reach today that do nothing.
critical
  • The clinical letter upload is discarded. The form accepts a file; the payload omits it; no attachment model exists. The landing page advertises the feature.
  • Editing a referral silently duplicates it. The screen relabels itself and then submits to the create endpoint. The update endpoint has no caller in the frontend.
  • The admin screen is entirely hardcoded. Seven real staff endpoints exist on the backend and the screen calls none of them; its controls persist nothing.
  • Registration from a public page does nothing afterwards — the success callback is empty, so the user is neither signed in nor moved.
  • Delegate permission switches are cosmetic, and the create endpoint discards what the form submitted.
  • "Request a demo" persists nothing — a Slack message only, so a missed enquiry is unrecoverable.
  • The account-review message is untrue — it promises a review step that does not exist.
  • A fully-mocked "new referral" modal is mounted on five screens and reachable from none. Wiring any button to it would silently fake referrals.
Scope question for the client: some of these are launch-blocking (the letter upload, the duplicate-on-edit), others are cosmetic. This list is deliberately not pre-triaged — the split is the client's call.
D5
Security and data-protection hygieneReported factually. Several touch patient data, so they need a decision even if the answer is "accept the risk".
critical
  • Credentials committed to the repository and present in history — see headline 5. Rotation, not deletion.
  • Plaintext passwords and patient details written to the application log. Whenever validation fails, the entire request body is logged — including the login, password-set, registration and patient create/update paths.
  • The dummy email sender logs patient names and email addresses at info level into a mounted, persistent volume.
  • Emailed links are built from the request's Origin header rather than a configured domain. A request with a forged header produces an email containing a link to another domain carrying a live verification code. This becomes exploitable the moment real email is switched on.
  • The demo box's API and Django admin are not behind the demo password. Basic auth covers the app shell only.
  • The demo runs with DEBUG = True, leaking the full URL map on any 404 and a full traceback on any unhandled error — through that same unauthenticated path.
  • Session tokens live in localStorage on a platform holding patient-identifiable data, and the client-side check tests only that a token is present, never that it is valid.
  • The role used to draw the admin navigation is read from an editable browser value. Worth stating plainly: this is a cosmetic spoof, not a data exposure — the backend enforces permissions server-side and the admin screen calls no API. It becomes real the day that screen is wired up.
D6
Build, CI and the test suiteThe safety net we would rely on while doing everything above.
high
  • The backend image cannot be built from a clean clone. The Dockerfile copies a requirements file that .gitignore excludes and no script in the repo generates. This is the documented local-run workaround, and it is worth fixing properly rather than documenting again.
  • The deploy script's database backup step is an empty function. It prints "Backing up database instance…", takes no backup, and the next steps run migrations against live patient data. A bad migration is unrecoverable. This is the single most alarming line in the deployment path.
  • The health check probes the wrong port and the wrong path — port 8008 against an app on 8000, with a trailing slash the route does not have. The backend container reports unhealthy permanently.
  • The service-status cron is implemented and its call site is commented out, so the five-minute health monitor is never installed.
  • CI runs lint, type-check, test and build, and deploys nothing. There is no deploy stage, no environments, no rules and no manual jobs. Every step from build onward is run by hand from a laptop holding AWS credentials and a private key.
  • The repository does not pass its own strict type-check.
  • There are no frontend tests at all. The Cypress suite died with the frontend deletion and was never replaced.
  • The backend suite passes as committed — 539 passed, 1 skipped, 540 collected. Worth knowing why it is fragile though: a malformed logging call in the shared base view raises a TypeError on every validation failure, and it is only swallowed because the app loggers are configured not to propagate to the root logger. In an environment where that configuration does not apply, pytest's own log handler re-raises instead of swallowing and 69 tests fail. The suite is green, but it is one logging-config change away from not being.
D7
Launch verificationThe third agreed deliverable.
medium
  • A written journey script covering all six roles, walked on the demo after each deploy and on production at launch.
  • Email verification in a real inbox for every one of the 24 template types, in both the practitioner and patient directions — this is the acceptance test for D1 and cannot be done from the code.
  • Confirmation of what is actually running on each box. The deployed compose file lives on the EC2 host and is not in the repository, so several claims here — most importantly whether a Celery worker exists in production — cannot be settled from the repo alone.
D8
ContinuityThe fourth agreed deliverable, and the one with the longest lead time.
high
  • Bus factor of one. Of roughly 4,400 commits, about 4,270 are from a single author. Everything below follows from that.
  • An access map: AWS, ECR, the EC2 boxes and their keys, Route 53, Mailjet, Slack webhooks, Google and Jawg API keys, GitLab.
  • A plain-steps runbook for deploy, rollback and database restore — with one full deployment executed from the runbook alone by someone who did not write it.
  • Correcting the repository documentation, which currently describes a frontend, a directory layout, a linter, a CI pipeline and two script names that do not exist.
  • Sentry on the backend. It is present in v1 and absent here; the only trace is a CORS allowance for the frontend SDK's headers.

03Full finding register

Everything found, with severity and confidence. Ordered by severity. "Unverified" means it could not be settled from the repository and needs a check against the running system.

SevFindingEvidenceArea
critPractitioner referral emails addressed to the patientTen *ReferrerInput/*TargetInput classes overwrite the recipient in get_email_variables(). Independently re-derived and confirmed.email
crit18 of 24 Mailjet template IDs are placeholdersLiteral integers 1–18 covering all referral and delegate email. Counted mechanically; cross-checked against the length assertion the service makes at start-up.email
critNo Celery worker in either compose fileBoth blocks commented out; worker command names the wrong app. Redis runs, so the queue exists with no consumer. Production state unverified — the deployed compose file is not in the repo.infra
critCredentials committed and in git historybackend/env.staging is tracked; the .env* ignore pattern misses it. Django secret key, AWS key pair, Mailjet key/secret, two Slack webhooks, Google API key, DB password. Values not tested.security
critPasswords and patient data written to the logThe whole request body is logged on any validation failure, across login, password and patient paths.security
critDeploy script's database backup is an empty functionPrints a stage line and returns. Migrations then run against live data on every deploy.ops
critBackend image cannot be built from a clean cloneDockerfile copies a gitignored file that no script generates.build
critClinical letter upload is discardedNo file in the payload, no field on the serializer, no attachment model. Advertised on the landing page.product
critEditing a referral creates a duplicateEdit screen submits to the create endpoint; the update endpoint has no frontend caller.product
critAdmin screen is hardcodedThree sample arrays, zero API calls, reachable from the admin sidebar. Seven real staff endpoints go unused.product
critPublic demo runs with DEBUG = TrueVerified live: a 404 returns Django's debug page leaking all 105 URL patterns; debug toolbar installed; a 500 would render a full traceback with source and settings. Reachable without the demo password, since /api/ opts out of basic auth.security
highPassword reset returns a 500 on ordinary bad inputVerified live: POST /user/password/reset/ with a non-email string returns HTTP 500 {"detail":"An unknown error occurred on the server."} where it should return a 400. The one user-facing path found that genuinely errors rather than validates.UX
medDEBUG, email and Slack are welded to one variableAll three derive from is_production_env(ENV_TYPE). Email cannot be enabled without also changing DEBUG and Slack behaviour, which blocks a staged rollout.config
highReferral email links are broken at both endsTen sites pass an empty host; the five patient templates carry no link; the app does not recognise type=referral.email
highNo delivery trackingEmailSent is never written; message IDs discarded; no webhook; the de-duplication guard is a permanent no-op.email
highAll 15 referral subjects are identicalRejections and did-not-attends arrive titled "You have been referred by …".email
highNotification preferences are ignoredFour switches stored and editable; no dispatch site reads them. No unsubscribe link.email
highEmailed links built from the Origin headerNine call sites. A forged header yields a link to another domain carrying a live code.security
highEvery validation error collapses to one messageBackend returns a single generic string; the frontend extractor reads only that key; ~40 further toasts discard it entirely.UX
highNo router: no deep links, no back, no bookmarksState-based navigation; query params stripped on mount; refresh resets to the dashboard.frontend
highHealth check probes the wrong port and path8008 vs 8000, plus a trailing slash the route lacks. Container permanently unhealthy.infra
medTest suite is green but fragile539 passed / 1 skipped as committed. A malformed logger.error(dict, "\n\n") call in the shared base view is swallowed only because app loggers set propagate: False. Remove that and 69 tests fail. Fix the logging call regardless — it also destroys the diagnostic line.CI
highRepository fails its own strict type-checkThe CI type-check gate does not pass on this branch.CI
highNo frontend testsThe Cypress suite was deleted with the old frontend; nothing replaced it. No test script exists.CI
medDemo API and Django admin are not password-protectedBasic auth is declared after the location blocks; /api/ and /medr/ both opt out.security
medSession token in localStorage; presence-only auth checkA revoked token renders the full authenticated shell until the first API call fails.security
medDelegate permission flags are never readStored, surfaced and toggled; no consumer. Three are hardcoded true on creation.product
medService-status cron never installedImplemented; its call site is commented out. Its Slack variable name matches nothing the repo generates.ops
med"Request a demo" persists nothingSlack only. Contrast the help-request endpoint, which does store a row.product
medRegistration from a public page does nothing afterwardsEmpty success callback on four pages.frontend
medAdmin lands on the wrong page on first loginA stale captured value; self-corrects on refresh.frontend
medMisleading "await review" messageNo review step exists; the account is already live.UX
lowSuccessful denial shows an error toastSuccess path calls the error toast.UX
lowAnalytics export is a stubReturns an empty object; the button is commented out.product
low~1,300 lines of unreachable frontend code shippedTwo unreachable pages including an 813-line design-tool component gallery, plus a fully commented-out page.frontend
lowDebug prints in production pathsRequest metadata, headers and body printed on every registration.backend
lowDocumentation driftFrontend, directory layout, linter, CI stages and two script names all described wrongly.docs
lowProbable typo in the production nginx server nameA comma where nginx expects a space, which would send the apex domain to the API block. Needs a live check.infra
lowBilling screen will return a server error in NovemberA month-arithmetic bug in the placeholder subscription view. The placeholder is fine; the 500 is avoidable with a one-line change.backend

Deliberately excluded

Checked, and left alone because the client has already decided them: the invite-a-practitioner flow that records no invitation; the billing placeholder; social login and magic links. Also excluded: one claim that the frontend renders mock data on many screens — that is not true. Apart from the admin screen, every page is on the live API. The sample fixtures in the repository are dead code, not something users see.

04Open questions and blockers

Blocking

  • Mailjet account access — 18 templates need authoring there, and no template work can start without it. Note that Mailjet credentials appear to be committed in backend/env.staging; confirm with Anshul whether those are live before anyone uses them.
  • AWS account access — being set up client-side.
  • Access to the Loom infrastructure walkthrough — request already sent.

Needs one answer, each cheap to get

  • Is a Celery worker running in production right now? The deployed compose file is on the EC2 box and not in the repository. One command settles it, and it determines whether any notification has ever been delivered in production.
  • Were the committed keys included in the rotation the client's infrastructure summary describes?
  • Is the demo box a separate EC2 target? The deploy script has only two targets and defaults to the non-MedR one; there is no demo target in the repo.
  • Is a delegate meant to be able to accept, reject, book and mark DNA on a practitioner's behalf? They can today. It is a clinical-governance question, not a technical one.
  • Is excluding your own speciality from practitioner search intentional? It blocks second-opinion referrals.
  • Should accepting an insurer apply to every one of a practitioner's clinics? It does today, and per-clinic differences cannot be expressed.