---
title: 'Day 1: The App Starts Talking to ABDM'
series: Building the Caladrius PHR with agents
part: 1
series_total: 15
date: '2026-11-18'
reading_time: 18 min
description: The day the PHR switched from its in-browser mock to the real API. An
  agent audit found eighteen gaps, the first live ABDM sandbox run found seven bugs
  no test could, and the QA deploy failed six times before it worked.
canonical_url: https://caladriushealth.ai/solutions/phr-build-diary/day-1-the-app-starts-talking-to-abdm/
publisher: Caladrius Health AI Studio
---

# Day 1: The App Starts Talking to ABDM

The day the PHR switched from its in-browser mock to the real API. An agent audit found eighteen gaps, the first live ABDM sandbox run found seven bugs no test could, and the QA deploy failed six times before it worked.

*The PHR is built by a small Caladrius team (Giri, Krishna, Preetha and me) working with AI agents; each post ends with what the day meant for each of our areas.*

Day 0 ended with a repository, a rules file and first versions of P1 to P4 that could, in principle, reach the
[ABDM](https://caladriushealth.ai/what-is-abdm/) sandbox. Day 1 was the day they actually had to. It was the busiest day of the project so far: 32 pull requests into
`dev` and 117 commits, plus six promotions to the QA environment.

Three things happened on the same Thursday, and they pulled in different directions:

1. The app's default backend switched from the in-browser mock to the real PHR API, and the functional tests followed.
2. An agent audited the app against NHA's test cases and found eighteen gaps, which other agents then fixed in
   parallel.
3. We ran P1 against the live ABDM sandbox for the first time, with a person holding a phone, and found seven bugs no
   test of ours could have found.

Around all of that, the QA deploy failed in six different ways before it worked. This post goes through each.

---

## 1. Flipping the default: the API is the product, the mock is a demo

Until the night of the 28th, the app had a build flag that chose between two implementations of each milestone's
backend seam: `apiP1`…`apiP4`, which call the PHR API, and `mockP1`…`mockP4`, which run a simulator in the browser.
The mock was the default. That made sense for a UI prototype and made no sense for a product.

Just after midnight the default flipped:

| | Before | After |
|---|---|---|
| `VITE_PHR_BACKEND` unset | mock | **api** |
| Demo | the default build | opt-in: `npm run dev:demo`, `build:demo` |
| Synthetic hints, the `/guide` page | everywhere | demo build only |
| Functional tests (qa, main, on demand) | against the mock | against the API build |
| Label | none | "Demo — synthetic data" on the demo |

Any value other than `api` or `mock` fails the build. A typo should never quietly ship the simulator.

The interesting part was the functional tests. Running NHA's cases against the API build means the browser talks to the
real PHR API, which talks to PostgreSQL, Redis and Valkey (throwaway service containers in CI), which talks to... what?
Not the ABDM sandbox: a test suite can't type a real OTP. So the API talks to a **stub ABDM**: a small Node server that
plays the gateway and the consent manager from ABDM's published specification. It signs its callbacks with a throwaway
key set, so the API's callback authentication runs unchanged. Nothing about security is relaxed for the tests.

The first count was sobering. Of the mandatory cases, the API build passed P1 58 of 63, P2 45 of 66, P3 10 of 15 and
P4 4 of 41. The rest were tagged `@not-api`, each with a reason. Those tags became the to-do list for the next three
days.

## 2. Making the link between NHA's cases and the code mechanical

Day 0 put NHA's catalogue into the repository. Day 1 made the connection between a case and the code that serves it
something CI checks, not something a reviewer has to remember.

- **A case gate.** A script reads every spec, finds the case ids it names, and compares them with the catalogue. It
  reports mandatory cases with no spec, cases whose spec fails, and ids that don't exist. Unknown ids fail everywhere,
  in every pull request's lint. Missing or failing cases are **report-only on `qa` and blocking on `main`**.
- **A screen-change check on `dev`.** Every screen declares the cases it serves (`<TestIds ids={[…]} />`). When a pull
  request changes a screen or a component, CI walks from the changed files to the screens that import them, collects
  their case ids, and runs only those specs against the API build. Later that day I loosened one rule: on `dev`, a
  touched mandatory case that has no spec yet is a warning, not a failure, otherwise the first person to touch a screen
  pays for every missing spec on it.
- **Request bodies checked offline.** We exported 76 ABDM operations and 39 request schemas from ABDM's documentation server
  (catalogue 2026.09.16). Every body our ABDM client sends is validated against its schema in the client's own tests.
  A body that drifts from ABDM's schema now fails a unit test on a laptop, not a call to the sandbox.
- **A registry of cited rules.** Every ABDM-facing constant (OTP resend wait and limit, Aadhaar length and message,
  address and password minimums) lives in one file per workspace as `{ value, source }`, where the source is a case
  id or a documentation URL. The code reads from there. When NHA changes a rule, there is one place to change and one
  citation to check.

```ts
// the shape every cited rule takes
otpResendAfterSeconds: { value: 60, source: 'PHR_ADDR_105 …' },
```

The pull request template, new that night, has two headings that every agent now fills in: **NHA cases affected** and **Plugin
source**. That small change did more for review quality than anything else that day. A reviewer reads the case ids,
opens the plugin section, and checks the change against it.

## 3. The P1 fixes that came first

The night's first P1 pull request tightened sign-up and sign-in:

- **OTP limits from the plugin.** A 60-second wait before resend in every flow, two resends (NHA's count for the Aadhaar route, which we applied to every route), and on the third press
  NHA's own message ("Maximum OTP resend attempts reached. Please try again after 30 mins"). They are enforced in the
  API, mirrored in the app, and published on a config endpoint so the app never guesses.
- **Errors under their fields.** A shared field component with `aria-invalid`, `aria-describedby` and
  `role="alert"`, so a screen reader announces the error next to the input that caused it. Problems that aren't about
  one field stay as a step-level alert.
- **Aadhaar validation before any call.** Twelve digits, first digit 2–9, and a Verhoeff checksum. A bad number is
  refused in the browser with NHA's wording, and the API refuses it again without echoing the value back.
- **ABDM's refusals mapped.** Eight more ABDM error codes became named API errors, each with a test, instead of a
  generic failure.

One bug from that morning is worth telling because it was a real race, not a flaky test. The OTP field sent the OTP
request when it appeared and enabled **Verify** at once. A code typed (or autofilled) before the send had answered went
to verify while the flow was still at "started", and got "This step has expired". On a slow network, that's a real
person failing to sign in. The fix holds a verify until the send answers. A new regression test delays the send by
800 ms. Before the fix, the delayed case failed every time; after it, the delayed case passed 20 out of 20, and a 20-run repeat passed twice, with retries off.

## 4. An agent audits the app against NHA

Early in the morning I asked an agent to do what an NHA assessor would do: walk the API build case by case and list every
place where the shipped app falls short of the expected result. It came back with eighteen items, D1 to D18. Some were
one-line wording changes. Others were whole features that worked only in the demo.

The worst was **D1**: on the API build, "Pull Records" made no API call at all. The screen was importing the
simulator directly, so it stored invented records under a real facility's name. That's exactly what the backend seam
exists to prevent, and it had slipped through anyway.

I split the list across agents in parallel, one branch each, with the larger items as their own pull requests:

| Item | What was wrong | What was built |
|---|---|---|
| D1 | Pull Records used the simulator | Real fetching through the PHR's own consent request (below) |
| D2 | The Scan screen was a static picture | An in-app QR scanner and ABDM's counter URL as a route |
| D5 | The bell said "1 unread"; the list was empty | Notifications read from the API |
| D7 | Locker uploads were stored unchecked | The locker decides whether an upload is a health record |
| D8 | One office IP was locked out mid-test | Rate limits per flow and per identifier, under a per-IP ceiling |
| D3, D9–D15, D18 | Wording, buttons, demo leftovers | One branch, one commit per area, NHA's wording verbatim |

### 4.1 Pull Records: the PHR as its own HIU

The design came straight from ABDM's PHR playbook: when the app fetches a record for its user, the app is the health
information user (HIU), so it raises the consent request and the health information request itself. The flow:

1. **Pull Records** on a linked facility sends one API call. The API refuses a facility that isn't linked to the
   account.
2. The API raises a consent request: purpose "Self Requested", that facility, every record type, the last ten years.
   If it already holds a granted, unexpired consent artefact for it, it skips straight to the data request.
3. The facility card shows **Waiting for your approval** with a link to the request.
4. The person approves (and can narrow the record types and dates) or denies it in Consents.
5. On a grant, the API fetches the artefact, sends the data request with fresh ECDH keys, and receives the hospital's
   encrypted push. It **checks the consent before decrypting**, then stores each record encrypted (AES-256-GCM) with
   an encrypted summary for the list. Revoked or expired consent erases what it brought in.
6. **My Records** lists only what a live consent covers, and every read writes an audit entry naming the consent.

Two guards came with it, so D1 can't happen again. A lint script fails if any non-demo module imports the simulator.
A build check fails if the simulator's text appears in the API bundle. We checked it both ways: the API bundle is
clean, and the demo bundle trips the check.

The stub ABDM grew to match. It plays consent init, the patient's approve, deny and revoke, artefact fetch and the data
request, then pushes as the hospital: NRCES FHIR bundles, each checked with the documentation server's FHIR validator,
encrypted with the same Fidelius code the API uses to decrypt. P2's mandatory cases on the API build went from 38 to
50 of 66.

### 4.2 Notifications without personal data

The notification list was the easy half. The harder question was what a stored notification is allowed to contain. We
settled on a **message key plus whitelisted parameters**: a facility or requester name and a count. No ABHA address or
number, mobile, name, token or record content is stored or returned. The app renders the text in all five languages
from the key. An id belonging to another account answers 404, not 403, so the API doesn't even confirm it exists.

### 4.3 Rate limits per person, not per office

NHA's testers run P1 from one office network. Our auth tier counted requests per IP only, so a tester was
locked out halfway through a run, and the 429 told them to wait "a minute" for a much longer window.

The new design runs two counters on the auth and OTP tiers: a per-person budget under a per-IP ceiling.

A 429 now carries `Retry-After`, and the app shows the actual wait in the
person's language. The per-identifier OTP budget stayed the primary control; this tier is the backstop.

### 4.4 "Is this a health record?" without sending it anywhere

NHA's locker case PHR_LOCKER_402 says the locker should accept only health documents. It doesn't say how. Our rules
narrow the options: no patient document leaves our infrastructure without consent and a privacy-notice entry, and
inference stays in India. So the agent built the check in-process, inside the API:

1. A **structural screen**: a PDF needs its end marker, a picture at least 100 px on its short side.
2. **FHIR JSON** must be a FHIR Bundle, and it is filed under the record type its own Composition declares.
3. **PDF, JPEG and PNG**: text is extracted in a worker thread (the PDF text layer, or local OCR for pictures, with the
   language data shipped in the image and nothing fetched at runtime), with caps on time, memory and image size. The
   text is scored against a curated vocabulary of health terms in all five languages.
4. Below the threshold, the upload is refused. **If the file can't be read** (a scanned PDF with no text layer, a
   timeout), it is refused too. Refusing beats accepting blindly.

The extracted text lives in memory only: it is scored and dropped, and never logged, stored or returned.

By midday I'd asked for more formats: FHIR JSON validated properly, DICOM and TIFF. For FHIR, the agent took the
validator recipe from the ABDM documentation (the HL7 validator with the NRCES implementation guide) and ran it as
**its own internal service**: a separate container on an internal-only network shared with the API, no published port,
both downloads pinned by SHA-256 at build time and nothing downloaded at runtime. The validator's messages quote the
record, so the service answers with counts and issue-type codes only. Errors refuse the upload; if the validator is
down or slow, the upload is refused with "check unavailable", never accepted unchecked. DICOM is parsed by
hand, within bounds, without a library; TIFF is decoded with the tiff library.

That evening the image scanner refused the validator image: the pinned validator version carried known
vulnerabilities, and the service validates patient-uploaded documents, so they were reachable. The choice was to
suppress or upgrade. We upgraded to the current major version, which meant rewriting the small Java front end against
its new API. The HTTP contract stayed the same, so the API didn't change.

## 5. The first P1 sandbox run

In the afternoon we did what no stub can do: a tester with a phone ran P1 against the live ABDM sandbox through a
local build, with an agent driving the plugin's checklist and recording each step. Ten steps (5 to 14) were done by
the evening, and the run found seven bugs. Three are worth describing.

**The wrong key for one route.** Creating an ABHA address from an existing ABHA number encrypts the number and the OTP
before sending them. We encrypted with the PHR app's certificate. ABDM decrypted with a different one, got an empty
string, and answered with an error about a string index out of range. It took five requests across two numbers and
both OTP systems to rule out the obvious causes. The same request encrypted with the **ABHA service certificate**
returned 200 and an OTP. Neither the specification nor the plugin names a key per route; the sandbox did. The rule went
into the plan: the ABHA-login scope takes the ABHA service key, the ABHA-address scopes take the PHR key. A new test
uses two different key pairs to prove each route picks the right one.

**A flow that died with its token.** The verify step returns a token the sandbox keeps alive for a few minutes. Our
creation flow ended when that token did, so "Create & finish" failed with "This step has expired" before enrolment was
even called. But enrolment only needs the transaction id. The flow now lives its full 30 minutes, and the one step that
needs the token checks it itself and sends the person to sign in if it has lapsed.

**Which token the password flow keeps.** Setting a password on an address that had none failed with "Invalid
T-token". The OTP went to that one address, so the token verify returned already belonged to it; we were treating it
as a pre-choice token and exchanging it again. The sign-in route already handled this correctly. The password flow now
does the same.

By the end of the day P1 stood at 16 of 18 steps; e-mail sign-in and the formal NHA run were left. The plan recorded
every step with its sandbox request ids and statuses, and **no identifiers**: no mobile, Aadhaar, ABHA value, OTP or
password.

One more fix came from the sandbox that day: the ABHA card and QR downloads got `406 Not Acceptable`, because every
call sent `Accept: application/json`, including the ones that return an image or a PDF.

## 6. The QA deploy, six failures deep

The first full-stack deploy to QA (app, API, PostgreSQL, Redis, Valkey) had to pass the
[security gates](https://caladriushealth.ai/platform/brief/#security) and then
actually start. It failed six times, each time further along; four are worth telling:

1. **The image scanner** found an outdated OpenSSL in the base image and vulnerable dependencies inside the npm that
   ships with Node. Nothing at runtime needs npm, so the runtime image upgrades its packages and deletes npm; the
   migration runner is called directly.
2. **The dependency gates disagreed.** The npm audit gate and the image scanner each keep their own exception file,
   with a reason and an expiry for every reviewed exception. An exception recorded in one wasn't in the other. The lesson
   was to keep the two lists in step.
3. **PostgreSQL hung at authentication.** Every connection, including the container's own setup client, stalled. The
   agent traced it on the host, with throwaway containers, to an interaction between one container option and the
   host's container runtime, and changed the QA compose file. Local compose was untouched; the bug was specific to that
   host.
4. **The deploy script stopped halfway, successfully.** The script was streamed to `bash -s` over SSH, so bash read
   it from standard input while running it. A health-check command inside it also read standard input and swallowed
   the rest of the script. Bash hit end-of-file after the database came up and exited 0. Redis, Valkey, the API and the
   app were never started. The fix is an old shell idiom: put the whole body in `main()` and call
   `main "$@" </dev/null` on the last line, so bash parses everything before running anything.

That evening GitHub stopped starting hosted jobs on the account, so CI moved to self-hosted runners. Main builds
stayed on GitHub-hosted runners. PostgreSQL in CI then started timing out on disk under load; the throwaway test database moved to tmpfs and
counts as ready only when the final server answers on TCP.

## 7. Meanwhile, on an iPhone

All day I was also using the app on a real iPhone and iPad and sending back screenshots. Agents fixed what I found,
and each fix taught something about the web platform on iOS:

- In an installed iOS web app with a translucent status bar, `100dvh` **leaves out the status bar**, so the app
  stopped one status bar short of the bottom.
- The glass bottom menu floated as a pill **above Safari's own floating toolbar**, two bars stacked. Now the menu floats
  only when there is no browser chrome (installed), and docks in a browser tab.
- On iPad, the back arrow sat under the window controls in the top-left; headers now keep that corner clear.
- Absolutely positioned screen-reader text escaped its scroller and dragged the sticky header up under the status
  bar.

A scripted check now proves there is no horizontal scroll across 31 routes at six widths from 320 to 768 px, including
at 125% text size.

## 8. What I learned on Day 1

- **The sandbox is the real specification.** The key for the ABHA-number route, the token lifetimes and the `Accept`
  header aren't in any document we had. Each one cost an hour against the sandbox and minutes to fix. Writing the
  answer into the plan, with the evidence, means nobody pays that hour twice.
- **An audit agent is worth running early.** Asking one agent to read the app the way an assessor would found a
  feature that only pretended to work. Tests didn't catch it, because the tests that covered it were switched off on the API build (`@not-api`) and had run against the same simulator the
  screen was secretly using.
- **Turn each lesson into a guard.** Most fixes that day came with something that stops the bug coming back: a lint
  rule against importing the simulator, a bundle check, a schema test for each request body, a regression test for a
  race. Agents fix the same mistake twice if nothing stops them.
- **Don't relax security for tests.** The stub ABDM signs its callbacks, so the real callback authentication runs in
  every functional test. A test that bypasses the control proves nothing about it.

*Next, Day 2 (30 October): the health locker learns to be a hospital, and the stub ABDM learns to play every other
party in the exchange.*

## The team behind Day 1

The PHR is built by a small Caladrius team working with AI agents:

- **Giri**: CEO; Cally taxonomy and intent framework
- **Krishna**: development, infrastructure and go-live
- **Preetha**: narrative engineer, personas
- **Manish** (me): CTO and CPO, enabling the Caladrius Health AI PHR and the AI Studio framework

### Cally: taxonomy and intent (Giri)

Day 1 had no Cally work, but it laid groundwork Giri's area will build on. Pull Records gave a record a lifecycle the
person can see: a consent request raised, "Waiting for your approval", a grant that can narrow record types and dates,
and My Records listing only what a live consent covers. A question like "why can't I see my records from this
hospital?" now has answers that are consent states, and the taxonomy has to respect the same line the screens do.

Notifications set another pattern: a message key plus whitelisted parameters, rendered in five languages, with no
identifier or record content stored. That is a useful model for how Cally's answers about events can be shaped:
categories and counts, never the personal data behind them.

### Development, infrastructure and go-live (Krishna)

On the infrastructure side, which Krishna leads, Day 1 was the busiest so far: 32 pull requests into `dev`, 117
commits and six promotions to QA. The first full-stack QA deploy failed six ways before it worked, including an outdated
package in the base image, two exception lists that disagreed, a database that hung at authentication on that one
host, and a deploy script that stopped halfway while reporting success. None of the fixes disabled a gate; three reviewed, expiring exceptions were added.

When hosted CI jobs stopped starting that evening, CI moved to self-hosted runners (main builds stayed on GitHub-hosted ones) and the test database moved to
tmpfs. The FHIR validator became its own internal service with pinned downloads, and the stub ABDM let the functional
tests run against the API build with callback authentication unchanged.

### Narrative and personas (Preetha)

Day 1's fixes were about real people at real moments. A tester on an office network was locked out halfway through a
run, so rate limits moved to the person and the flow, and a 429 now tells them the actual wait in their own language.
A person on a slow network could fail to sign in because they typed the OTP too quickly; that race is gone. Someone
using a screen reader now hears an error next to the field that caused it.

The wording followed NHA's text verbatim where NHA has text, and the demo build gained its label, "Demo — synthetic
data", so nobody mistakes the simulator's invented people for the product. The day's iPhone and iPad fixes were the
same story: the app has to fit the device the person actually holds.

### Product and technology direction (Manish)

I made the API the product and the mock a demo, and kept any other build value failing, because a typo should never ship
the simulator. I asked an agent to read the app the way an assessor would, and split its eighteen findings across
agents in parallel, with the larger items as their own pull requests. On `dev` I loosened one rule, so a touched
mandatory case with no spec warns rather than fails.

Two choices were about refusing the easy path. An upload that can't be read is refused, not accepted blindly. And when
the scanner flagged the validator, we upgraded to the current major version rather than suppress the finding.

## Further reading

- [Caladrius Health](https://caladriushealth.ai/), the company behind the PHR
- [The Caladrius platform brief](https://caladriushealth.ai/platform/brief/): AI Studio, [Cally](https://caladriushealth.ai/platform/brief/#cally), the [Health Vault](https://caladriushealth.ai/platform/brief/#vault), the [design system](https://caladriushealth.ai/platform/brief/#design-system) and [security by design](https://caladriushealth.ai/platform/brief/#security)
- [Caladrius Pulse](https://caladriushealth.ai/blog/), our blog, including the ABDM series ([What is ABDM?](https://caladriushealth.ai/what-is-abdm/)) and the NHCX series ([What is NHCX?](https://caladriushealth.ai/what-is-nhcx/))
