# praveenyt872/labflow-ai architecture

> Architecture diagram of the GitHub repository praveenyt872/labflow-ai, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2026-08-17). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/praveenyt872/labflow-ai
- Repository: https://github.com/praveenyt872/labflow-ai

## Overview

#### Purpose and Entry Points
This is a Vite React single-page application for engineering-lab experiment workflows: students select a subject and experiment, enter/inspect observations, calculate formulas, visualize results, and receive AI-assisted validation. It also includes teacher authentication and access-code administration.

Browser startup is `src/main.jsx`, which mounts `src/App.jsx`. Primary page-level navigation is represented by `src/pages/LandingPage.jsx`, `src/pages/SubjectSelectPage.jsx`, `src/pages/ExperimentSelectPage.jsx`, and `src/pages/WorkspacePage.jsx`.

#### Client Application State and Access Control
Global client state is split between authentication and active experiment/workspace state:
- `src/store/authStore.js`
- `src/store/experimentStore.js`

The authentication UI supports role selection, Google sign-in, student gating, teacher login, and teacher dashboard flows through `src/components/auth/RoleSelector.jsx`, `src/components/auth/GoogleSignIn.jsx`, and `src/components/auth/TeacherDashboard.jsx`. Workspace access is therefore a boundary between public experiment discovery and authenticated/student-authorized use.

#### Experiment Definition Pipeline
Experiments are data-driven JSON definitions under `src/data/experiments/`, including `src/data/experiments/venturi.json`, `src/data/experiments/rtd_cstr.json`, and `src/data/experiments/process_control_first_order.json`. Subject grouping is supplied by `src/data/subjects.js`.

Selected definitions feed the workspace rather than requiring a separate implementation per experiment. This makes experiment schema/content a central extensibility boundary: adding an experiment likely requires data and associated formulas/assets rather than new routing architecture.

#### Calculation, Validation, and AI Boundary
The client-side computation layer is concentrated in:
- `src/engine/formulaEngine.js`
- `src/engine/validationEngine.js`
- `src/engine/aiService.js`

`formulaEngine` derives engineering results from observations and experiment definitions; `validationEngine` evaluates inputs/results and supports detailed feedback. `aiService` is an external/remote-service boundary consumed by workspace AI components, notably `src/components/workspace/AIChatWidget.jsx` and `src/components/workspace/AIValidationPanel.jsx`. Offline-aware UI exists in `src/components/pwa/OfflineAIMessage.jsx`, implying AI functionality may degrade independently from local calculations.

#### Workspace Presentation and Results Flow
`src/pages/WorkspacePage.jsx` assembles the active lab workflow. Data moves from observation/input interfaces into calculated, validated, tabular, graphical, and interpretive outputs:
- Inputs/tables: `src/components/workspace/ObservationTable.jsx`, `src/components/workspace/StandardizationTables.jsx`
- Derived results: `src/components/workspace/LiveResultsPanel.jsx`, `src/components/workspace/SampleCalculationPanel.jsx`
- Visualization: `src/components/workspace/GraphPanel.jsx`, `src/components/graph/MatlabStyledPlot.jsx`
- Student narrative: `src/components/workspace/StudentInterpretationPanel.jsx`

Supporting modals provide derivations, validation details, code reference, reports, onboarding, and reset confirmation under `src/components/modals/`.

#### Backend and External Services
A Node server provides authorization/access-code APIs through `server/index.js`, database initialization/access in `server/db.js`, and route modules `server/routes/auth.js`, `server/routes/accessCode.js`, `server/routes/teacherAuth.js`, and `server/routes/verifyCode.js`. A serverless teacher status endpoint also exists at `api/teacher/check-status.js`.

Supabase is a material external service: browser integration is `src/utils/supabaseClient.js`, while provisioning/schema setup is `scripts/supabase_setup.sql`. The architecture therefore separates browser-facing Supabase access from server-owned teacher/access-code route handling.

#### Offline, Persistence, and Deployment Shape
The frontend is PWA-oriented, with manifest/static deployment assets in `public/manifest.json` and `public/.nojekyll`, plus installation/connectivity components in `src/components/pwa/InstallBanner.jsx` and `src/components/pwa/OfflineBadge.jsx`. Local persistence is handled through `src/utils/indexedDbStore.js`, allowing workspace-related data to survive browser sessions or connectivity loss.

