# atharvakatre/pharmsight-forecast architecture

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

- Interactive diagram: https://gitdiagram.com/atharvakatre/pharmsight-forecast
- Repository: https://github.com/atharvakatre/pharmsight-forecast

## Overview

PharmSight is a web app for forecasting ten years of drug revenue across editable scenarios. Forecasters enter or import year-by-year funnel assumptions, then review patient and revenue results, compare scenarios, export CSVs, and save immutable workspace snapshots; Brand Leads can review and comment. The React UI calls a FastAPI backend, whose scenario services persist inputs and invoke the Decimal forecast engine; PostgreSQL stores scenarios, versions, and comments. The graph includes documented versioning and dashboard capabilities, though some of their backend implementation was not excerpted.

Main entry points: [`frontend/src/api/client.ts`](https://github.com/atharvakatre/pharmsight-forecast/blob/main/frontend/src/api/client.ts) (API client), [`frontend/src/routes.tsx`](https://github.com/atharvakatre/pharmsight-forecast/blob/main/frontend/src/routes.tsx) (Feature routing), [`frontend/src/features/scenarios/ScenarioEditor.tsx`](https://github.com/atharvakatre/pharmsight-forecast/blob/main/frontend/src/features/scenarios/ScenarioEditor.tsx) (Scenario editing), [`backend/app/services/scenarios.py`](https://github.com/atharvakatre/pharmsight-forecast/blob/main/backend/app/services/scenarios.py) (Scenario service)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_client["Web client"]
  node_routes["Feature routing<br/>[routes.tsx]"]
  node_login["Login<br/>[LoginPage.tsx]"]
  node_authstate["Session state<br/>[AuthContext.tsx]"]
  node_apiclient["API client<br/>[client.ts]"]
  node_workspace["Workspace state"]
  node_scenarioeditor["Scenario editing<br/>[ScenarioEditor.tsx]"]
  node_inputgrid["Assumption grid<br/>[InputGrid.tsx]"]
  node_csvinputs["CSV input import<br/>[csvInputs.ts]"]
  node_dashboard["Forecast dashboard<br/>[DashboardPage.tsx]"]
  node_versionsui["Version history<br/>[VersionsPage.tsx]"]
  node_versiondetail["Snapshot review"]
end

subgraph group_api["API and access"]
  node_authroutes["Authentication routes<br/>[auth.py]"]
  node_scenarioroutes["Scenario routes<br/>[scenarios.py]"]
  node_versionroutes["Version and comment routes<br/>[versions.py]"]
  node_access["Identity and permissions<br/>[deps.py]"]
  node_authservice["Credential service<br/>[auth.py]"]
end

subgraph group_forecast["Forecast domain"]
  node_scenario_service["Scenario service<br/>[scenarios.py]"]
  node_version_service["Version service<br/>[versions.py]"]
  node_engine["Forecast calculations<br/>[engine.py]"]
  node_forecast_models["Forecast models<br/>[models.py]"]
end

subgraph group_persistence["Workspace data"]
  node_orm["Workspace records<br/>[db_models.py]"]
  node_database["Database sessions<br/>[database.py]"]
  node_postgres[("PostgreSQL")]
end

node_user(("Forecaster / Brand Lead"))

node_user -->|"uses"| node_routes
node_routes -->|"routes to"| node_login
node_routes -->|"routes to"| node_dashboard
node_routes -->|"routes to"| node_scenarioeditor
node_routes -->|"routes to"| node_versionsui
node_login -->|"uses session"| node_authstate
node_authstate -->|"sets token"| node_apiclient
node_scenarioeditor -->|"renders"| node_inputgrid
node_scenarioeditor -->|"imports CSV"| node_csvinputs
node_scenarioeditor -->|"uses state"| node_workspace
node_dashboard -->|"uses scenarios"| node_workspace
node_versionsui -.->|"shows detail"| node_versiondetail
node_login -->|"calls API"| node_apiclient
node_workspace -->|"calls API"| node_apiclient
node_dashboard -->|"requests data"| node_apiclient
node_scenarioeditor -->|"requests data"| node_apiclient
node_versiondetail -->|"requests data"| node_apiclient
node_apiclient -->|"HTTP API"| node_authroutes
node_apiclient -->|"HTTP API"| node_scenarioroutes
node_apiclient -->|"HTTP API"| node_versionroutes
node_authroutes -->|"authenticates via"| node_authservice
node_authroutes -->|"uses identity"| node_access
node_scenarioroutes -->|"checks access"| node_access
node_scenarioroutes -->|"delegates to"| node_scenario_service
node_versionroutes -->|"delegates to"| node_version_service
node_authservice -->|"reads users"| node_orm
node_authservice -.->|"verifies passwords"| node_access
node_scenario_service -->|"persists scenarios"| node_orm
node_scenario_service -->|"calculates forecasts"| node_engine
node_scenario_service -->|"builds inputs"| node_forecast_models
node_version_service -->|"loads scenarios"| node_scenario_service
node_version_service -->|"calculates snapshots"| node_engine
node_version_service -->|"stores snapshots/comments"| node_orm
node_engine -->|"uses models"| node_forecast_models
node_orm -->|"uses base"| node_database
node_database -->|"connects"| node_postgres

click node_routes "https://github.com/atharvakatre/pharmsight-forecast/blob/main/frontend/src/routes.tsx"
click node_login "https://github.com/atharvakatre/pharmsight-forecast/blob/main/frontend/src/features/login/LoginPage.tsx"
click node_authstate "https://github.com/atharvakatre/pharmsight-forecast/blob/main/frontend/src/auth/AuthContext.tsx"
click node_apiclient "https://github.com/atharvakatre/pharmsight-forecast/blob/main/frontend/src/api/client.ts"
click node_workspace "https://github.com/atharvakatre/pharmsight-forecast/blob/main/frontend/src/workspace/WorkspaceContext.tsx"
click node_scenarioeditor "https://github.com/atharvakatre/pharmsight-forecast/blob/main/frontend/src/features/scenarios/ScenarioEditor.tsx"
click node_inputgrid "https://github.com/atharvakatre/pharmsight-forecast/blob/main/frontend/src/features/scenarios/InputGrid.tsx"
click node_csvinputs "https://github.com/atharvakatre/pharmsight-forecast/blob/main/frontend/src/features/scenarios/csvInputs.ts"
click node_dashboard "https://github.com/atharvakatre/pharmsight-forecast/blob/main/frontend/src/features/dashboard/DashboardPage.tsx"
click node_versionsui "https://github.com/atharvakatre/pharmsight-forecast/blob/main/frontend/src/features/versions/VersionsPage.tsx"
click node_versiondetail "https://github.com/atharvakatre/pharmsight-forecast/blob/main/frontend/src/features/versions/VersionDetailView.tsx"
click node_authroutes "https://github.com/atharvakatre/pharmsight-forecast/blob/main/backend/app/api/auth.py"
click node_scenarioroutes "https://github.com/atharvakatre/pharmsight-forecast/blob/main/backend/app/api/scenarios.py"
click node_versionroutes "https://github.com/atharvakatre/pharmsight-forecast/blob/main/backend/app/api/versions.py"
click node_access "https://github.com/atharvakatre/pharmsight-forecast/blob/main/backend/app/api/deps.py"
click node_authservice "https://github.com/atharvakatre/pharmsight-forecast/blob/main/backend/app/services/auth.py"
click node_scenario_service "https://github.com/atharvakatre/pharmsight-forecast/blob/main/backend/app/services/scenarios.py"
click node_version_service "https://github.com/atharvakatre/pharmsight-forecast/blob/main/backend/app/services/versions.py"
click node_engine "https://github.com/atharvakatre/pharmsight-forecast/blob/main/backend/app/forecast/engine.py"
click node_forecast_models "https://github.com/atharvakatre/pharmsight-forecast/blob/main/backend/app/forecast/models.py"
click node_orm "https://github.com/atharvakatre/pharmsight-forecast/blob/main/backend/app/db_models.py"
click node_database "https://github.com/atharvakatre/pharmsight-forecast/blob/main/backend/app/database.py"

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_routes,node_login,node_authstate,node_apiclient,node_workspace,node_scenarioeditor,node_inputgrid,node_csvinputs,node_dashboard,node_versionsui,node_versiondetail toneBlue
class node_authroutes,node_scenarioroutes,node_versionroutes,node_access,node_authservice toneAmber
class node_scenario_service,node_version_service,node_engine,node_forecast_models toneMint
class node_orm,node_database,node_postgres toneRose
class node_user toneIndigo
```

## Components

### Web client

- [Feature routing](https://github.com/atharvakatre/pharmsight-forecast/blob/main/frontend/src/routes.tsx): `frontend/src/routes.tsx`
- [Login](https://github.com/atharvakatre/pharmsight-forecast/blob/main/frontend/src/features/login/LoginPage.tsx): `frontend/src/features/login/LoginPage.tsx`
- [Session state](https://github.com/atharvakatre/pharmsight-forecast/blob/main/frontend/src/auth/AuthContext.tsx): `frontend/src/auth/AuthContext.tsx`
- [API client](https://github.com/atharvakatre/pharmsight-forecast/blob/main/frontend/src/api/client.ts): `frontend/src/api/client.ts`
- [Workspace state](https://github.com/atharvakatre/pharmsight-forecast/blob/main/frontend/src/workspace/WorkspaceContext.tsx): `frontend/src/workspace/WorkspaceContext.tsx`
- [Scenario editing](https://github.com/atharvakatre/pharmsight-forecast/blob/main/frontend/src/features/scenarios/ScenarioEditor.tsx): `frontend/src/features/scenarios/ScenarioEditor.tsx`
- [Assumption grid](https://github.com/atharvakatre/pharmsight-forecast/blob/main/frontend/src/features/scenarios/InputGrid.tsx): `frontend/src/features/scenarios/InputGrid.tsx`
- [CSV input import](https://github.com/atharvakatre/pharmsight-forecast/blob/main/frontend/src/features/scenarios/csvInputs.ts): `frontend/src/features/scenarios/csvInputs.ts`
- [Forecast dashboard](https://github.com/atharvakatre/pharmsight-forecast/blob/main/frontend/src/features/dashboard/DashboardPage.tsx): `frontend/src/features/dashboard/DashboardPage.tsx`
- [Version history](https://github.com/atharvakatre/pharmsight-forecast/blob/main/frontend/src/features/versions/VersionsPage.tsx): `frontend/src/features/versions/VersionsPage.tsx`
- [Snapshot review](https://github.com/atharvakatre/pharmsight-forecast/blob/main/frontend/src/features/versions/VersionDetailView.tsx): `frontend/src/features/versions/VersionDetailView.tsx`

### API and access

- [Authentication routes](https://github.com/atharvakatre/pharmsight-forecast/blob/main/backend/app/api/auth.py): `backend/app/api/auth.py`
- [Scenario routes](https://github.com/atharvakatre/pharmsight-forecast/blob/main/backend/app/api/scenarios.py): `backend/app/api/scenarios.py`
- [Version and comment routes](https://github.com/atharvakatre/pharmsight-forecast/blob/main/backend/app/api/versions.py): `backend/app/api/versions.py`
- [Identity and permissions](https://github.com/atharvakatre/pharmsight-forecast/blob/main/backend/app/api/deps.py): `backend/app/api/deps.py`
- [Credential service](https://github.com/atharvakatre/pharmsight-forecast/blob/main/backend/app/services/auth.py): `backend/app/services/auth.py`

### Forecast domain

- [Scenario service](https://github.com/atharvakatre/pharmsight-forecast/blob/main/backend/app/services/scenarios.py): `backend/app/services/scenarios.py`
- [Version service](https://github.com/atharvakatre/pharmsight-forecast/blob/main/backend/app/services/versions.py): `backend/app/services/versions.py`
- [Forecast calculations](https://github.com/atharvakatre/pharmsight-forecast/blob/main/backend/app/forecast/engine.py): `backend/app/forecast/engine.py`
- [Forecast models](https://github.com/atharvakatre/pharmsight-forecast/blob/main/backend/app/forecast/models.py): `backend/app/forecast/models.py`

### Workspace data

- [Workspace records](https://github.com/atharvakatre/pharmsight-forecast/blob/main/backend/app/db_models.py): `backend/app/db_models.py`
- [Database sessions](https://github.com/atharvakatre/pharmsight-forecast/blob/main/backend/app/database.py): `backend/app/database.py`
- **PostgreSQL**

### Other components

- **Forecaster / Brand Lead**

## Connections

- Forecaster / Brand Lead → Feature routing: uses (evidence: `frontend/src/routes.tsx`)
- Feature routing → Login: routes to (evidence: `frontend/src/routes.tsx`)
- Feature routing → Forecast dashboard: routes to (evidence: `frontend/src/routes.tsx`)
- Feature routing → Scenario editing: routes to (evidence: `frontend/src/routes.tsx`)
- Feature routing → Version history: routes to (evidence: `frontend/src/routes.tsx`)
- Login → Session state: uses session (evidence: `frontend/src/features/login/LoginPage.tsx`)
- Session state → API client: sets token (evidence: `frontend/src/auth/AuthContext.tsx`)
- Scenario editing → Assumption grid: renders (evidence: `frontend/src/features/scenarios/ScenarioEditor.tsx`)
- Scenario editing → CSV input import: imports CSV (evidence: `frontend/src/features/scenarios/ScenarioEditor.tsx`)
- Scenario editing → Workspace state: uses state (evidence: `frontend/src/features/scenarios/ScenarioEditor.tsx`)
- Forecast dashboard → Workspace state: uses scenarios (evidence: `frontend/src/features/dashboard/DashboardPage.tsx`)
- Version history → Snapshot review: shows detail
- Login → API client: calls API (evidence: `frontend/src/features/login/LoginPage.tsx`)
- Workspace state → API client: calls API (evidence: `frontend/src/workspace/WorkspaceContext.tsx`)
- Forecast dashboard → API client: requests data (evidence: `frontend/src/features/dashboard/DashboardPage.tsx`)
- Scenario editing → API client: requests data (evidence: `frontend/src/features/scenarios/ScenarioEditor.tsx`)
- Snapshot review → API client: requests data (evidence: `frontend/src/features/versions/VersionDetailView.tsx`)
- API client → Authentication routes: HTTP API (evidence: `README.md`)
- API client → Scenario routes: HTTP API (evidence: `README.md`)
- API client → Version and comment routes: HTTP API (evidence: `README.md`)
- Authentication routes → Credential service: authenticates via (evidence: `backend/app/api/auth.py`)
- Authentication routes → Identity and permissions: uses identity (evidence: `backend/app/api/auth.py`)
- Scenario routes → Identity and permissions: checks access (evidence: `backend/app/api/scenarios.py`)
- Scenario routes → Scenario service: delegates to (evidence: `backend/app/api/scenarios.py`)
- Version and comment routes → Version service: delegates to
- Credential service → Workspace records: reads users (evidence: `backend/app/services/auth.py`)
- Credential service → Identity and permissions: verifies passwords
- Scenario service → Workspace records: persists scenarios (evidence: `backend/app/services/scenarios.py`)
- Scenario service → Forecast calculations: calculates forecasts (evidence: `backend/app/services/scenarios.py`)
- Scenario service → Forecast models: builds inputs (evidence: `backend/app/services/scenarios.py`)
- Version service → Scenario service: loads scenarios (evidence: `backend/app/services/versions.py`)
- Version service → Forecast calculations: calculates snapshots (evidence: `backend/app/services/versions.py`)
- Version service → Workspace records: stores snapshots/comments (evidence: `backend/app/services/versions.py`)
- Forecast calculations → Forecast models: uses models (evidence: `backend/app/forecast/engine.py`)
- Workspace records → Database sessions: uses base (evidence: `backend/app/db_models.py`)
- Database sessions → PostgreSQL: connects (evidence: `backend/app/database.py`)
