%% Data Ecosystem Diagram for NIPH DSP
%% Render with Mermaid (https://mermaid.js.org/)

flowchart LR
    subgraph Clients
        U1[Public/Authenticated Users]
        U2[DAC Staff]
    end

    subgraph WebTier[PHP + Apache (dsp_app)]
        UI[Portal UI<br/>Dashboards & Workflows]
        API[PHP APIs<br/>Uploads & R runners]
    end

    subgraph Database[(MySQL 8.0<br/>dsp_db)]
        DS[(dsps_tbl_datasource)]
        PERM[(dsps_tbl_datasource_permission)]
        PEOPLE[(ist_tbl_people & ist_tbl_users)]
        USAGE[(dsps_tbl_datasource_used)]
    end

    subgraph Storage[/Shared Volumes/]
        FILES[(uploads/datasources)]
        RSCRIPTS[(r_scripts)]
        JWS[(uploads/jupyter_workspace)]
    end

    subgraph Tooling
        PMA[phpMyAdmin<br/>dsp_phpmyadmin]
        JUP[Jupyter (R kernel)<br/>dsp_jupyter]
    end

    U1 -->|HTTPS :8082| UI
    U2 -->|HTTPS :8082| UI
    U2 -->|Admin Ops| PMA

    UI --> API
    API -->|SQL queries| Database
    PMA -->|SQL admin| Database

    API -->|File uploads/downloads| FILES
    API -->|Sync approved files| JWS
    API -->|Whitelisted scripts| RSCRIPTS

    JUP -->|Mounts| FILES
    JUP -->|Mounts| RSCRIPTS
    JUP -->|Per-user workspace| JWS
    JUP -->|Notebook insights| U1

    Database -->|Metadata feeds| UI
    Database -->|Permission checks| API
    Database -->|Audit logs| DAC[DAC Reports]

    style DAC fill:#f7f9fb,stroke:#93a1c3,stroke-width:1px