The repository combines a Vite-built static React client (`vite.config.js`) with a Node API server and an `api/` serverless-compatible endpoint, so deployment must provide both static hosting and runtime support for backend/auth routes.

Main entry points: [`src/pages/LandingPage.jsx`](https://github.com/praveenyt872/labflow-ai/blob/main/src/pages/LandingPage.jsx) (Lab navigation), [`src/components/auth/RoleSelector.jsx`](https://github.com/praveenyt872/labflow-ai/blob/main/src/components/auth/RoleSelector.jsx) (Auth and teacher UI), [`src/pages/WorkspacePage.jsx`](https://github.com/praveenyt872/labflow-ai/blob/main/src/pages/WorkspacePage.jsx) (Lab workspace), [`src/engine/formulaEngine.js`](https://github.com/praveenyt872/labflow-ai/blob/main/src/engine/formulaEngine.js) (Formula engine)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_client["React client"]
  node_main(("Browser startup<br/>Vite entry<br/>[main.jsx]"))
  node_app["Application shell<br/>React app<br/>[App.jsx]"]
  node_navigation["Lab navigation<br/>page flow<br/>[LandingPage.jsx]"]
  node_auth_store["Authentication state<br/>client store<br/>[authStore.js]"]
  node_auth_ui["Auth and teacher UI<br/>React components<br/>[RoleSelector.jsx]"]
end

subgraph group_workspace["Lab workspace"]
  node_experiment_store["Active experiment state<br/>client store<br/>[experimentStore.js]"]
  node_workspace_page["Lab workspace<br/>React page<br/>[WorkspacePage.jsx]"]
  node_observation_ui["Observation tables<br/>workspace UI"]
  node_results_ui["Results and interpretation<br/>workspace UI"]
  node_graph_ui["Engineering graphs<br/>visualization UI<br/>[GraphPanel.jsx]"]
  node_ai_ui["AI assistance UI<br/>workspace UI<br/>[AIChatWidget.jsx]"]
  node_formula_engine["Formula engine<br/>calculation engine<br/>[formulaEngine.js]"]
  node_validation_engine["Validation engine"]
end

subgraph group_services["Backend services"]
  node_ai_service{{"Remote AI service<br/>AI client boundary<br/>[aiService.js]"}}
  node_node_api["Node API server<br/>HTTP server<br/>[index.js]"]
  node_api_routes["Auth and access routes<br/>route modules<br/>[auth.js]"]
  node_server_db[("Server database access<br/>database adapter<br/>[db.js]")]
  node_teacher_status["Teacher status endpoint<br/>serverless API<br/>[check-status.js]"]
end

subgraph group_data["Data and persistence"]
  node_experiment_definitions["Experiment definitions<br/>JSON catalog"]
  node_subjects["Subject catalog<br/>data module<br/>[subjects.js]"]
  node_local_store[("Offline local storage<br/>IndexedDB adapter<br/>[indexedDbStore.js]")]
  node_supabase_client{{"Supabase browser client<br/>external service adapter<br/>[supabaseClient.js]"}}
end

node_main -->|"mounts"| node_app
node_app -->|"renders"| node_navigation
node_navigation -->|"lists"| node_subjects
node_navigation -->|"selects"| node_experiment_definitions
node_navigation -->|"gates access"| node_auth_ui
node_auth_ui -->|"updates"| node_auth_store
node_auth_ui -->|"auth and codes"| node_node_api
node_auth_ui -.->|"checks status"| node_teacher_status
node_navigation -->|"sets selection"| node_experiment_store
node_experiment_store -->|"drives"| node_workspace_page
node_experiment_definitions -->|"configures"| node_workspace_page
node_workspace_page -->|"collects inputs"| node_observation_ui
node_observation_ui -->|"observations"| node_formula_engine
node_experiment_definitions -->|"formulas and schema"| node_formula_engine
node_formula_engine -->|"derived results"| node_validation_engine
node_formula_engine -->|"calculations"| node_results_ui
node_validation_engine -->|"feedback"| node_results_ui
node_formula_engine -->|"plot data"| node_graph_ui
node_workspace_page -->|"hosts"| node_ai_ui
node_ai_ui -->|"AI requests"| node_ai_service
node_workspace_page -->|"persists work"| node_local_store
node_node_api -->|"serves"| node_api_routes
node_api_routes -->|"reads and writes"| node_server_db
node_auth_ui -->|"browser integration"| node_supabase_client

click node_main "https://github.com/praveenyt872/labflow-ai/blob/main/src/main.jsx"
click node_app "https://github.com/praveenyt872/labflow-ai/blob/main/src/App.jsx"
click node_navigation "https://github.com/praveenyt872/labflow-ai/blob/main/src/pages/LandingPage.jsx"
click node_auth_store "https://github.com/praveenyt872/labflow-ai/blob/main/src/store/authStore.js"
click node_auth_ui "https://github.com/praveenyt872/labflow-ai/blob/main/src/components/auth/RoleSelector.jsx"
click node_experiment_store "https://github.com/praveenyt872/labflow-ai/blob/main/src/store/experimentStore.js"
click node_workspace_page "https://github.com/praveenyt872/labflow-ai/blob/main/src/pages/WorkspacePage.jsx"
click node_observation_ui "https://github.com/praveenyt872/labflow-ai/blob/main/src/components/workspace/ObservationTable.jsx"
click node_results_ui "https://github.com/praveenyt872/labflow-ai/blob/main/src/components/workspace/LiveResultsPanel.jsx"
click node_graph_ui "https://github.com/praveenyt872/labflow-ai/blob/main/src/components/workspace/GraphPanel.jsx"
click node_ai_ui "https://github.com/praveenyt872/labflow-ai/blob/main/src/components/workspace/AIChatWidget.jsx"
click node_subjects "https://github.com/praveenyt872/labflow-ai/blob/main/src/data/subjects.js"
click node_formula_engine "https://github.com/praveenyt872/labflow-ai/blob/main/src/engine/formulaEngine.js"
click node_validation_engine "https://github.com/praveenyt872/labflow-ai/blob/main/src/engine/validationEngine.js"
click node_ai_service "https://github.com/praveenyt872/labflow-ai/blob/main/src/engine/aiService.js"
click node_local_store "https://github.com/praveenyt872/labflow-ai/blob/main/src/utils/indexedDbStore.js"
click node_node_api "https://github.com/praveenyt872/labflow-ai/blob/main/server/index.js"
click node_api_routes "https://github.com/praveenyt872/labflow-ai/blob/main/server/routes/auth.js"
click node_server_db "https://github.com/praveenyt872/labflow-ai/blob/main/server/db.js"
click node_teacher_status "https://github.com/praveenyt872/labflow-ai/blob/main/api/teacher/check-status.js"
click node_supabase_client "https://github.com/praveenyt872/labflow-ai/blob/main/src/utils/supabaseClient.js"

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_main,node_app,node_navigation,node_auth_store,node_auth_ui toneBlue
class node_experiment_store,node_workspace_page,node_observation_ui,node_results_ui,node_graph_ui,node_ai_ui,node_formula_engine,node_validation_engine toneAmber
class node_ai_service,node_node_api,node_api_routes,node_server_db,node_teacher_status toneMint
class node_experiment_definitions,node_subjects,node_local_store,node_supabase_client toneRose
```

## Components

### React client

- [Browser startup](https://github.com/praveenyt872/labflow-ai/blob/main/src/main.jsx): Vite entry · `src/main.jsx`
- [Application shell](https://github.com/praveenyt872/labflow-ai/blob/main/src/App.jsx): React app · `src/App.jsx`
- [Lab navigation](https://github.com/praveenyt872/labflow-ai/blob/main/src/pages/LandingPage.jsx): page flow · Landing, subject selection, experiment selection, and workspace pages. · `src/pages/LandingPage.jsx`
- [Authentication state](https://github.com/praveenyt872/labflow-ai/blob/main/src/store/authStore.js): client store · `src/store/authStore.js`
- [Auth and teacher UI](https://github.com/praveenyt872/labflow-ai/blob/main/src/components/auth/RoleSelector.jsx): React components · Role selection, Google sign-in, and teacher dashboard flows. · `src/components/auth/RoleSelector.jsx`

### Lab workspace

- [Active experiment state](https://github.com/praveenyt872/labflow-ai/blob/main/src/store/experimentStore.js): client store · `src/store/experimentStore.js`
- [Lab workspace](https://github.com/praveenyt872/labflow-ai/blob/main/src/pages/WorkspacePage.jsx): React page · Assembles the active experiment workflow. · `src/pages/WorkspacePage.jsx`
- [Observation tables](https://github.com/praveenyt872/labflow-ai/blob/main/src/components/workspace/ObservationTable.jsx): workspace UI · Observation and standardization input tables. · `src/components/workspace/ObservationTable.jsx`
- [Results and interpretation](https://github.com/praveenyt872/labflow-ai/blob/main/src/components/workspace/LiveResultsPanel.jsx): workspace UI · Live results, sample calculations, and student interpretation. · `src/components/workspace/LiveResultsPanel.jsx`
- [Engineering graphs](https://github.com/praveenyt872/labflow-ai/blob/main/src/components/workspace/GraphPanel.jsx): visualization UI · Workspace graph panel and MATLAB-styled plot. · `src/components/workspace/GraphPanel.jsx`
- [AI assistance UI](https://github.com/praveenyt872/labflow-ai/blob/main/src/components/workspace/AIChatWidget.jsx): workspace UI · Chat, validation feedback, and offline AI messaging. · `src/components/workspace/AIChatWidget.jsx`
- [Formula engine](https://github.com/praveenyt872/labflow-ai/blob/main/src/engine/formulaEngine.js): calculation engine · `src/engine/formulaEngine.js`
- [Validation engine](https://github.com/praveenyt872/labflow-ai/blob/main/src/engine/validationEngine.js): validation engine · `src/engine/validationEngine.js`

### Backend services

- [Remote AI service](https://github.com/praveenyt872/labflow-ai/blob/main/src/engine/aiService.js): AI client boundary · `src/engine/aiService.js`
- [Node API server](https://github.com/praveenyt872/labflow-ai/blob/main/server/index.js): HTTP server · Owns authorization and access-code APIs. · `server/index.js`
- [Auth and access routes](https://github.com/praveenyt872/labflow-ai/blob/main/server/routes/auth.js): route modules · Authentication, teacher login, code creation, and code verification. · `server/routes/auth.js`
- [Server database access](https://github.com/praveenyt872/labflow-ai/blob/main/server/db.js): database adapter · `server/db.js`
- [Teacher status endpoint](https://github.com/praveenyt872/labflow-ai/blob/main/api/teacher/check-status.js): serverless API · `api/teacher/check-status.js`

### Data and persistence

- **Experiment definitions**: JSON catalog · Data-driven experiment schemas and content.
- [Subject catalog](https://github.com/praveenyt872/labflow-ai/blob/main/src/data/subjects.js): data module · `src/data/subjects.js`
- [Offline local storage](https://github.com/praveenyt872/labflow-ai/blob/main/src/utils/indexedDbStore.js): IndexedDB adapter · `src/utils/indexedDbStore.js`
- [Supabase browser client](https://github.com/praveenyt872/labflow-ai/blob/main/src/utils/supabaseClient.js): external service adapter · `src/utils/supabaseClient.js`

## Connections

- Browser startup → Application shell: mounts
- Application shell → Lab navigation: renders
- Lab navigation → Subject catalog: lists
- Lab navigation → Experiment definitions: selects
- Lab navigation → Auth and teacher UI: gates access
- Auth and teacher UI → Authentication state: updates
- Auth and teacher UI → Node API server: auth and codes
- Auth and teacher UI → Teacher status endpoint: checks status
- Lab navigation → Active experiment state: sets selection
- Active experiment state → Lab workspace: drives
- Experiment definitions → Lab workspace: configures
- Lab workspace → Observation tables: collects inputs
- Observation tables → Formula engine: observations
- Experiment definitions → Formula engine: formulas and schema
- Formula engine → Validation engine: derived results
- Formula engine → Results and interpretation: calculations
- Validation engine → Results and interpretation: feedback
- Formula engine → Engineering graphs: plot data
- Lab workspace → AI assistance UI: hosts
- AI assistance UI → Remote AI service: AI requests
- Lab workspace → Offline local storage: persists work
- Node API server → Auth and access routes: serves
- Auth and access routes → Server database access: reads and writes
- Auth and teacher UI → Supabase browser client: browser integration
