DRAFTFIG. HOSHCARE-API
SUPERSEDED JUL 2026Node.jsExpressPrisma 6PostgreSQL 15
NestJS Consolidation

HOSHCARE API - Backend Data Pipeline

1. the problem

The original backend for HOSHCARE: token verification on every request, four relational data models, encrypted document streaming, and an extraction pipeline that dispatched medical scans to Gemini Vision and returned structured fields for review. Extraction never wrote directly to primary storage - output was buffered in staging, awaiting human review. Query strings in download endpoints leak tokens into server logs and browser history - header-only auth is non-negotiable for medical documents.

INTERACTIVE PIPELINEClick any box to inspect architecture
client uploadmultipart/form[bearer auth]upload streamexpress gateway• token validation• disk buffer write• worker dispatchingestion gatewaygemini 1.5 flashstructured schemarx date / doc / dosesstaging buffer (uncommitted)ai extractionlocked!postgres
STAGE 01 // Header-Only Authenticated Stream

ROLE: Streaming HTTP upload handler enforcing strict RFC 6750 Bearer token headers. Query string tokens are rejected at the edge to prevent URL logging in upstream reverse proxies.

POST /api/documents/ingest HTTP/1.1 Host: api.hoshcare.internal Authorization: Bearer eyJhbGciOiJIUzI1NiIsInR5cCI6... Content-Type: multipart/form-data; boundary=---------------------------9747672998 Content-Length: 1489120 [EDGE_AUTH] JWT Signature verified · User: usr_90b21a · Role: PATIENT_WRITE
INVARIANT: Zero tokens allowed in GET/POST query parameters; all authorization resides in HTTP headers.
FAILURE GUARD: Eliminates credential leaks in Nginx access logs, CDN telemetry, and browser history.

2. what i built

The ingestion backend pipeline and verification architecture before the NestJS cutover:

header-only token auth
structured JSON schema
4 relational Prisma models
ephemeral disk buffer
uncommitted staging buffer
immutable write lock
multipart streaming
retry queue with backoff

3. problems i had to crack

Click card to view root cause & code diff
Aschema drift broke production queries
▼ DIFF

A column existed in the Prisma schema and in application code but not in the running database. Requests failed on a field that looked present everywhere it was read. Fixed by enforcing that db push and generate run strictly together in CI, never separately.

Bgemini returned empty object {}
▼ DIFF

Gemini was returning {} with a 200 status on some documents. The responseSchema was under-specified - fields not explicitly declared were silently dropped rather than rejected. Fixed by declaring every field explicitly and adding an empty-payload retry guard.

Cdownloads leaked auth tokens
▼ DIFF

The browser's native download cannot attach an Authorization header, tempting query string tokens. Query strings land in server logs and browser history - unacceptable for medical records. Kept header-only auth and handled downloads client-side via memory Blobs.

Dsurviving the nestjs cutover
▼ DIFF

Running two backends against one app caused auth sync bugs. Migrated the app to the shared NestJS backend in a day - used migrate deploy rather than db push to avoid corrupting nine already-committed database migrations.

PRIVATE REPO. Happy to walk through the code and architecture in an interview.

PROJECTHOSHCARE API (BACKEND)
DRAWN BYBIDYA B. NANDA
STATUSSUPERSEDED JUL 2026