# switchcontrol01/switchcontrol architecture

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

- Interactive diagram: https://gitdiagram.com/switchcontrol01/switchcontrol
- Repository: https://github.com/switchcontrol01/switchcontrol

## Overview

SwitchControl is a Windows-focused gaming optimization dashboard delivered as a React client, Express cloud service, and Electron desktop wrapper. Users sign in, inspect system state, choose diagnostic or optimization features, and can apply desktop actions; cloud routes also support AI advice, account entitlements, and persistent history. The README establishes the dashboard-in-desktop workflow and OAuth support. Several feature modules are present in the tree but unsampled, so their internal calls are not asserted; dashed edges mark documented-but-unverified connections.

Main entry points: [`server/routes.ts`](https://github.com/switchcontrol01/switchcontrol/blob/main/server/routes.ts) (Route registry), [`electron/main.js`](https://github.com/switchcontrol01/switchcontrol/blob/main/electron/main.js) (Electron bridge), [`client/src/lib/api.ts`](https://github.com/switchcontrol01/switchcontrol/blob/main/client/src/lib/api.ts) (Client API), [`client/src/App.tsx`](https://github.com/switchcontrol01/switchcontrol/blob/main/client/src/App.tsx) (Dashboard shell)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_client["Dashboard client"]
  node_dashboard["Dashboard shell<br/>[App.tsx]"]
  node_feature_pages["Feature pages"]
  node_client_api["Client API<br/>[api.ts]"]
  node_query_cache["Query cache<br/>[queryClient.ts]"]
  node_telemetry_ui["Live telemetry"]
end

subgraph group_cloud["Cloud services"]
  node_system_routes["System features"]
  node_route_registry["Route registry<br/>[routes.ts]"]
  node_ai_routes["AI advisor<br/>[ai.ts]"]
  node_advisor_context["Advisor context<br/>[advisorContext.ts]"]
  node_telemetry_service["Telemetry service<br/>[telemetry.ts]"]
end

subgraph group_desktop["Desktop controls"]
  node_electron["Electron bridge<br/>[main.js]"]
  node_tweak_executor["System tweak executor<br/>[tweak-executor.js]"]
  node_power_manager["Power plans"]
  node_storage_helper["Drive diagnostics<br/>[storage-helper.js]"]
  node_revert_pipeline["Premium change revert"]
  node_ownership[("Change ownership<br/>[ownership-store.js]")]
end

subgraph group_domain["Optimization intelligence"]
  node_engine["Optimization planner"]
  node_network_engine["Network planner"]
  node_tweak_catalog["Tweak catalog<br/>[tweak-registry.ts]"]
end

subgraph group_identity["Identity and state"]
  node_auth["OAuth and sessions<br/>[google.ts]"]
  node_cloud_auth["Cloud authorization"]
  node_storage["Account storage<br/>[storage.ts]"]
  node_database[("Postgres database<br/>[db.ts]")]
end

node_user(("User"))

node_user -.->|"uses"| node_dashboard
node_dashboard -->|"configures"| node_query_cache
node_feature_pages -.->|"requests data"| node_client_api
node_client_api -->|"uses"| node_query_cache
node_client_api -.->|"calls API"| node_route_registry
node_dashboard -.->|"presents"| node_feature_pages
node_telemetry_ui -.->|"fetches telemetry"| node_client_api
node_route_registry -->|"registers"| node_system_routes
node_route_registry -->|"registers"| node_ai_routes
node_ai_routes -->|"enriches prompts"| node_advisor_context
node_advisor_context -->|"reads snapshot"| node_telemetry_service
node_route_registry -->|"sets up auth"| node_auth
node_cloud_auth -->|"loads user"| node_storage
node_auth -->|"persists accounts"| node_storage
node_storage -->|"reads and writes"| node_database
node_engine -.->|"scores tweaks"| node_tweak_catalog
node_network_engine -->|"uses planner"| node_engine
node_user -.->|"uses desktop app"| node_electron
node_electron -->|"dispatches actions"| node_tweak_executor
node_electron -->|"dispatches actions"| node_power_manager
node_electron -->|"registers handlers"| node_storage_helper
node_revert_pipeline -->|"reverts tweaks"| node_tweak_executor
node_revert_pipeline -->|"records revert"| node_ownership
node_power_manager -->|"tracks changes"| node_ownership

click node_dashboard "https://github.com/switchcontrol01/switchcontrol/blob/main/client/src/App.tsx"
click node_feature_pages "https://github.com/switchcontrol01/switchcontrol/tree/main/client/src/pages"
click node_client_api "https://github.com/switchcontrol01/switchcontrol/blob/main/client/src/lib/api.ts"
click node_query_cache "https://github.com/switchcontrol01/switchcontrol/blob/main/client/src/lib/queryClient.ts"
click node_telemetry_ui "https://github.com/switchcontrol01/switchcontrol/blob/main/client/src/hooks/useLiveTelemetry.ts"
click node_system_routes "https://github.com/switchcontrol01/switchcontrol/tree/main/server/routes"
click node_route_registry "https://github.com/switchcontrol01/switchcontrol/blob/main/server/routes.ts"
click node_ai_routes "https://github.com/switchcontrol01/switchcontrol/blob/main/server/routes/ai.ts"
click node_advisor_context "https://github.com/switchcontrol01/switchcontrol/blob/main/server/routes/advisorContext.ts"
click node_telemetry_service "https://github.com/switchcontrol01/switchcontrol/blob/main/server/lib/telemetry.ts"
click node_auth "https://github.com/switchcontrol01/switchcontrol/blob/main/server/auth/google.ts"
click node_cloud_auth "https://github.com/switchcontrol01/switchcontrol/blob/main/server/middleware/requireCloudAuth.ts"
click node_storage "https://github.com/switchcontrol01/switchcontrol/blob/main/server/storage.ts"
click node_database "https://github.com/switchcontrol01/switchcontrol/blob/main/server/db.ts"
click node_engine "https://github.com/switchcontrol01/switchcontrol/blob/main/shared/optimizationEngine.ts"
click node_network_engine "https://github.com/switchcontrol01/switchcontrol/blob/main/shared/networkOptimizationEngine.ts"
click node_tweak_catalog "https://github.com/switchcontrol01/switchcontrol/blob/main/client/src/lib/tweak-registry.ts"
click node_electron "https://github.com/switchcontrol01/switchcontrol/blob/main/electron/main.js"
click node_tweak_executor "https://github.com/switchcontrol01/switchcontrol/blob/main/electron/tweak-executor.js"
click node_power_manager "https://github.com/switchcontrol01/switchcontrol/blob/main/electron/power-plan-manager.js"
click node_storage_helper "https://github.com/switchcontrol01/switchcontrol/blob/main/electron/storage-helper.js"
click node_revert_pipeline "https://github.com/switchcontrol01/switchcontrol/blob/main/electron/premium-revert-pipeline.js"
click node_ownership "https://github.com/switchcontrol01/switchcontrol/blob/main/electron/ownership-store.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_dashboard,node_feature_pages,node_client_api,node_query_cache,node_telemetry_ui,node_user toneBlue
class node_system_routes,node_route_registry,node_ai_routes,node_advisor_context,node_telemetry_service toneAmber
class node_electron,node_tweak_executor,node_power_manager,node_storage_helper,node_revert_pipeline,node_ownership toneMint
class node_engine,node_network_engine,node_tweak_catalog toneRose
class node_auth,node_cloud_auth,node_storage,node_database toneIndigo
```

## Components

### Dashboard client

- [Dashboard shell](https://github.com/switchcontrol01/switchcontrol/blob/main/client/src/App.tsx): `client/src/App.tsx`
- [Feature pages](https://github.com/switchcontrol01/switchcontrol/tree/main/client/src/pages): `client/src/pages`
- [Client API](https://github.com/switchcontrol01/switchcontrol/blob/main/client/src/lib/api.ts): `client/src/lib/api.ts`
- [Query cache](https://github.com/switchcontrol01/switchcontrol/blob/main/client/src/lib/queryClient.ts): `client/src/lib/queryClient.ts`
- [Live telemetry](https://github.com/switchcontrol01/switchcontrol/blob/main/client/src/hooks/useLiveTelemetry.ts): `client/src/hooks/useLiveTelemetry.ts`

### Cloud services

- [System features](https://github.com/switchcontrol01/switchcontrol/tree/main/server/routes): `server/routes`
- [Route registry](https://github.com/switchcontrol01/switchcontrol/blob/main/server/routes.ts): `server/routes.ts`
- [AI advisor](https://github.com/switchcontrol01/switchcontrol/blob/main/server/routes/ai.ts): `server/routes/ai.ts`
- [Advisor context](https://github.com/switchcontrol01/switchcontrol/blob/main/server/routes/advisorContext.ts): `server/routes/advisorContext.ts`
- [Telemetry service](https://github.com/switchcontrol01/switchcontrol/blob/main/server/lib/telemetry.ts): `server/lib/telemetry.ts`

### Desktop controls

- [Electron bridge](https://github.com/switchcontrol01/switchcontrol/blob/main/electron/main.js): `electron/main.js`
- [System tweak executor](https://github.com/switchcontrol01/switchcontrol/blob/main/electron/tweak-executor.js): `electron/tweak-executor.js`
- [Power plans](https://github.com/switchcontrol01/switchcontrol/blob/main/electron/power-plan-manager.js): `electron/power-plan-manager.js`
- [Drive diagnostics](https://github.com/switchcontrol01/switchcontrol/blob/main/electron/storage-helper.js): `electron/storage-helper.js`
- [Premium change revert](https://github.com/switchcontrol01/switchcontrol/blob/main/electron/premium-revert-pipeline.js): `electron/premium-revert-pipeline.js`
- [Change ownership](https://github.com/switchcontrol01/switchcontrol/blob/main/electron/ownership-store.js): `electron/ownership-store.js`

### Optimization intelligence

- [Optimization planner](https://github.com/switchcontrol01/switchcontrol/blob/main/shared/optimizationEngine.ts): `shared/optimizationEngine.ts`
- [Network planner](https://github.com/switchcontrol01/switchcontrol/blob/main/shared/networkOptimizationEngine.ts): `shared/networkOptimizationEngine.ts`
- [Tweak catalog](https://github.com/switchcontrol01/switchcontrol/blob/main/client/src/lib/tweak-registry.ts): `client/src/lib/tweak-registry.ts`

### Identity and state

- [OAuth and sessions](https://github.com/switchcontrol01/switchcontrol/blob/main/server/auth/google.ts): `server/auth/google.ts`
- [Cloud authorization](https://github.com/switchcontrol01/switchcontrol/blob/main/server/middleware/requireCloudAuth.ts): `server/middleware/requireCloudAuth.ts`
- [Account storage](https://github.com/switchcontrol01/switchcontrol/blob/main/server/storage.ts): `server/storage.ts`
- [Postgres database](https://github.com/switchcontrol01/switchcontrol/blob/main/server/db.ts): `server/db.ts`

### Other components

- **User**

## Connections

- User → Dashboard shell: uses
- Dashboard shell → Query cache: configures (evidence: `client/src/App.tsx`)
- Feature pages → Client API: requests data
- Client API → Query cache: uses (evidence: `client/src/lib/api.ts`)
- Client API → Route registry: calls API
- Dashboard shell → Feature pages: presents
- Live telemetry → Client API: fetches telemetry
- Route registry → System features: registers (evidence: `server/routes.ts`)
- Route registry → AI advisor: registers (evidence: `server/routes.ts`)
- AI advisor → Advisor context: enriches prompts (evidence: `server/routes/ai.ts`)
- Advisor context → Telemetry service: reads snapshot (evidence: `server/routes/advisorContext.ts`)
- Route registry → OAuth and sessions: sets up auth (evidence: `server/routes.ts`)
- Cloud authorization → Account storage: loads user (evidence: `server/middleware/requireCloudAuth.ts`)
- OAuth and sessions → Account storage: persists accounts (evidence: `server/auth/google.ts`)
- Account storage → Postgres database: reads and writes (evidence: `server/storage.ts`)
- Optimization planner → Tweak catalog: scores tweaks
- Network planner → Optimization planner: uses planner (evidence: `shared/networkOptimizationEngine.ts`)
- User → Electron bridge: uses desktop app
- Electron bridge → System tweak executor: dispatches actions (evidence: `electron/main.js`)
- Electron bridge → Power plans: dispatches actions (evidence: `electron/main.js`)
- Electron bridge → Drive diagnostics: registers handlers (evidence: `electron/main.js`)
- Premium change revert → System tweak executor: reverts tweaks (evidence: `electron/premium-revert-pipeline.js`)
- Premium change revert → Change ownership: records revert (evidence: `electron/premium-revert-pipeline.js`)
- Power plans → Change ownership: tracks changes (evidence: `electron/power-plan-manager.js`)
