# ymffuture/sonatg architecture

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

- Interactive diagram: https://gitdiagram.com/ymffuture/sonatg
- Repository: https://github.com/ymffuture/sonatg

## Overview

SonaTG is a chat application with an “Ask Sona” message-intelligence feature. The main user flow is entering the authenticated chat, viewing and acting on messages, and optionally asking Sona about a message; other product areas include calls, classroom polls, moderation, administration, and billing. The tree and excerpts support several links, but most feature files were not sampled, so the graph omits unverified wiring rather than implying a complete runtime sequence.

Main entry points: [`src/components/SonaChat.tsx`](https://github.com/ymffuture/sonatg/blob/main/src/components/SonaChat.tsx) (Chat interface), [`src/integrations/supabase/client.ts`](https://github.com/ymffuture/sonatg/blob/main/src/integrations/supabase/client.ts) (Supabase client), [`src/features/moderation/useMessageModeration.ts`](https://github.com/ymffuture/sonatg/blob/main/src/features/moderation/useMessageModeration.ts) (Moderation check), [`src/components/CallManager.tsx`](https://github.com/ymffuture/sonatg/blob/main/src/components/CallManager.tsx) (Voice and video calls)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_app["Chat experience"]
  node_chat["Chat interface<br/>[SonaChat.tsx]"]
  node_message_bubble["Message actions<br/>[MessageBubble.tsx]"]
  node_calls["Voice and video calls<br/>[CallManager.tsx]"]
  node_call_overlay["Call overlay<br/>[CallOverlay.tsx]"]
  node_thread_panel["Message threads<br/>[ThreadPanel.tsx]"]
end

subgraph group_intelligence["AI and moderation"]
  node_ask_panel["Ask Sona panel<br/>[AskSonaPanel.tsx]"]
  node_message_intelligence["Message intelligence"]
  node_ai_functions["AI gateway<br/>[ai.functions.ts]"]
  node_moderation_hook["Moderation check"]
  node_detection["Local detection<br/>[detectionEngine.ts]"]
  node_blocked_words["Blocked-word rules<br/>[blockedWords.ts]"]
  node_ai_moderation["AI moderation"]
  node_verdict_merge["Verdict merging<br/>[mergeVerdicts.ts]"]
end

subgraph group_platform["Identity and data"]
  node_auth_route["Sign-in<br/>[auth.tsx]"]
  node_auth_guard["Authenticated routes<br/>[route.tsx]"]
  node_supabase_client["Supabase client<br/>[client.ts]"]
  node_preview_storage["Preview auth storage"]
  node_db["Application database access<br/>[db.ts]"]
end

subgraph group_product["Product features"]
  node_classroom["Classroom polls"]
  node_admin["Administration<br/>[admin.tsx]"]
  node_billing["Billing and plans<br/>[billing.tsx]"]
end

node_user(("Chat user"))

node_user -->|"signs in"| node_auth_route
node_auth_route -->|"checks session"| node_supabase_client
node_user -.->|"opens protected area"| node_auth_guard
node_auth_guard -->|"validates user"| node_supabase_client
node_supabase_client -->|"configures storage"| node_preview_storage
node_user -.->|"uses chat"| node_chat
node_chat -->|"renders messages"| node_message_bubble
node_message_bubble -->|"raises Ask Sona action"| node_chat
node_chat -->|"renders panel"| node_ask_panel
node_ask_panel -.->|"requests answer"| node_message_intelligence
node_message_intelligence -->|"reuses gateway"| node_ai_functions
node_moderation_hook -->|"evaluates message"| node_detection
node_detection -->|"loads word rules"| node_blocked_words
node_moderation_hook -->|"requests classification"| node_ai_moderation
node_moderation_hook -->|"merges verdicts"| node_verdict_merge
node_verdict_merge -->|"uses classifier result"| node_ai_moderation
node_calls -->|"uses realtime client"| node_supabase_client
node_calls -->|"renders overlay"| node_call_overlay

click node_auth_route "https://github.com/ymffuture/sonatg/blob/main/src/routes/auth.tsx"
click node_auth_guard "https://github.com/ymffuture/sonatg/blob/main/src/routes/_authenticated/route.tsx"
click node_supabase_client "https://github.com/ymffuture/sonatg/blob/main/src/integrations/supabase/client.ts"
click node_preview_storage "https://github.com/ymffuture/sonatg/blob/main/src/integrations/supabase/previewAuthStorage.ts"
click node_chat "https://github.com/ymffuture/sonatg/blob/main/src/components/SonaChat.tsx"
click node_message_bubble "https://github.com/ymffuture/sonatg/blob/main/src/components/MessageBubble.tsx"
click node_ask_panel "https://github.com/ymffuture/sonatg/blob/main/src/components/AskSonaPanel.tsx"
click node_message_intelligence "https://github.com/ymffuture/sonatg/blob/main/src/lib/messageIntelligence.functions.ts"
click node_ai_functions "https://github.com/ymffuture/sonatg/blob/main/src/lib/ai.functions.ts"
click node_moderation_hook "https://github.com/ymffuture/sonatg/blob/main/src/features/moderation/useMessageModeration.ts"
click node_detection "https://github.com/ymffuture/sonatg/blob/main/src/features/moderation/detectionEngine.ts"
click node_blocked_words "https://github.com/ymffuture/sonatg/blob/main/src/features/moderation/blockedWords.ts"
click node_ai_moderation "https://github.com/ymffuture/sonatg/blob/main/src/features/moderation/aiModeration.functions.ts"
click node_verdict_merge "https://github.com/ymffuture/sonatg/blob/main/src/features/moderation/mergeVerdicts.ts"
click node_calls "https://github.com/ymffuture/sonatg/blob/main/src/components/CallManager.tsx"
click node_call_overlay "https://github.com/ymffuture/sonatg/blob/main/src/components/CallOverlay.tsx"
click node_thread_panel "https://github.com/ymffuture/sonatg/blob/main/src/components/chat/ThreadPanel.tsx"
click node_classroom "https://github.com/ymffuture/sonatg/tree/main/src/features/classroom"
click node_admin "https://github.com/ymffuture/sonatg/blob/main/src/features/adimn/admin.tsx"
click node_billing "https://github.com/ymffuture/sonatg/blob/main/src/routes/billing.tsx"
click node_db "https://github.com/ymffuture/sonatg/blob/main/src/lib/db.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_chat,node_message_bubble,node_calls,node_call_overlay,node_thread_panel,node_user toneBlue
class node_ask_panel,node_message_intelligence,node_ai_functions,node_moderation_hook,node_detection,node_blocked_words,node_ai_moderation,node_verdict_merge toneAmber
class node_auth_route,node_auth_guard,node_supabase_client,node_preview_storage,node_db toneMint
class node_classroom,node_admin,node_billing toneRose
```

## Components

### Chat experience

- [Chat interface](https://github.com/ymffuture/sonatg/blob/main/src/components/SonaChat.tsx): `src/components/SonaChat.tsx`
- [Message actions](https://github.com/ymffuture/sonatg/blob/main/src/components/MessageBubble.tsx): `src/components/MessageBubble.tsx`
- [Voice and video calls](https://github.com/ymffuture/sonatg/blob/main/src/components/CallManager.tsx): `src/components/CallManager.tsx`
- [Call overlay](https://github.com/ymffuture/sonatg/blob/main/src/components/CallOverlay.tsx): `src/components/CallOverlay.tsx`
- [Message threads](https://github.com/ymffuture/sonatg/blob/main/src/components/chat/ThreadPanel.tsx): `src/components/chat/ThreadPanel.tsx`

### AI and moderation

- [Ask Sona panel](https://github.com/ymffuture/sonatg/blob/main/src/components/AskSonaPanel.tsx): `src/components/AskSonaPanel.tsx`
- [Message intelligence](https://github.com/ymffuture/sonatg/blob/main/src/lib/messageIntelligence.functions.ts): `src/lib/messageIntelligence.functions.ts`
- [AI gateway](https://github.com/ymffuture/sonatg/blob/main/src/lib/ai.functions.ts): `src/lib/ai.functions.ts`
- [Moderation check](https://github.com/ymffuture/sonatg/blob/main/src/features/moderation/useMessageModeration.ts): `src/features/moderation/useMessageModeration.ts`
- [Local detection](https://github.com/ymffuture/sonatg/blob/main/src/features/moderation/detectionEngine.ts): `src/features/moderation/detectionEngine.ts`
- [Blocked-word rules](https://github.com/ymffuture/sonatg/blob/main/src/features/moderation/blockedWords.ts): `src/features/moderation/blockedWords.ts`
- [AI moderation](https://github.com/ymffuture/sonatg/blob/main/src/features/moderation/aiModeration.functions.ts): `src/features/moderation/aiModeration.functions.ts`
- [Verdict merging](https://github.com/ymffuture/sonatg/blob/main/src/features/moderation/mergeVerdicts.ts): `src/features/moderation/mergeVerdicts.ts`

### Identity and data

- [Sign-in](https://github.com/ymffuture/sonatg/blob/main/src/routes/auth.tsx): `src/routes/auth.tsx`
- [Authenticated routes](https://github.com/ymffuture/sonatg/blob/main/src/routes/_authenticated/route.tsx): `src/routes/_authenticated/route.tsx`
- [Supabase client](https://github.com/ymffuture/sonatg/blob/main/src/integrations/supabase/client.ts): `src/integrations/supabase/client.ts`
- [Preview auth storage](https://github.com/ymffuture/sonatg/blob/main/src/integrations/supabase/previewAuthStorage.ts): `src/integrations/supabase/previewAuthStorage.ts`
- [Application database access](https://github.com/ymffuture/sonatg/blob/main/src/lib/db.ts): `src/lib/db.ts`

### Product features

- [Classroom polls](https://github.com/ymffuture/sonatg/tree/main/src/features/classroom): `src/features/classroom`
- [Administration](https://github.com/ymffuture/sonatg/blob/main/src/features/adimn/admin.tsx): `src/features/adimn/admin.tsx`
- [Billing and plans](https://github.com/ymffuture/sonatg/blob/main/src/routes/billing.tsx): `src/routes/billing.tsx`

### Other components

- **Chat user**

## Connections

- Chat user → Sign-in: signs in (evidence: `src/routes/auth.tsx`)
- Sign-in → Supabase client: checks session (evidence: `src/routes/auth.tsx`)
- Chat user → Authenticated routes: opens protected area
- Authenticated routes → Supabase client: validates user (evidence: `src/routes/_authenticated/route.tsx`)
- Supabase client → Preview auth storage: configures storage (evidence: `src/integrations/supabase/client.ts`)
- Chat user → Chat interface: uses chat
- Chat interface → Message actions: renders messages (evidence: `README.md`)
- Message actions → Chat interface: raises Ask Sona action (evidence: `README.md`)
- Chat interface → Ask Sona panel: renders panel (evidence: `README.md`)
- Ask Sona panel → Message intelligence: requests answer
- Message intelligence → AI gateway: reuses gateway (evidence: `README.md`)
- Moderation check → Local detection: evaluates message (evidence: `src/features/moderation/useMessageModeration.ts`)
- Local detection → Blocked-word rules: loads word rules (evidence: `src/features/moderation/detectionEngine.ts`)
- Moderation check → AI moderation: requests classification (evidence: `src/features/moderation/useMessageModeration.ts`)
- Moderation check → Verdict merging: merges verdicts (evidence: `src/features/moderation/useMessageModeration.ts`)
- Verdict merging → AI moderation: uses classifier result (evidence: `src/features/moderation/mergeVerdicts.ts`)
- Voice and video calls → Supabase client: uses realtime client (evidence: `src/components/CallManager.tsx`)
- Voice and video calls → Call overlay: renders overlay (evidence: `src/components/CallManager.tsx`)
