# ndrvndr/ai-toxic-moderator architecture

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

- Interactive diagram: https://gitdiagram.com/ndrvndr/ai-toxic-moderator
- Repository: https://github.com/ndrvndr/ai-toxic-moderator

## Overview

AI Toxic Moderator is a dashboard and backend for moderating Indonesian YouTube Live Chat. A channel owner signs in, selects a broadcast, and starts monitoring; the API records a run that the worker polls, ingests chat for, and evaluates for blacklist and AI moderation. The worker may plan and execute guarded moderation actions, while the dashboard receives live updates and exposes controls, settings, and saved history. The graph keeps these product stages distinct. Several capabilities are documented but their implementation was not sampled, so those links cite the README rather than implying source inspection.

Main entry points: [`apps/dashboard/lib/api-client.ts`](https://github.com/ndrvndr/ai-toxic-moderator/blob/main/apps/dashboard/lib/api-client.ts) (API client), [`apps/worker/src/ingestion/automatic-ai-cycle.ts`](https://github.com/ndrvndr/ai-toxic-moderator/blob/main/apps/worker/src/ingestion/automatic-ai-cycle.ts) (Moderation cycles), [`apps/dashboard/features/live/components/live-page.tsx`](https://github.com/ndrvndr/ai-toxic-moderator/blob/main/apps/dashboard/features/live/components/live-page.tsx) (Live controls), [`apps/api/src/monitoring/monitoring.service.ts`](https://github.com/ndrvndr/ai-toxic-moderator/blob/main/apps/api/src/monitoring/monitoring.service.ts) (Monitoring lifecycle)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_dashboard["Dashboard"]
  node_dashboard_auth["Login and session<br/>[login-page.tsx]"]
  node_dashboard_live["Live controls<br/>[live-page.tsx]"]
  node_dashboard_chat["Live chat"]
  node_dashboard_history["History reports<br/>[history-page.tsx]"]
  node_dashboard_settings["Moderation settings"]
  node_dashboard_client["API client<br/>[api-client.ts]"]
end

subgraph group_api["API"]
  node_api_auth["OAuth and sessions<br/>[google.service.ts]"]
  node_api_monitoring["Monitoring lifecycle"]
  node_api_chat["Chat endpoints<br/>[chat.module.ts]"]
  node_api_live["Live events and access<br/>[live.gateway.ts]"]
  node_api_history["Saved sessions"]
  node_api_settings["Settings endpoints"]
  node_api_database["API database access<br/>[database.module.ts]"]
end

subgraph group_worker["Worker"]
  node_worker_runtime["Worker runtime<br/>[worker-runtime.ts]"]
  node_worker_coordinator["Ingestion coordinator<br/>[coordinator.ts]"]
  node_worker_poll["Polling and leases<br/>[poll-cycle.ts]"]
  node_worker_persist["Batch persistence<br/>[batch-writer.ts]"]
  node_worker_moderation["Moderation cycles"]
  node_worker_actions["Action execution<br/>[ban-executor.ts]"]
  node_worker_ai["AI inference and planning"]
end

subgraph group_moderation["Moderation"]
  node_core_rules["Moderation rules<br/>[rule-engine.ts]"]
  node_core_planning["Action planning"]
end

subgraph group_shared["Shared packages"]
  node_contracts["Shared contracts"]
  node_persistence["Persistence utilities<br/>[live-events.ts]"]
end

node_owner(("Channel owner"))
node_database[("PostgreSQL")]
node_youtube["YouTube services"]
node_google["Google OAuth"]

node_owner -->|"signs in"| node_dashboard_auth
node_dashboard_auth -->|"requests session"| node_dashboard_client
node_dashboard_client -->|"authenticates"| node_api_auth
node_api_auth -->|"authorizes"| node_google
node_owner -->|"selects broadcast"| node_dashboard_live
node_dashboard_live -->|"requests monitoring"| node_dashboard_client
node_dashboard_client -->|"starts or stops"| node_api_monitoring
node_api_monitoring -->|"verifies ownership"| node_youtube
node_api_monitoring -->|"records run"| node_database
node_worker_runtime -->|"ticks"| node_worker_coordinator
node_worker_coordinator -->|"coordinates polling"| node_worker_poll
node_worker_poll -->|"retrieves chat"| node_youtube
node_worker_coordinator -->|"persists batches"| node_worker_persist
node_worker_persist -->|"writes observations"| node_database
node_worker_moderation -.->|"checks messages"| node_core_rules
node_worker_moderation -.->|"evaluates AI"| node_worker_ai
node_worker_ai -.->|"plans actions"| node_core_planning
node_worker_moderation -->|"dispatches actions"| node_worker_actions
node_worker_actions -->|"applies moderation"| node_youtube
node_dashboard_live -->|"opens updates"| node_api_live
node_api_live -->|"streams events"| node_dashboard_chat
node_dashboard_chat -->|"requests decisions"| node_api_chat
node_dashboard_history -->|"loads saved history"| node_api_history
node_dashboard_settings -->|"saves settings"| node_api_settings
node_api_settings -->|"stores revisions"| node_database
node_api_history -->|"reads sessions"| node_database
node_api_database -->|"creates pool"| node_persistence
node_worker_persist -.->|"uses ingestion types"| node_contracts

click node_dashboard_auth "https://github.com/ndrvndr/ai-toxic-moderator/blob/main/apps/dashboard/features/auth/components/login-page.tsx"
click node_dashboard_live "https://github.com/ndrvndr/ai-toxic-moderator/blob/main/apps/dashboard/features/live/components/live-page.tsx"
click node_dashboard_chat "https://github.com/ndrvndr/ai-toxic-moderator/blob/main/apps/dashboard/features/live/components/live-chat-panel.tsx"
click node_dashboard_history "https://github.com/ndrvndr/ai-toxic-moderator/blob/main/apps/dashboard/features/history/components/history-page.tsx"
click node_dashboard_settings "https://github.com/ndrvndr/ai-toxic-moderator/blob/main/apps/dashboard/features/moderation-settings/components/moderation-settings-page.tsx"
click node_dashboard_client "https://github.com/ndrvndr/ai-toxic-moderator/blob/main/apps/dashboard/lib/api-client.ts"
click node_api_auth "https://github.com/ndrvndr/ai-toxic-moderator/blob/main/apps/api/src/auth/google.service.ts"
click node_api_monitoring "https://github.com/ndrvndr/ai-toxic-moderator/blob/main/apps/api/src/monitoring/monitoring.service.ts"
click node_api_chat "https://github.com/ndrvndr/ai-toxic-moderator/blob/main/apps/api/src/chat/chat.module.ts"
click node_api_live "https://github.com/ndrvndr/ai-toxic-moderator/blob/main/apps/api/src/live/live.gateway.ts"
click node_api_history "https://github.com/ndrvndr/ai-toxic-moderator/blob/main/apps/api/src/live/saved-sessions.controller.ts"
click node_api_settings "https://github.com/ndrvndr/ai-toxic-moderator/blob/main/apps/api/src/settings/ai-moderation-settings.service.ts"
click node_api_database "https://github.com/ndrvndr/ai-toxic-moderator/blob/main/apps/api/src/database.module.ts"
click node_worker_runtime "https://github.com/ndrvndr/ai-toxic-moderator/blob/main/apps/worker/src/ingestion/worker-runtime.ts"
click node_worker_coordinator "https://github.com/ndrvndr/ai-toxic-moderator/blob/main/apps/worker/src/ingestion/coordinator.ts"
click node_worker_poll "https://github.com/ndrvndr/ai-toxic-moderator/blob/main/apps/worker/src/ingestion/poll-cycle.ts"
click node_worker_persist "https://github.com/ndrvndr/ai-toxic-moderator/blob/main/apps/worker/src/ingestion/batch-writer.ts"
click node_worker_moderation "https://github.com/ndrvndr/ai-toxic-moderator/blob/main/apps/worker/src/ingestion/automatic-ai-cycle.ts"
click node_worker_actions "https://github.com/ndrvndr/ai-toxic-moderator/blob/main/apps/worker/src/ingestion/ban-executor.ts"
click node_worker_ai "https://github.com/ndrvndr/ai-toxic-moderator/blob/main/apps/worker/src/ingestion/ai-shadow-runner.ts"
click node_core_rules "https://github.com/ndrvndr/ai-toxic-moderator/blob/main/packages/moderation-core/src/rule-engine.ts"
click node_core_planning "https://github.com/ndrvndr/ai-toxic-moderator/blob/main/packages/moderation-core/src/ai-action-planner.ts"
click node_contracts "https://github.com/ndrvndr/ai-toxic-moderator/blob/main/packages/contracts/src/youtube-ingestion.ts"
click node_persistence "https://github.com/ndrvndr/ai-toxic-moderator/blob/main/packages/persistence/src/live-events.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_dashboard_auth,node_dashboard_live,node_dashboard_chat,node_dashboard_history,node_dashboard_settings,node_dashboard_client toneBlue
class node_api_auth,node_api_monitoring,node_api_chat,node_api_live,node_api_history,node_api_settings,node_api_database,node_database toneAmber
class node_worker_runtime,node_worker_coordinator,node_worker_poll,node_worker_persist,node_worker_moderation,node_worker_actions,node_worker_ai toneMint
class node_core_rules,node_core_planning toneRose
class node_contracts,node_persistence,node_owner,node_youtube,node_google toneIndigo
```

## Components

### Dashboard

- [Login and session](https://github.com/ndrvndr/ai-toxic-moderator/blob/main/apps/dashboard/features/auth/components/login-page.tsx): `apps/dashboard/features/auth/components/login-page.tsx`
- [Live controls](https://github.com/ndrvndr/ai-toxic-moderator/blob/main/apps/dashboard/features/live/components/live-page.tsx): `apps/dashboard/features/live/components/live-page.tsx`
- [Live chat](https://github.com/ndrvndr/ai-toxic-moderator/blob/main/apps/dashboard/features/live/components/live-chat-panel.tsx): `apps/dashboard/features/live/components/live-chat-panel.tsx`
- [History reports](https://github.com/ndrvndr/ai-toxic-moderator/blob/main/apps/dashboard/features/history/components/history-page.tsx): `apps/dashboard/features/history/components/history-page.tsx`
- [Moderation settings](https://github.com/ndrvndr/ai-toxic-moderator/blob/main/apps/dashboard/features/moderation-settings/components/moderation-settings-page.tsx): `apps/dashboard/features/moderation-settings/components/moderation-settings-page.tsx`
- [API client](https://github.com/ndrvndr/ai-toxic-moderator/blob/main/apps/dashboard/lib/api-client.ts): `apps/dashboard/lib/api-client.ts`

### API

- [OAuth and sessions](https://github.com/ndrvndr/ai-toxic-moderator/blob/main/apps/api/src/auth/google.service.ts): `apps/api/src/auth/google.service.ts`
- [Monitoring lifecycle](https://github.com/ndrvndr/ai-toxic-moderator/blob/main/apps/api/src/monitoring/monitoring.service.ts): `apps/api/src/monitoring/monitoring.service.ts`
- [Chat endpoints](https://github.com/ndrvndr/ai-toxic-moderator/blob/main/apps/api/src/chat/chat.module.ts): `apps/api/src/chat/chat.module.ts`
- [Live events and access](https://github.com/ndrvndr/ai-toxic-moderator/blob/main/apps/api/src/live/live.gateway.ts): `apps/api/src/live/live.gateway.ts`
- [Saved sessions](https://github.com/ndrvndr/ai-toxic-moderator/blob/main/apps/api/src/live/saved-sessions.controller.ts): `apps/api/src/live/saved-sessions.controller.ts`
- [Settings endpoints](https://github.com/ndrvndr/ai-toxic-moderator/blob/main/apps/api/src/settings/ai-moderation-settings.service.ts): `apps/api/src/settings/ai-moderation-settings.service.ts`
- [API database access](https://github.com/ndrvndr/ai-toxic-moderator/blob/main/apps/api/src/database.module.ts): `apps/api/src/database.module.ts`

### Worker

- [Worker runtime](https://github.com/ndrvndr/ai-toxic-moderator/blob/main/apps/worker/src/ingestion/worker-runtime.ts): `apps/worker/src/ingestion/worker-runtime.ts`
- [Ingestion coordinator](https://github.com/ndrvndr/ai-toxic-moderator/blob/main/apps/worker/src/ingestion/coordinator.ts): `apps/worker/src/ingestion/coordinator.ts`
- [Polling and leases](https://github.com/ndrvndr/ai-toxic-moderator/blob/main/apps/worker/src/ingestion/poll-cycle.ts): `apps/worker/src/ingestion/poll-cycle.ts`
- [Batch persistence](https://github.com/ndrvndr/ai-toxic-moderator/blob/main/apps/worker/src/ingestion/batch-writer.ts): `apps/worker/src/ingestion/batch-writer.ts`
- [Moderation cycles](https://github.com/ndrvndr/ai-toxic-moderator/blob/main/apps/worker/src/ingestion/automatic-ai-cycle.ts): `apps/worker/src/ingestion/automatic-ai-cycle.ts`
- [Action execution](https://github.com/ndrvndr/ai-toxic-moderator/blob/main/apps/worker/src/ingestion/ban-executor.ts): `apps/worker/src/ingestion/ban-executor.ts`
- [AI inference and planning](https://github.com/ndrvndr/ai-toxic-moderator/blob/main/apps/worker/src/ingestion/ai-shadow-runner.ts): `apps/worker/src/ingestion/ai-shadow-runner.ts`

### Moderation

- [Moderation rules](https://github.com/ndrvndr/ai-toxic-moderator/blob/main/packages/moderation-core/src/rule-engine.ts): `packages/moderation-core/src/rule-engine.ts`
- [Action planning](https://github.com/ndrvndr/ai-toxic-moderator/blob/main/packages/moderation-core/src/ai-action-planner.ts): `packages/moderation-core/src/ai-action-planner.ts`

### Shared packages

- [Shared contracts](https://github.com/ndrvndr/ai-toxic-moderator/blob/main/packages/contracts/src/youtube-ingestion.ts): `packages/contracts/src/youtube-ingestion.ts`
- [Persistence utilities](https://github.com/ndrvndr/ai-toxic-moderator/blob/main/packages/persistence/src/live-events.ts): `packages/persistence/src/live-events.ts`

### Other components

- **Channel owner**
- **PostgreSQL**
- **YouTube services**
- **Google OAuth**

## Connections

- Channel owner → Login and session: signs in
- Login and session → API client: requests session
- API client → OAuth and sessions: authenticates
- OAuth and sessions → Google OAuth: authorizes
- Channel owner → Live controls: selects broadcast
- Live controls → API client: requests monitoring
- API client → Monitoring lifecycle: starts or stops
- Monitoring lifecycle → YouTube services: verifies ownership
- Monitoring lifecycle → PostgreSQL: records run (evidence: `apps/api/src/monitoring/monitoring.service.ts`)
- Worker runtime → Ingestion coordinator: ticks (evidence: `apps/worker/src/ingestion/worker-runtime.ts`)
- Ingestion coordinator → Polling and leases: coordinates polling (evidence: `apps/worker/src/ingestion/coordinator.ts`)
- Polling and leases → YouTube services: retrieves chat
- Ingestion coordinator → Batch persistence: persists batches (evidence: `apps/worker/src/ingestion/coordinator.ts`)
- Batch persistence → PostgreSQL: writes observations
- Moderation cycles → Moderation rules: checks messages
- Moderation cycles → AI inference and planning: evaluates AI
- AI inference and planning → Action planning: plans actions
- Moderation cycles → Action execution: dispatches actions
- Action execution → YouTube services: applies moderation
- Live controls → Live events and access: opens updates
- Live events and access → Live chat: streams events
- Live chat → Chat endpoints: requests decisions
- History reports → Saved sessions: loads saved history
- Moderation settings → Settings endpoints: saves settings
- Settings endpoints → PostgreSQL: stores revisions
- Saved sessions → PostgreSQL: reads sessions
- API database access → Persistence utilities: creates pool (evidence: `apps/api/src/database.module.ts`)
- Batch persistence → Shared contracts: uses ingestion types
