# sg-victorchai/gep-poc architecture

> Architecture diagram of the GitHub repository sg-victorchai/gep-poc, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2025-04-21). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/sg-victorchai/gep-poc
- Repository: https://github.com/sg-victorchai/gep-poc

## Overview

##### Project type and purpose
- This is primarily a React‑based Single Page Application (SPA) that demonstrates HL7 FHIR resource browsing, searching, and CRUD workflows—all scaffolded and enhanced by GitHub Copilot prompts.
- There is no custom backend code in this repo; instead it calls out to an external FHIR server (Synapxe Innovation Sandbox) as its data source.
- The `.copilot` folder holds developer‑time prompt definitions used to generate UI code based on FHIR StructureDefinition, SearchParameter, and OperationDefinition resources.

##### File structure
- Top‑level folders:
– `.copilot` : Markdown prompts used during development to drive codegen
– `fhirprofile` : FHIR StructureDefinition JSON files (metadata that the UI loads to auto‑generate forms and tables)
– `fhirweb-spa` : full React/Vite SPA codebase
- Inside `fhirweb-spa`:
– `src/components` : shared UI components (Header, Footer, badges, etc.)
– `src/pages` : page components mapping to routes (Home, PatientSearch, ObservationPage, CRUD pages, etc.)
– `src/services/fhir/client.ts` : HTTP client for FHIR API calls
– `src/store` : Redux Toolkit setup and slices (authSlice, uiSlice)
– `src/styles` & Tailwind config: CSS setup
– Build & config files: Vite, TSConfig, PostCSS, Vitest
- Deployment contexts: `.env.development` / `.env.example` define the external FHIR server URL and API key.

##### README for additional insights
- The README details a four‑part journey that illustrates how the UI is programmatically generated from FHIR metadata via Copilot
- It clarifies that the runtime system is an SPA calling an external FHIR API, not a monolithic full‑stack with its own backend server
- It confirms reliance on standard FHIR resources—Patient, Observation, CarePlan, MedicationRequest—and custom extensions via StructureDefinition JSON

## Diagram (Mermaid)

