# ahmedinternist/rx-v2 architecture

> Architecture diagram of the GitHub repository ahmedinternist/rx-v2, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2026-11-10). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/ahmedinternist/rx-v2
- Repository: https://github.com/ahmedinternist/rx-v2

## Overview

Rx-v2 is a shareable prescription viewer. An API client submits prescription JSON; the API authorizes the request, stores it in Redis with a 60-day expiry, and returns a viewer link. The viewer retrieves the record by ID, formats prescription and medication details, and renders the result with localized text and interactive medication rows. The README gives little product detail, so the graph follows the sampled runtime code; the normalizer is included as a separate helper because its use is not shown.

Main entry points: [`app/p/[id]/page.tsx`](https://github.com/ahmedinternist/rx-v2/blob/main/app/p/%5Bid%5D/page.tsx) (Prescription page), [`app/api/rx/route.ts`](https://github.com/ahmedinternist/rx-v2/blob/main/app/api/rx/route.ts) (Prescription API), [`app/page.tsx`](https://github.com/ahmedinternist/rx-v2/blob/main/app/page.tsx) (Share instructions), [`app/lib/rx-presentation.ts`](https://github.com/ahmedinternist/rx-v2/blob/main/app/lib/rx-presentation.ts) (Medication formatting)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_sharing["Prescription sharing"]
  node_rx_api["Prescription API<br/>[route.ts]"]
  node_redis[("Upstash Redis")]
  node_home["Share instructions<br/>[page.tsx]"]
end

subgraph group_viewer["Prescription viewer"]
  node_prescription_page["Prescription page<br/>[page.tsx]"]
  node_normalizer["Record normalizer<br/>[rx-normalizer.ts]"]
end

subgraph group_presentation["Display and recovery"]
  node_presentation_helpers["Medication formatting<br/>[rx-presentation.ts]"]
  node_medication_item["Medication row"]
  node_localized_text["Script annotation<br/>[localized-text.tsx]"]
  node_error_state["Load error state<br/>[error.tsx]"]
  node_missing_state["Unavailable state<br/>[not-found.tsx]"]
  node_layout["Application layout<br/>[layout.tsx]"]
end

node_api_client(("API client"))
node_viewer_user(("Viewer user"))

node_api_client -->|"submits JSON"| node_rx_api
node_rx_api -->|"stores and checks"| node_redis
node_rx_api -->|"returns viewer link"| node_api_client
node_viewer_user -->|"opens link"| node_prescription_page
node_prescription_page -->|"loads record"| node_redis
node_prescription_page -->|"formats details"| node_presentation_helpers
node_prescription_page -->|"renders rows"| node_medication_item
node_prescription_page -->|"renders annotated text"| node_localized_text
node_prescription_page -.->|"shows load failure"| node_error_state
node_prescription_page -->|"shows missing record"| node_missing_state
node_home -->|"describes submission"| node_api_client

click node_rx_api "https://github.com/ahmedinternist/rx-v2/blob/main/app/api/rx/route.ts"
click node_home "https://github.com/ahmedinternist/rx-v2/blob/main/app/page.tsx"
click node_prescription_page "https://github.com/ahmedinternist/rx-v2/blob/main/app/p/%5Bid%5D/page.tsx"
click node_normalizer "https://github.com/ahmedinternist/rx-v2/blob/main/app/lib/rx-normalizer.ts"
click node_presentation_helpers "https://github.com/ahmedinternist/rx-v2/blob/main/app/lib/rx-presentation.ts"
click node_medication_item "https://github.com/ahmedinternist/rx-v2/blob/main/app/p/%5Bid%5D/medication-item.tsx"
click node_localized_text "https://github.com/ahmedinternist/rx-v2/blob/main/app/p/%5Bid%5D/localized-text.tsx"
click node_error_state "https://github.com/ahmedinternist/rx-v2/blob/main/app/p/%5Bid%5D/error.tsx"
click node_missing_state "https://github.com/ahmedinternist/rx-v2/blob/main/app/p/%5Bid%5D/not-found.tsx"
click node_layout "https://github.com/ahmedinternist/rx-v2/blob/main/app/layout.tsx"

classDef toneNeutral fill:#f8fafc,stroke:#334155,stroke-width:1.5px,color:#0f172a
classDef toneBlue fill:#dbeafe,stroke:#2563eb,stroke-width:1.5px,color:#172554
classDef toneAmber fill:#fef3c7,stroke:#d97706,stroke-width:1.5px,color:#78350f
classDef toneMint fill:#dcfce7,stroke:#16a34a,stroke-width:1.5px,color:#14532d
classDef toneRose fill:#ffe4e6,stroke:#e11d48,stroke-width:1.5px,color:#881337
classDef toneIndigo fill:#e0e7ff,stroke:#4f46e5,stroke-width:1.5px,color:#312e81
classDef toneTeal fill:#ccfbf1,stroke:#0f766e,stroke-width:1.5px,color:#134e4a
class node_rx_api,node_redis,node_home,node_api_client,node_viewer_user toneBlue
class node_prescription_page,node_normalizer toneAmber
class node_presentation_helpers,node_medication_item,node_localized_text,node_error_state,node_missing_state,node_layout toneMint
```

## Components

### Prescription sharing

- [Prescription API](https://github.com/ahmedinternist/rx-v2/blob/main/app/api/rx/route.ts): `app/api/rx/route.ts`
- **Upstash Redis**
- [Share instructions](https://github.com/ahmedinternist/rx-v2/blob/main/app/page.tsx): `app/page.tsx`

### Prescription viewer

- [Prescription page](https://github.com/ahmedinternist/rx-v2/blob/main/app/p/%5Bid%5D/page.tsx): `app/p/[id]/page.tsx`
- [Record normalizer](https://github.com/ahmedinternist/rx-v2/blob/main/app/lib/rx-normalizer.ts): `app/lib/rx-normalizer.ts`

### Display and recovery

- [Medication formatting](https://github.com/ahmedinternist/rx-v2/blob/main/app/lib/rx-presentation.ts): `app/lib/rx-presentation.ts`
- [Medication row](https://github.com/ahmedinternist/rx-v2/blob/main/app/p/%5Bid%5D/medication-item.tsx): `app/p/[id]/medication-item.tsx`
- [Script annotation](https://github.com/ahmedinternist/rx-v2/blob/main/app/p/%5Bid%5D/localized-text.tsx): `app/p/[id]/localized-text.tsx`
- [Load error state](https://github.com/ahmedinternist/rx-v2/blob/main/app/p/%5Bid%5D/error.tsx): `app/p/[id]/error.tsx`
- [Unavailable state](https://github.com/ahmedinternist/rx-v2/blob/main/app/p/%5Bid%5D/not-found.tsx): `app/p/[id]/not-found.tsx`
- [Application layout](https://github.com/ahmedinternist/rx-v2/blob/main/app/layout.tsx): `app/layout.tsx`

### Other components

- **API client**
- **Viewer user**

## Connections

- API client → Prescription API: submits JSON
- Prescription API → Upstash Redis: stores and checks (evidence: `app/api/rx/route.ts`)
- Prescription API → API client: returns viewer link (evidence: `app/api/rx/route.ts`)
- Viewer user → Prescription page: opens link (evidence: `app/p/[id]/page.tsx`)
- Prescription page → Upstash Redis: loads record (evidence: `app/p/[id]/page.tsx`)
- Prescription page → Medication formatting: formats details (evidence: `app/p/[id]/page.tsx`)
- Prescription page → Medication row: renders rows (evidence: `app/p/[id]/page.tsx`)
- Prescription page → Script annotation: renders annotated text (evidence: `app/p/[id]/page.tsx`)
- Prescription page → Load error state: shows load failure
- Prescription page → Unavailable state: shows missing record (evidence: `app/p/[id]/page.tsx`)
- Share instructions → API client: describes submission (evidence: `app/page.tsx`)
