# smart-on-fhir/patient-browser architecture

> Architecture diagram of the GitHub repository smart-on-fhir/patient-browser, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2025-07-11). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/smart-on-fhir/patient-browser
- Repository: https://github.com/smart-on-fhir/patient-browser

## Overview

##### Project type and purpose
- This is a standalone, static single-page application (“patient-browser”) implemented with React and Redux, bundled by Vite, and served as HTML/CSS/JS.
- Its purpose is to allow a host web application (in a popup or iframe on a different domain) to let users browse and select FHIR patients from a remote FHIR server, communicating via postMessage.

##### File structure
- Top-level:
- public/ – static assets (Bootstrap, Font-Awesome, jQuery), prebuilt configs under public/config.
- src/ – React components, Less styles, Redux store modules, lib utilities, TypeScript entry (main.tsx).
- config-genrator/ – Node.js CLI tool that queries a FHIR server, parses metadata/conditions, and produces JSON5 config files.
- test/e2e/ and nightwatch.conf.cjs – end-to-end tests.
- Vite & TypeScript config files, GitHub Actions CI workflow, Dockerignore, Procfile (for deployment).

##### README for additional insights
- App initializes by loading a JSON5 config from public/config based on a URL search parameter.
- It fetches patient resources (and optionally tags/conditions) from an open FHIR server.
- It dispatches Redux actions, renders data via React components, posts “ready”/“result” messages to the opener, and listens for injected config on “ready.”

## Diagram (Mermaid)

```mermaid
flowchart TD
    %% Build & CI Pipeline
    subgraph "CI/CD & Build" 
        direction TB
        VITE["Vite Build (vite.config.ts)"]:::build
        TS["TypeScript Config (tsconfig.json, tsconfig.node.json)"]:::build
        CI["GitHub Actions CI (.github/workflows/CI.yml)"]:::build
        DOCKER["Deployment Config (.dockerignore, Procfile)"]:::build
        VITE -->|bundles| HOSTING
        CI -->|runs lint & tests| VITE
        CI -->|deploy| HOSTING
    end

    %% Offline Tool
    subgraph "Offline Tools" 
        direction TB
        CLI["Config Generator CLI"]:::offline
        CLI -->|fetches metadata| FHIR
        CLI -->|generates JSON5| CONFIGFS
    end

    %% Hosting / CDN
    HOSTING["Static Hosting / CDN (index.html)"]:::build
    CONFIGFS["Config Files (public/config/*.json5)"]:::build
    ASSETS["Static Assets (public/assets)"]:::build
    HOSTING -->|serves| ASSETS
    HOSTING -->|serves| CONFIGFS

    %% External Services
    subgraph "External Services"
        direction TB
        HostApp["Host Application (iframe/popup)"]:::external
        FHIR["FHIR API Servers (DSTU2/STU3/R4)"]:::external
    end

    %% Browser Runtime
    subgraph "Browser Runtime" 
        direction TB
        ENTRY["App Entry (src/main.tsx)"]:::runtime
        Loader["Config Loader (src/config.default.js)"]:::runtime
        PARAMS["Routing & URL Helpers (src/lib/withParams.jsx, src/lib/withRouter.jsx)"]:::runtime
        API["FHIR API Client (src/lib/PatientSearch.js)"]:::runtime
        CONST["API Utilities & Constants (src/lib/constants.js)"]:::runtime
        STORE["Redux Store (src/redux)"]:::runtime
        UI["React UI Components (src/components)"]:::runtime
        COMM["Communication Module (src/lib/index.jsx)"]:::runtime
        STYLES["Less Styles (src/less/variables.less & component .less)"]:::runtime

        ENTRY -->|loads| Loader
        ENTRY -->|bootstraps| STORE
        ENTRY -->|bootstraps| UI
        Loader -->|reads| CONFIGFS
        Loader -->|uses| PARAMS
        STORE -->|holds state| UI
        UI -->|renders| STORE
        UI -->|styled by| STYLES
        API -->|uses| CONST
        STORE -->|dispatches| API
        COMM -->|sends/receives| HostApp
        UI -->|onSelect| COMM
        ENTRY -->|initializes| COMM
    end

    %% Runtime Interactions
    HOSTING -->|loads index.html| ENTRY
    ENTRY -->|AJAX calls| FHIR
    HostApp -->|postMessage ready| COMM
    COMM -->|postMessage result| HostApp

    %% Testing
    subgraph "Testing"
        direction TB
        UNIT["Unit Tests (src/lib/__tests__, src/redux/__tests__)"]:::build
        E2E["E2E Tests (test/e2e, nightwatch.conf.cjs)"]:::build
        CI -->|runs| UNIT
        CI -->|runs| E2E
    end

    %% Click Events
    click UI "https://github.com/smart-on-fhir/patient-browser/tree/master/src/components"
    click STORE "https://github.com/smart-on-fhir/patient-browser/tree/master/src/redux"
    click API "https://github.com/smart-on-fhir/patient-browser/blob/master/src/lib/PatientSearch.js"
    click CONST "https://github.com/smart-on-fhir/patient-browser/blob/master/src/lib/constants.js"
    click ENTRY "https://github.com/smart-on-fhir/patient-browser/blob/master/src/main.tsx"
    click Loader "https://github.com/smart-on-fhir/patient-browser/blob/master/src/config.default.js"
    click PARAMS "https://github.com/smart-on-fhir/patient-browser/blob/master/src/lib/withParams.jsx"
    click PARAMS "https://github.com/smart-on-fhir/patient-browser/blob/master/src/lib/withRouter.jsx"
    click COMM "https://github.com/smart-on-fhir/patient-browser/blob/master/src/lib/index.jsx"
    click STYLES "https://github.com/smart-on-fhir/patient-browser/blob/master/src/less/variables.less"
    click CLI "https://github.com/smart-on-fhir/patient-browser/blob/master/config-genrator/generate_config.js"
    click CONFIGFS "https://github.com/smart-on-fhir/patient-browser/blob/master/public/config/*.json5"
    click ASSETS "https://github.com/smart-on-fhir/patient-browser/tree/master/public/assets"
    click HOSTING "https://github.com/smart-on-fhir/patient-browser/blob/master/index.html"
    click VITE "https://github.com/smart-on-fhir/patient-browser/blob/master/vite.config.ts"
    click TS "https://github.com/smart-on-fhir/patient-browser/blob/master/tsconfig.json"
    click CI "https://github.com/smart-on-fhir/patient-browser/blob/master/.github/workflows/CI.yml"
    click DOCKER "https://github.com/smart-on-fhir/patient-browser/blob/master/.dockerignore"
    click DOCKER "https://github.com/smart-on-fhir/patient-browser/tree/master/Procfile"
    click UNIT "https://github.com/smart-on-fhir/patient-browser/tree/master/src/lib/__tests__"
    click UNIT "https://github.com/smart-on-fhir/patient-browser/tree/master/src/redux/__tests__"
    click E2E "https://github.com/smart-on-fhir/patient-browser/tree/master/test/e2e"
    click E2E "https://github.com/smart-on-fhir/patient-browser/blob/master/nightwatch.conf.cjs"

    %% Styles
    classDef runtime fill:#e0f7e9,stroke:#2f855a,color:#2f855a
    classDef build fill:#e6f0ff,stroke:#3182ce,color:#2b6cb0
    classDef external fill:#fff4e6,stroke:#dd6b20,color:#dd6b20
    classDef offline fill:#f7fafc,stroke:#718096,color:#4a5568
```
