# baoinam/leafcheck-ai-superadmin architecture

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

- Interactive diagram: https://gitdiagram.com/baoinam/leafcheck-ai-superadmin
- Repository: https://github.com/baoinam/leafcheck-ai-superadmin

## Overview

LeafCheck Super Admin is a standalone web console with a Node/Express backend. Operators sign in with a manually provisioned account; the browser restores and verifies the session before mounting dashboard pages. Authorized pages request read-only telemetry and retention data, while other sections are explicitly disconnected. The graph preserves those disconnected capabilities without implying they are implemented. Relationships for unsampled modules rely only on the README and SOURCE INDEX; no unsampled implementation is assumed inspected.

Main entry points: [`frontend/src/AuthGate.tsx`](https://github.com/baoinam/leafcheck-ai-superadmin/blob/main/frontend/src/AuthGate.tsx) (Auth gate), [`backend/src/server.ts`](https://github.com/baoinam/leafcheck-ai-superadmin/blob/main/backend/src/server.ts) (HTTP server), [`frontend/src/main.tsx`](https://github.com/baoinam/leafcheck-ai-superadmin/blob/main/frontend/src/main.tsx) (Console shell), [`backend/src/auth-store.ts`](https://github.com/baoinam/leafcheck-ai-superadmin/blob/main/backend/src/auth-store.ts) (Auth store)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_web["Console frontend"]
  node_app["Console shell<br/>[main.tsx]"]
  node_gate["Auth gate<br/>[AuthGate.tsx]"]
  node_session["Session client<br/>[session.ts]"]
  node_routing["Route handling<br/>[routing.ts]"]
  node_theme["Theme preference<br/>[theme.ts]"]
  node_api["Admin API client<br/>[api.ts]"]
end

subgraph group_auth["Standalone authentication"]
  node_server["HTTP server<br/>[server.ts]"]
  node_routes["API routes<br/>[app.ts]"]
  node_authflow["Auth middleware<br/>[standalone-auth.ts]"]
  node_authcli["Account provisioning<br/>[auth-cli.ts]"]
  node_store[("Auth store<br/>[auth-store.ts]")]
  node_authdb[("SQLite auth database")]
end

subgraph group_data["Telemetry access"]
  node_telemetry["Telemetry queries<br/>[telemetry.ts]"]
  node_mongo[("Telemetry MongoDB")]
end

subgraph group_scope["Console capabilities"]
  node_pages["Dashboard pages<br/>[pages.tsx]"]
  node_disconnected["Unconnected sections<br/>[pages.tsx]"]
end

node_operator(("Server operator"))
node_browser(("Browser operator"))

node_browser -->|"opens console"| node_gate
node_gate -->|"restores session"| node_session
node_gate -->|"verifies access"| node_api
node_gate -->|"selects destination"| node_routing
node_gate -->|"mounts when authorized"| node_app
node_app -->|"renders sections"| node_pages
node_app -->|"applies preference"| node_theme
node_pages -->|"requests data"| node_api
node_session -->|"calls auth endpoints"| node_authflow
node_api -->|"requests admin data"| node_routes
node_operator -->|"provisions account"| node_authcli
node_authcli -->|"creates account"| node_store
node_server -->|"opens auth store"| node_store
node_server -->|"configures auth"| node_authflow
node_server -->|"connects telemetry"| node_telemetry
node_server -->|"creates app"| node_routes
node_authflow -->|"checks sessions"| node_store
node_store -.->|"persists accounts"| node_authdb
node_routes -->|"dispatches queries"| node_telemetry
node_telemetry -->|"reads telemetry"| node_mongo
node_app -->|"renders unavailable sections"| node_disconnected

click node_app "https://github.com/baoinam/leafcheck-ai-superadmin/blob/main/frontend/src/main.tsx"
click node_gate "https://github.com/baoinam/leafcheck-ai-superadmin/blob/main/frontend/src/AuthGate.tsx"
click node_session "https://github.com/baoinam/leafcheck-ai-superadmin/blob/main/frontend/src/session.ts"
click node_routing "https://github.com/baoinam/leafcheck-ai-superadmin/blob/main/frontend/src/routing.ts"
click node_theme "https://github.com/baoinam/leafcheck-ai-superadmin/blob/main/frontend/src/theme.ts"
click node_api "https://github.com/baoinam/leafcheck-ai-superadmin/blob/main/frontend/src/api.ts"
click node_pages "https://github.com/baoinam/leafcheck-ai-superadmin/blob/main/frontend/src/pages.tsx"
click node_server "https://github.com/baoinam/leafcheck-ai-superadmin/blob/main/backend/src/server.ts"
click node_routes "https://github.com/baoinam/leafcheck-ai-superadmin/blob/main/backend/src/app.ts"
click node_authflow "https://github.com/baoinam/leafcheck-ai-superadmin/blob/main/backend/src/standalone-auth.ts"
click node_authcli "https://github.com/baoinam/leafcheck-ai-superadmin/blob/main/backend/src/auth-cli.ts"
click node_store "https://github.com/baoinam/leafcheck-ai-superadmin/blob/main/backend/src/auth-store.ts"
click node_telemetry "https://github.com/baoinam/leafcheck-ai-superadmin/blob/main/backend/src/telemetry.ts"
click node_disconnected "https://github.com/baoinam/leafcheck-ai-superadmin/blob/main/frontend/src/pages.tsx"

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_app,node_gate,node_session,node_routing,node_theme,node_api,node_browser toneBlue
class node_server,node_routes,node_authflow,node_authcli,node_store,node_authdb toneAmber
class node_telemetry,node_mongo,node_operator toneMint
class node_pages,node_disconnected toneRose
```

## Components

### Console frontend

- [Console shell](https://github.com/baoinam/leafcheck-ai-superadmin/blob/main/frontend/src/main.tsx): `frontend/src/main.tsx`
- [Auth gate](https://github.com/baoinam/leafcheck-ai-superadmin/blob/main/frontend/src/AuthGate.tsx): `frontend/src/AuthGate.tsx`
- [Session client](https://github.com/baoinam/leafcheck-ai-superadmin/blob/main/frontend/src/session.ts): `frontend/src/session.ts`
- [Route handling](https://github.com/baoinam/leafcheck-ai-superadmin/blob/main/frontend/src/routing.ts): `frontend/src/routing.ts`
- [Theme preference](https://github.com/baoinam/leafcheck-ai-superadmin/blob/main/frontend/src/theme.ts): `frontend/src/theme.ts`
- [Admin API client](https://github.com/baoinam/leafcheck-ai-superadmin/blob/main/frontend/src/api.ts): `frontend/src/api.ts`

### Standalone authentication

- [HTTP server](https://github.com/baoinam/leafcheck-ai-superadmin/blob/main/backend/src/server.ts): `backend/src/server.ts`
- [API routes](https://github.com/baoinam/leafcheck-ai-superadmin/blob/main/backend/src/app.ts): `backend/src/app.ts`
- [Auth middleware](https://github.com/baoinam/leafcheck-ai-superadmin/blob/main/backend/src/standalone-auth.ts): `backend/src/standalone-auth.ts`
- [Account provisioning](https://github.com/baoinam/leafcheck-ai-superadmin/blob/main/backend/src/auth-cli.ts): `backend/src/auth-cli.ts`
- [Auth store](https://github.com/baoinam/leafcheck-ai-superadmin/blob/main/backend/src/auth-store.ts): `backend/src/auth-store.ts`
- **SQLite auth database**

### Telemetry access

- [Telemetry queries](https://github.com/baoinam/leafcheck-ai-superadmin/blob/main/backend/src/telemetry.ts): `backend/src/telemetry.ts`
- **Telemetry MongoDB**

### Console capabilities

- [Dashboard pages](https://github.com/baoinam/leafcheck-ai-superadmin/blob/main/frontend/src/pages.tsx): `frontend/src/pages.tsx`
- [Unconnected sections](https://github.com/baoinam/leafcheck-ai-superadmin/blob/main/frontend/src/pages.tsx): `frontend/src/pages.tsx`

### Other components

- **Server operator**
- **Browser operator**

## Connections

- Browser operator → Auth gate: opens console (evidence: `README.md`)
- Auth gate → Session client: restores session (evidence: `frontend/src/AuthGate.tsx`)
- Auth gate → Admin API client: verifies access (evidence: `frontend/src/AuthGate.tsx`)
- Auth gate → Route handling: selects destination (evidence: `frontend/src/AuthGate.tsx`)
- Auth gate → Console shell: mounts when authorized (evidence: `frontend/src/main.tsx`)
- Console shell → Dashboard pages: renders sections (evidence: `frontend/src/main.tsx`)
- Console shell → Theme preference: applies preference (evidence: `frontend/src/main.tsx`)
- Dashboard pages → Admin API client: requests data (evidence: `frontend/src/pages.tsx`)
- Session client → Auth middleware: calls auth endpoints (evidence: `README.md`)
- Admin API client → API routes: requests admin data (evidence: `README.md`)
- Server operator → Account provisioning: provisions account (evidence: `README.md`)
- Account provisioning → Auth store: creates account (evidence: `backend/src/auth-cli.ts`)
- HTTP server → Auth store: opens auth store (evidence: `backend/src/server.ts`)
- HTTP server → Auth middleware: configures auth (evidence: `backend/src/server.ts`)
- HTTP server → Telemetry queries: connects telemetry (evidence: `backend/src/server.ts`)
- HTTP server → API routes: creates app (evidence: `backend/src/server.ts`)
- Auth middleware → Auth store: checks sessions (evidence: `backend/src/standalone-auth.ts`)
- Auth store → SQLite auth database: persists accounts
- API routes → Telemetry queries: dispatches queries (evidence: `backend/src/app.ts`)
- Telemetry queries → Telemetry MongoDB: reads telemetry (evidence: `README.md`)
- Console shell → Unconnected sections: renders unavailable sections (evidence: `frontend/src/main.tsx`)
