# teresebo/orpha_table architecture

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

- Interactive diagram: https://gitdiagram.com/teresebo/orpha_table
- Repository: https://github.com/teresebo/orpha_table

## Overview

##### Project Type and Purpose
- This is a full-stack, single-page Next.js (React) application for building and exporting custom lists of rare diseases (ORPHAcode, ICD-10, names, synonyms) by querying the Orphanet API.
- The app uses Next.js App Router (app/ directory), server-side API routes for proxying external API requests, a React-based frontend for search and table interactions, and in-browser state management (Zustand).

##### File Structure Analysis
- Top-level assets and settings:
- next.config.mjs, postcss.config.mjs, tailwind.config.js — build & styling configuration
- .eslintrc.json, jest.config.js, jsconfig.json — lint, test, and editor settings
- .github/workflows — CI configuration
- app/ directory (Next.js App Router):
- app/layout.js, app/page.jsx — overall layout and home page
- app/globals.css — global styles
- app/api/* — serverless route handlers (icd10, name, orphacode) and shared utils
- components/ directory:
- searchbox.jsx — search input UI
- result/* — results table UI, action buttons
- selection/* — selected items table, export schema
- ui/* — generic UI primitives (Button, Input, Table, DataTable)
- zustandstore/: state management hooks (e.g., orphastore.js)
- lib/ and utils/: shared utility functions (date formatting, API helpers)
- __tests__ and __testutils__: testing infrastructure for components and pages

##### README Insights
- Confirms Next.js usage, reliance on ORPHA_API_KEY (via .env)
- Describes user flow: search → display results → select/remove → export JSON/Excel

a. Main Components
- Client Browser (React UI in Next.js)
- Next.js Server (App Router + API Routes)
- External Orphanet REST API
- In-Browser State Store (Zustand)
- Export Module (JSON/Excel generator)
- Configuration (.env for ORPHA_API_KEY)
b. Relationships & Data Flow
1. User enters search in Browser → React SearchBox → triggers fetch() to Next.js API route
2. Next.js API Route (e.g., /api/icd10/[term])
→ reads ORPHA_API_KEY
→ proxies request to Orphanet API
→ receives JSON response → returns to client
3. React UI receives response → renders ResultsTable (components/result)
4. User selects items → dispatch to Zustand store → updates SelectionTable
5. User triggers export → ExportModule reads state → generates file (JSON or Excel) → browser download
c. Architectural Patterns
- Serverless Functions: API routes as thin proxies to external API
- Component-based UI (atomic components in components/ui)
- State management via Zustand (global store decoupled from component tree)
- Separation of concerns: UI → state → API → external services
d. Key Technologies
- Next.js 13 (App Router)
- React + JSX
- Tailwind CSS (styling)
- Zustand (state management)
- Node.js serverless functions (API handlers)
- Excel generation library (via schema in components/selection/excelschema)

## Diagram (Mermaid)

```mermaid
flowchart TD
    %% Frontend Layer
    subgraph "Frontend Browser"
        direction TB
        SearchBox["SearchBox"]:::frontend
        ResultsTable["ResultsTable"]:::frontend
        ResultsColumns["Results Columns"]:::frontend
        ActionButtons["Action Buttons"]:::frontend
        SelectionTable["SelectionTable"]:::frontend
        SelectionColumns["Selection Columns"]:::frontend
        RemoveButton["Remove Button"]:::frontend
        ExportModule["Export Module (JSON/Excel)"]:::frontend
        ZustandStore["Zustand Store"]:::state
    end

    %% Backend Layer
    subgraph "Next.js Server"
        direction TB
        APIUtils["Shared API Utils"]:::backend
        subgraph "API Routes (Serverless)"
            direction TB
            ICDEntry["/api/icd10.js"]:::backend
            ICDDynamic["/api/icd10/[term]/route.js"]:::backend
            NameEntry["/api/name.js"]:::backend
            NameDynamic["/api/name/[term]/route.js"]:::backend
            OrphaEntry["/api/orphacode.js"]:::backend
            OrphaDynamic["/api/orphacode/[term]/route.js"]:::backend
        end
    end

    %% External Service
    OrphanetAPI["Orphanet REST API"]:::external

    %% Configuration
    EnvConfig[".env (ORPHA_API_KEY)"]:::config

    %% Connections
    SearchBox -->|"fetch search"| ICDEntry
    SearchBox --> ICDDynamic
    ICDEntry -->|uses| APIUtils
    ICDDynamic -->|uses| APIUtils
    NameEntry -->|uses| APIUtils
    NameDynamic -->|uses| APIUtils
    OrphaEntry -->|uses| APIUtils
    OrphaDynamic -->|uses| APIUtils

    ICDEntry -->|"proxy request"| OrphanetAPI
    ICDDynamic -->|"proxy request"| OrphanetAPI
    NameEntry -->|"proxy request"| OrphanetAPI
    NameDynamic -->|"proxy request"| OrphanetAPI
    OrphaEntry -->|"proxy request"| OrphanetAPI
    OrphaDynamic -->|"proxy request"| OrphanetAPI

    OrphanetAPI -->|"JSON response"| ResultsTable
    ResultsTable --> ResultsColumns
    ResultsTable --> ActionButtons

    ActionButtons -->|select item| ZustandStore
    ResultsTable -->|select item| ZustandStore
    ZustandStore --> SelectionTable
    SelectionTable --> SelectionColumns
    SelectionTable --> RemoveButton

    SelectionTable --> ExportModule
    ExportModule -->|"download JSON/Excel"| BrowserDownloads["Browser Download"]:::external

    EnvConfig -->|provides key| APIUtils

    %% Click Events
    click SearchBox "https://github.com/teresebo/orpha_table/blob/master/components/searchbox.jsx"
    click ResultsTable "https://github.com/teresebo/orpha_table/blob/master/components/result/resultstable.jsx"
    click ResultsColumns "https://github.com/teresebo/orpha_table/blob/master/components/result/columns.jsx"
    click ActionButtons "https://github.com/teresebo/orpha_table/blob/master/components/result/actionbuttons.jsx"
    click SelectionTable "https://github.com/teresebo/orpha_table/blob/master/components/selection/selectiontable.jsx"
    click SelectionColumns "https://github.com/teresebo/orpha_table/blob/master/components/selection/columns.jsx"
    click RemoveButton "https://github.com/teresebo/orpha_table/blob/master/components/selection/removebutton.jsx"
    click ExportModule "https://github.com/teresebo/orpha_table/blob/master/components/selection/excelschema/schema.js"
    click ZustandStore "https://github.com/teresebo/orpha_table/blob/master/zustandstore/orphastore.js"
    click APIUtils "https://github.com/teresebo/orpha_table/blob/master/app/api/utils.js"
    click ICDEntry "https://github.com/teresebo/orpha_table/blob/master/app/api/icd10.js"
    click ICDDynamic "https://github.com/teresebo/orpha_table/blob/master/app/api/icd10/[term]/route.js"
    click NameEntry "https://github.com/teresebo/orpha_table/blob/master/app/api/name.js"
    click NameDynamic "https://github.com/teresebo/orpha_table/blob/master/app/api/name/[term]/route.js"
    click OrphaEntry "https://github.com/teresebo/orpha_table/blob/master/app/api/orphacode.js"
    click OrphaDynamic "https://github.com/teresebo/orpha_table/blob/master/app/api/orphacode/[term]/route.js"
    click EnvConfig "https://github.com/teresebo/orpha_table/blob/master/.env"

    %% Styles
    classDef frontend fill:#cce5ff,stroke:#004085,color:#004085;
    classDef backend fill:#d4edda,stroke:#155724,color:#155724;
    classDef external fill:#e2e3e5,stroke:#6c757d,color:#383d41;
    classDef config fill:#fff3cd,stroke:#856404,color:#856404;
    classDef state fill:#fef7e0,stroke:#8a6d3b,color:#8a6d3b;
```
