# lilfanq/nguyen-luong-nhat-phuong_24ct1_cnpm_loki architecture

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

- Interactive diagram: https://gitdiagram.com/lilfanq/nguyen-luong-nhat-phuong_24ct1_cnpm_loki
- Repository: https://github.com/lilfanq/nguyen-luong-nhat-phuong_24ct1_cnpm_loki

## Overview

LOKI is a browser workspace for gaming peripherals. The main workflow runs through the React app: users sign in or use a guest session, choose a device and profile, configure settings or apply recommendations, and review setup diagnostics. Profiles and device workspace state are mainly browser-local; signed-in profile names and account roles use Supabase. The assistant can request replies from a Supabase Edge Function. Edges reflect sampled source references and README-documented behavior; unsampled implementation details are omitted rather than inferred.

Main entry points: [`frontend/src/App.jsx`](https://github.com/lilfanq/nguyen-luong-nhat-phuong_24ct1_cnpm_loki/blob/main/frontend/src/App.jsx) (Workspace app), [`frontend/src/features/auth/authService.js`](https://github.com/lilfanq/nguyen-luong-nhat-phuong_24ct1_cnpm_loki/blob/main/frontend/src/features/auth/authService.js) (Auth service), [`frontend/src/profileService.js`](https://github.com/lilfanq/nguyen-luong-nhat-phuong_24ct1_cnpm_loki/blob/main/frontend/src/profileService.js) (Profile persistence), [`frontend/src/mockData.js`](https://github.com/lilfanq/nguyen-luong-nhat-phuong_24ct1_cnpm_loki/blob/main/frontend/src/mockData.js) (Catalog and sample data)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_app["Workspace"]
  node_app["Workspace app<br/>[App.jsx]"]
end

subgraph group_devices["Devices"]
  node_device_catalog["Device catalog"]
  node_workspace_settings["Device settings"]
  node_settings_defaults["Settings defaults<br/>[deviceSettings.js]"]
  node_webhid["Browser WebHID"]
end

subgraph group_profiles["Profiles and insights"]
  node_profile_panels["Profile panels<br/>[ProfilePanels.jsx]"]
  node_profile_service["Profile persistence<br/>[profileService.js]"]
  node_browser_storage[("Browser storage")]
  node_recommendations["Recommendations"]
  node_insights["Setup diagnostics<br/>[InsightPanels.jsx]"]
  node_mock_data["Catalog and sample data<br/>[mockData.js]"]
  node_assistant["Assistant service"]
end

subgraph group_identity["Identity and administration"]
  node_auth_form["Sign-in form<br/>[AuthFormPanel.jsx]"]
  node_auth_session["Signed-in session"]
  node_guest_session["Guest session"]
  node_auth_service["Auth service<br/>[authService.js]"]
  node_admin["Account administration<br/>[AdminDashboard.jsx]"]
  node_role_sql["Role policies<br/>[admin_roles.sql]"]
end

subgraph group_services["Backend services"]
  node_supabase_client["Supabase client<br/>[supabaseClient.js]"]
  node_supabase[("Supabase platform")]
  node_profiles_migration["Profile migration"]
  node_chat_function["LOKI chat function<br/>[index.ts]"]
end

node_user(("Workspace user"))

node_user -->|"uses"| node_app
node_app -->|"renders"| node_auth_form
node_app -->|"renders"| node_auth_session
node_app -->|"renders"| node_guest_session
node_app -->|"renders"| node_device_catalog
node_app -->|"renders"| node_workspace_settings
node_app -->|"renders"| node_admin
node_app -->|"renders"| node_profile_panels
node_app -->|"renders"| node_recommendations
node_app -->|"renders"| node_insights
node_app -->|"requests replies"| node_assistant
node_app -->|"loads and saves"| node_profile_service
node_workspace_settings -->|"uses defaults"| node_settings_defaults
node_app -->|"accesses devices"| node_webhid
node_auth_form -.->|"submits auth"| node_auth_service
node_app -->|"checks roles"| node_auth_service
node_auth_service -->|"uses client"| node_supabase_client
node_admin -->|"manages roles"| node_auth_service
node_auth_service -->|"queries accounts"| node_supabase
node_role_sql -->|"defines protections"| node_supabase
node_profile_panels -.->|"reports profile actions"| node_app
node_profile_service -->|"reads and writes"| node_browser_storage
node_app -->|"loads client"| node_supabase_client
node_profile_service -->|"syncs names"| node_supabase
node_profiles_migration -->|"creates profile table"| node_supabase
node_recommendations -->|"reads recommendations"| node_mock_data
node_insights -->|"reads diagnostics"| node_mock_data
node_app -->|"uses recommendations"| node_mock_data
node_assistant -->|"invokes function"| node_supabase
node_supabase -->|"dispatches chat"| node_chat_function

click node_app "https://github.com/lilfanq/nguyen-luong-nhat-phuong_24ct1_cnpm_loki/blob/main/frontend/src/App.jsx"
click node_device_catalog "https://github.com/lilfanq/nguyen-luong-nhat-phuong_24ct1_cnpm_loki/blob/main/frontend/src/features/devices/DeviceCatalogPanel.jsx"
click node_workspace_settings "https://github.com/lilfanq/nguyen-luong-nhat-phuong_24ct1_cnpm_loki/blob/main/frontend/src/features/devices/WorkspaceSettings.jsx"
click node_settings_defaults "https://github.com/lilfanq/nguyen-luong-nhat-phuong_24ct1_cnpm_loki/blob/main/frontend/src/features/devices/deviceSettings.js"
click node_auth_form "https://github.com/lilfanq/nguyen-luong-nhat-phuong_24ct1_cnpm_loki/blob/main/frontend/src/features/auth/AuthFormPanel.jsx"
click node_auth_session "https://github.com/lilfanq/nguyen-luong-nhat-phuong_24ct1_cnpm_loki/blob/main/frontend/src/features/auth/AuthenticatedSessionPanel.jsx"
click node_guest_session "https://github.com/lilfanq/nguyen-luong-nhat-phuong_24ct1_cnpm_loki/blob/main/frontend/src/features/auth/GuestSessionPanel.jsx"
click node_auth_service "https://github.com/lilfanq/nguyen-luong-nhat-phuong_24ct1_cnpm_loki/blob/main/frontend/src/features/auth/authService.js"
click node_admin "https://github.com/lilfanq/nguyen-luong-nhat-phuong_24ct1_cnpm_loki/blob/main/frontend/src/features/admin/AdminDashboard.jsx"
click node_role_sql "https://github.com/lilfanq/nguyen-luong-nhat-phuong_24ct1_cnpm_loki/blob/main/backend/supabase/admin_roles.sql"
click node_profile_panels "https://github.com/lilfanq/nguyen-luong-nhat-phuong_24ct1_cnpm_loki/blob/main/frontend/src/features/profiles/ProfilePanels.jsx"
click node_profile_service "https://github.com/lilfanq/nguyen-luong-nhat-phuong_24ct1_cnpm_loki/blob/main/frontend/src/profileService.js"
click node_recommendations "https://github.com/lilfanq/nguyen-luong-nhat-phuong_24ct1_cnpm_loki/blob/main/frontend/src/features/recommendations/RecommendationPanels.jsx"
click node_insights "https://github.com/lilfanq/nguyen-luong-nhat-phuong_24ct1_cnpm_loki/blob/main/frontend/src/features/insights/InsightPanels.jsx"
click node_mock_data "https://github.com/lilfanq/nguyen-luong-nhat-phuong_24ct1_cnpm_loki/blob/main/frontend/src/mockData.js"
click node_assistant "https://github.com/lilfanq/nguyen-luong-nhat-phuong_24ct1_cnpm_loki/blob/main/frontend/src/features/assistant/assistantService.js"
click node_supabase_client "https://github.com/lilfanq/nguyen-luong-nhat-phuong_24ct1_cnpm_loki/blob/main/frontend/src/supabaseClient.js"
click node_profiles_migration "https://github.com/lilfanq/nguyen-luong-nhat-phuong_24ct1_cnpm_loki/blob/main/backend/supabase/migrations/202610090001_user_profiles.sql"
click node_chat_function "https://github.com/lilfanq/nguyen-luong-nhat-phuong_24ct1_cnpm_loki/blob/main/backend/supabase/functions/loki-chat/index.ts"

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_user toneBlue
class node_device_catalog,node_workspace_settings,node_settings_defaults,node_webhid toneAmber
class node_profile_panels,node_profile_service,node_browser_storage,node_recommendations,node_insights,node_mock_data,node_assistant toneMint
class node_auth_form,node_auth_session,node_guest_session,node_auth_service,node_admin,node_role_sql toneRose
class node_supabase_client,node_supabase,node_profiles_migration,node_chat_function toneIndigo
```

## Components

### Workspace

- [Workspace app](https://github.com/lilfanq/nguyen-luong-nhat-phuong_24ct1_cnpm_loki/blob/main/frontend/src/App.jsx): `frontend/src/App.jsx`

### Devices

- [Device catalog](https://github.com/lilfanq/nguyen-luong-nhat-phuong_24ct1_cnpm_loki/blob/main/frontend/src/features/devices/DeviceCatalogPanel.jsx): `frontend/src/features/devices/DeviceCatalogPanel.jsx`
- [Device settings](https://github.com/lilfanq/nguyen-luong-nhat-phuong_24ct1_cnpm_loki/blob/main/frontend/src/features/devices/WorkspaceSettings.jsx): `frontend/src/features/devices/WorkspaceSettings.jsx`
- [Settings defaults](https://github.com/lilfanq/nguyen-luong-nhat-phuong_24ct1_cnpm_loki/blob/main/frontend/src/features/devices/deviceSettings.js): `frontend/src/features/devices/deviceSettings.js`
- **Browser WebHID**

### Profiles and insights

- [Profile panels](https://github.com/lilfanq/nguyen-luong-nhat-phuong_24ct1_cnpm_loki/blob/main/frontend/src/features/profiles/ProfilePanels.jsx): `frontend/src/features/profiles/ProfilePanels.jsx`
- [Profile persistence](https://github.com/lilfanq/nguyen-luong-nhat-phuong_24ct1_cnpm_loki/blob/main/frontend/src/profileService.js): `frontend/src/profileService.js`
- **Browser storage**
- [Recommendations](https://github.com/lilfanq/nguyen-luong-nhat-phuong_24ct1_cnpm_loki/blob/main/frontend/src/features/recommendations/RecommendationPanels.jsx): `frontend/src/features/recommendations/RecommendationPanels.jsx`
- [Setup diagnostics](https://github.com/lilfanq/nguyen-luong-nhat-phuong_24ct1_cnpm_loki/blob/main/frontend/src/features/insights/InsightPanels.jsx): `frontend/src/features/insights/InsightPanels.jsx`
- [Catalog and sample data](https://github.com/lilfanq/nguyen-luong-nhat-phuong_24ct1_cnpm_loki/blob/main/frontend/src/mockData.js): `frontend/src/mockData.js`
- [Assistant service](https://github.com/lilfanq/nguyen-luong-nhat-phuong_24ct1_cnpm_loki/blob/main/frontend/src/features/assistant/assistantService.js): `frontend/src/features/assistant/assistantService.js`

### Identity and administration

- [Sign-in form](https://github.com/lilfanq/nguyen-luong-nhat-phuong_24ct1_cnpm_loki/blob/main/frontend/src/features/auth/AuthFormPanel.jsx): `frontend/src/features/auth/AuthFormPanel.jsx`
- [Signed-in session](https://github.com/lilfanq/nguyen-luong-nhat-phuong_24ct1_cnpm_loki/blob/main/frontend/src/features/auth/AuthenticatedSessionPanel.jsx): `frontend/src/features/auth/AuthenticatedSessionPanel.jsx`
- [Guest session](https://github.com/lilfanq/nguyen-luong-nhat-phuong_24ct1_cnpm_loki/blob/main/frontend/src/features/auth/GuestSessionPanel.jsx): `frontend/src/features/auth/GuestSessionPanel.jsx`
- [Auth service](https://github.com/lilfanq/nguyen-luong-nhat-phuong_24ct1_cnpm_loki/blob/main/frontend/src/features/auth/authService.js): `frontend/src/features/auth/authService.js`
- [Account administration](https://github.com/lilfanq/nguyen-luong-nhat-phuong_24ct1_cnpm_loki/blob/main/frontend/src/features/admin/AdminDashboard.jsx): `frontend/src/features/admin/AdminDashboard.jsx`
- [Role policies](https://github.com/lilfanq/nguyen-luong-nhat-phuong_24ct1_cnpm_loki/blob/main/backend/supabase/admin_roles.sql): `backend/supabase/admin_roles.sql`

### Backend services

- [Supabase client](https://github.com/lilfanq/nguyen-luong-nhat-phuong_24ct1_cnpm_loki/blob/main/frontend/src/supabaseClient.js): `frontend/src/supabaseClient.js`
- **Supabase platform**
- [Profile migration](https://github.com/lilfanq/nguyen-luong-nhat-phuong_24ct1_cnpm_loki/blob/main/backend/supabase/migrations/202610090001_user_profiles.sql): `backend/supabase/migrations/202610090001_user_profiles.sql`
- [LOKI chat function](https://github.com/lilfanq/nguyen-luong-nhat-phuong_24ct1_cnpm_loki/blob/main/backend/supabase/functions/loki-chat/index.ts): `backend/supabase/functions/loki-chat/index.ts`

### Other components

- **Workspace user**

## Connections

- Workspace user → Workspace app: uses (evidence: `README.md`)
- Workspace app → Sign-in form: renders (evidence: `frontend/src/App.jsx`)
- Workspace app → Signed-in session: renders (evidence: `frontend/src/App.jsx`)
- Workspace app → Guest session: renders (evidence: `frontend/src/App.jsx`)
- Workspace app → Device catalog: renders (evidence: `frontend/src/App.jsx`)
- Workspace app → Device settings: renders (evidence: `frontend/src/App.jsx`)
- Workspace app → Account administration: renders (evidence: `frontend/src/App.jsx`)
- Workspace app → Profile panels: renders (evidence: `frontend/src/App.jsx`)
- Workspace app → Recommendations: renders (evidence: `frontend/src/App.jsx`)
- Workspace app → Setup diagnostics: renders (evidence: `frontend/src/App.jsx`)
- Workspace app → Assistant service: requests replies (evidence: `frontend/src/features/assistant/assistantService.js`)
- Workspace app → Profile persistence: loads and saves (evidence: `frontend/src/App.jsx`)
- Device settings → Settings defaults: uses defaults (evidence: `frontend/src/features/devices/WorkspaceSettings.jsx`)
- Workspace app → Browser WebHID: accesses devices (evidence: `README.md`)
- Sign-in form → Auth service: submits auth
- Workspace app → Auth service: checks roles (evidence: `frontend/src/App.jsx`)
- Auth service → Supabase client: uses client (evidence: `frontend/src/features/auth/authService.js`)
- Account administration → Auth service: manages roles (evidence: `frontend/src/features/admin/AdminDashboard.jsx`)
- Auth service → Supabase platform: queries accounts (evidence: `frontend/src/features/auth/authService.js`)
- Role policies → Supabase platform: defines protections (evidence: `README.md`)
- Profile panels → Workspace app: reports profile actions (evidence: `frontend/src/App.jsx`)
- Profile persistence → Browser storage: reads and writes (evidence: `frontend/src/profileService.js`)
- Workspace app → Supabase client: loads client (evidence: `frontend/src/App.jsx`)
- Profile persistence → Supabase platform: syncs names (evidence: `README.md`)
- Profile migration → Supabase platform: creates profile table (evidence: `README.md`)
- Recommendations → Catalog and sample data: reads recommendations (evidence: `frontend/src/features/recommendations/RecommendationPanels.jsx`)
- Setup diagnostics → Catalog and sample data: reads diagnostics (evidence: `frontend/src/features/insights/InsightPanels.jsx`)
- Workspace app → Catalog and sample data: uses recommendations (evidence: `frontend/src/App.jsx`)
- Assistant service → Supabase platform: invokes function (evidence: `frontend/src/features/assistant/assistantService.js`)
- Supabase platform → LOKI chat function: dispatches chat