```mermaid
flowchart TD
    %% Developer Tools
    subgraph "Developer Tools"    
        DevEnv["Developer Env + GitHub Copilot"]:::dev
        CopilotPrompts["Copilot Prompt Definitions"]:::dev
    end
    DevEnv -->|uses prompts| CopilotPrompts

    %% FHIR Metadata
    subgraph "FHIR Metadata"    
        ProfileDir["fhirprofile/"]:::meta
        SDObs["structure-definition-observation.json"]:::meta
        SDCarePlan["structure-definitions-careplan.json"]:::meta
        SDEncounter["structure-defition-encounter.json"]:::meta
    end
    ProfileDir --> SDObs
    ProfileDir --> SDCarePlan
    ProfileDir --> SDEncounter

    %% External FHIR Server
    ExternalFHIR["Synapxe Innovation Sandbox (FHIR Server)"]:::server

    %% Frontend SPA
    subgraph "React SPA (fhirweb-spa/)"    
        %% Entry & Config
        subgraph "Entry & Config"    
            IndexHTML["index.html"]:::frontend
            MainTSX["src/main.tsx"]:::frontend
            AppTSX["src/App.tsx"]:::frontend
            ViteConfig["vite.config.ts"]:::frontend
            TSConfig["tsconfig.json"]:::frontend
            PostCSS["postcss.config.js"]:::frontend
            TailwindConfig["tailwind.config.js"]:::frontend
        end
        %% UI Components
        subgraph "UI Components"    
            Header["Header.tsx"]:::frontend
            Footer["Footer.tsx"]:::frontend
        end
        %% Pages & Routes
        subgraph "Pages & Routes"    
            HomePage["HomePage.tsx"]:::frontend
            PatientSearch["PatientSearchPage.tsx"]:::frontend
            PatientPage["PatientPage.tsx"]:::frontend
            ObservationPage["ObservationPage.tsx"]:::frontend
            CarePlanPage["CarePlanPage.tsx"]:::frontend
            EncounterPage["EncounterPage.tsx"]:::frontend
            MedicationRequestPage["MedicationRequestPage.tsx"]:::frontend
            LaunchPage["LaunchPage.tsx"]:::frontend
            NotFound["NotFound.tsx"]:::frontend
            ObservationCrud["ObservationCrudPage.tsx"]:::frontend
            CarePlanCrud["CarePlanCrudPage.tsx"]:::frontend
            EncounterCrud["EncounterCrudPage.tsx"]:::frontend
            MedicationRequestCrud["MedicationRequestCrudPage.tsx"]:::frontend
            Routes["routes.tsx"]:::frontend
        end
        %% Service Layer
        subgraph "FHIR Service Layer"    
            FHIRClient["client.ts"]:::frontend
        end
        %% State Management
        subgraph "State Management"    
            StoreIndex["index.ts"]:::frontend
            AuthSlice["authSlice.ts"]:::frontend
            UiSlice["uiSlice.ts"]:::frontend
        end
        %% Styling & Env
        subgraph "Styling & Env"    
            Styles["index.css"]:::frontend
            EnvDev[".env.development"]:::frontend
            EnvExample[".env.example"]:::frontend
        end
    end

    %% Browser/User
    Browser["Browser / End User"]:::user

    %% Flows
    Browser -->|loads SPA assets| IndexHTML
    IndexHTML --> MainTSX
    MainTSX --> AppTSX
    AppTSX -->|dispatch actions| StoreIndex
    AppTSX -->|renders UI| Header
    AppTSX -->|renders pages| HomePage
    AppTSX --> Routes

    AppTSX -->|fetch profiles| ProfileDir
    FHIRClient -->|HTTP calls| ExternalFHIR
    ExternalFHIR -->|FHIR responses| FHIRClient
    StoreIndex --> AuthSlice
    StoreIndex --> UiSlice
    StoreIndex -->|updates state| AppTSX

    CopilotPrompts -->|scaffolds code into| IndexHTML

    %% Click Events for component mapping
    click DevEnv "https://github.com/sg-victorchai/gep-poc/tree/main/.copilot/"
    click CopilotPrompts "https://github.com/sg-victorchai/gep-poc/blob/main/.copilot/FHIRResourceUIDevGuide.md"
    click CopilotPrompts "https://github.com/sg-victorchai/gep-poc/blob/main/.copilot/ObservationUiGuide.md"
    click CopilotPrompts "https://github.com/sg-victorchai/gep-poc/blob/main/.copilot/fhir-typescript-spa-prompt.md"
    click ProfileDir "https://github.com/sg-victorchai/gep-poc/tree/main/fhirprofile/"
    click SDObs "https://github.com/sg-victorchai/gep-poc/blob/main/fhirprofile/structure-definition-observation.json"
    click SDCarePlan "https://github.com/sg-victorchai/gep-poc/blob/main/fhirprofile/structure-definitions-careplan.json"
    click SDEncounter "https://github.com/sg-victorchai/gep-poc/blob/main/fhirprofile/structure-defition-encounter.json"
    click IndexHTML "https://github.com/sg-victorchai/gep-poc/blob/main/fhirweb-spa/index.html"
    click MainTSX "https://github.com/sg-victorchai/gep-poc/blob/main/fhirweb-spa/src/main.tsx"
    click AppTSX "https://github.com/sg-victorchai/gep-poc/blob/main/fhirweb-spa/src/App.tsx"
    click ViteConfig "https://github.com/sg-victorchai/gep-poc/blob/main/fhirweb-spa/vite.config.ts"
    click TSConfig "https://github.com/sg-victorchai/gep-poc/blob/main/fhirweb-spa/tsconfig.json"
    click PostCSS "https://github.com/sg-victorchai/gep-poc/blob/main/fhirweb-spa/postcss.config.js"
    click TailwindConfig "https://github.com/sg-victorchai/gep-poc/blob/main/fhirweb-spa/tailwind.config.js"
    click Header "https://github.com/sg-victorchai/gep-poc/blob/main/fhirweb-spa/src/components/common/Header.tsx"
    click Footer "https://github.com/sg-victorchai/gep-poc/blob/main/fhirweb-spa/src/components/common/Footer.tsx"
    click HomePage "https://github.com/sg-victorchai/gep-poc/blob/main/fhirweb-spa/src/pages/HomePage.tsx"
    click PatientSearch "https://github.com/sg-victorchai/gep-poc/blob/main/fhirweb-spa/src/pages/PatientSearchPage.tsx"
    click PatientPage "https://github.com/sg-victorchai/gep-poc/blob/main/fhirweb-spa/src/pages/PatientPage.tsx"
    click ObservationPage "https://github.com/sg-victorchai/gep-poc/blob/main/fhirweb-spa/src/pages/ObservationPage.tsx"
    click CarePlanPage "https://github.com/sg-victorchai/gep-poc/blob/main/fhirweb-spa/src/pages/CarePlanPage.tsx"
    click EncounterPage "https://github.com/sg-victorchai/gep-poc/blob/main/fhirweb-spa/src/pages/EncounterPage.tsx"
    click MedicationRequestPage "https://github.com/sg-victorchai/gep-poc/blob/main/fhirweb-spa/src/pages/MedicationRequestPage.tsx"
    click LaunchPage "https://github.com/sg-victorchai/gep-poc/blob/main/fhirweb-spa/src/pages/LaunchPage.tsx"
    click NotFound "https://github.com/sg-victorchai/gep-poc/blob/main/fhirweb-spa/src/pages/NotFound.tsx"
    click ObservationCrud "https://github.com/sg-victorchai/gep-poc/blob/main/fhirweb-spa/src/pages/crud/ObservationCrudPage.tsx"
    click CarePlanCrud "https://github.com/sg-victorchai/gep-poc/blob/main/fhirweb-spa/src/pages/crud/CarePlanCrudPage.tsx"
    click EncounterCrud "https://github.com/sg-victorchai/gep-poc/blob/main/fhirweb-spa/src/pages/crud/EncounterCrudPage.tsx"
    click MedicationRequestCrud "https://github.com/sg-victorchai/gep-poc/blob/main/fhirweb-spa/src/pages/crud/MedicationRequestCrudPage.tsx"
    click Routes "https://github.com/sg-victorchai/gep-poc/blob/main/fhirweb-spa/src/routes.tsx"
    click FHIRClient "https://github.com/sg-victorchai/gep-poc/blob/main/fhirweb-spa/src/services/fhir/client.ts"
    click StoreIndex "https://github.com/sg-victorchai/gep-poc/blob/main/fhirweb-spa/src/store/index.ts"
    click AuthSlice "https://github.com/sg-victorchai/gep-poc/blob/main/fhirweb-spa/src/store/slices/authSlice.ts"
    click UiSlice "https://github.com/sg-victorchai/gep-poc/blob/main/fhirweb-spa/src/store/slices/uiSlice.ts"
    click Styles "https://github.com/sg-victorchai/gep-poc/blob/main/fhirweb-spa/src/styles/index.css"
    click EnvDev "https://github.com/sg-victorchai/gep-poc/blob/main/fhirweb-spa/.env.development"
    click EnvExample "https://github.com/sg-victorchai/gep-poc/blob/main/fhirweb-spa/.env.example"

    %% Styles
    classDef dev fill:#cccccc,stroke:#333,stroke-width:1px;
    classDef meta fill:#ccffcc,stroke:#333,stroke-width:1px;
    classDef frontend fill:#cce5ff,stroke:#333,stroke-width:1px;
    classDef server fill:#ffcc99,stroke:#333,stroke-width:1px;
    classDef user fill:#eeeeee,stroke:#333,stroke-width:1px;
```
