# techscholar777/andrew-ng-digital-twin architecture

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

- Interactive diagram: https://gitdiagram.com/techscholar777/andrew-ng-digital-twin
- Repository: https://github.com/techscholar777/andrew-ng-digital-twin

## Overview

Andrew Ng Digital Twin is a full-stack conversational application: a user asks a question in the web chat, the FastAPI service routes the turn, retrieves corpus evidence and contextual memory, generates a streamed answer, and may update the memory graph afterward. The graph also preserves the documented session, adaptive-persona, evidence-inspection, and voice capabilities. Backend call edges are supported by the source index and excerpts; frontend/API and optional voice links are documented in the README. Some UI and service internals were not sampled, so their links are limited to documented relationships.

Main entry points: [`backend/app/routers/chat.py`](https://github.com/techscholar777/andrew-ng-digital-twin/blob/master/backend/app/routers/chat.py) (Chat and service routes), [`frontend/src/app/app/page.tsx`](https://github.com/techscholar777/andrew-ng-digital-twin/blob/master/frontend/src/app/app/page.tsx) (Chat interface), [`backend/app/services/triplet_extractor.py`](https://github.com/techscholar777/andrew-ng-digital-twin/blob/master/backend/app/services/triplet_extractor.py) (Memory extraction), [`backend/app/services/gemini_client.py`](https://github.com/techscholar777/andrew-ng-digital-twin/blob/master/backend/app/services/gemini_client.py) (Gemini generation)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_client["Web client"]
  node_webchat["Chat interface<br/>[page.tsx]"]
  node_sessionui["Session controls<br/>[session-rail.tsx]"]
  node_graphui["Memory graph view"]
  node_graphmap["Graph mapping<br/>[graphMapper.ts]"]
  node_voiceui["Voice controls<br/>[voice-overlay.tsx]"]
end

subgraph group_api["Conversation API"]
  node_api["FastAPI entry<br/>[main.py]"]
  node_chat["Chat and service routes<br/>[chat.py]"]
  node_rate["Rate limiting<br/>[rate_limit.py]"]
  node_stream["Event streaming<br/>[streaming.py]"]
end

subgraph group_reasoning["Answer and retrieval"]
  node_routing["Turn routing<br/>[routing.py]"]
  node_retrieval["Hybrid retrieval<br/>[retrieval.py]"]
  node_embeddings["Text embeddings<br/>[embeddings.py]"]
  node_persona["Adaptive persona<br/>[persona.py]"]
  node_promptcache["Prompt caching<br/>[prompt_cache.py]"]
  node_gemini["Gemini generation<br/>[gemini_client.py]"]
  node_modelconfig["Model configuration<br/>[model_config.py]"]
  node_curriculum["Learning curriculum<br/>[curriculum.py]"]
  node_legacy["Legacy persona engine<br/>[persona_engine.py]"]
  node_chunking["Corpus chunking<br/>[chunking.py]"]
end

subgraph group_memory["Context memory"]
  node_graphmemory["Temporal graph memory<br/>[graph_memory.py]"]
  node_extractor["Memory extraction"]
  node_cleanup["Tenant cleanup<br/>[tenant_cleanup.py]"]
end

subgraph group_voice["Voice experience"]
  node_ttsservice["Optional clone speech"]
  node_browservoice["Browser speech fallback<br/>[browserVoice.ts]"]
end

node_visitor(("Chat user"))
node_database[("PostgreSQL and pgvector")]

node_visitor -->|"asks questions"| node_webchat
node_webchat -->|"sends chat requests"| node_chat
node_chat -->|"classifies turns"| node_routing
node_chat -->|"retrieves evidence"| node_retrieval
node_retrieval -->|"embeds queries"| node_embeddings
node_retrieval -->|"searches passages"| node_database
node_chat -->|"loads context"| node_graphmemory
node_graphmemory -->|"reads graph"| node_database
node_chat -->|"adapts framing"| node_persona
node_chat -->|"builds cached prompts"| node_promptcache
node_promptcache -->|"uses model client"| node_gemini
node_gemini -->|"selects model"| node_modelconfig
node_chat -->|"generates answers"| node_gemini
node_chat -->|"streams events"| node_stream
node_chat -->|"checks limits"| node_rate
node_chat -->|"uses learning context"| node_curriculum
node_chat -->|"schedules extraction"| node_extractor
node_extractor -->|"extracts facts"| node_gemini
node_extractor -->|"updates relations"| node_graphmemory
node_extractor -->|"writes memory"| node_database
node_sessionui -.->|"supports sessions"| node_webchat
node_webchat -->|"shows memory"| node_graphui
node_graphui -.->|"maps graph data"| node_graphmap
node_webchat -->|"offers voice chat"| node_voiceui
node_voiceui -->|"requests synthesis"| node_chat
node_chat -->|"requests clone speech"| node_ttsservice
node_voiceui -->|"falls back to speech"| node_browservoice
node_chat -->|"persists sessions"| node_database
node_api -->|"registers routes"| node_chat

click node_webchat "https://github.com/techscholar777/andrew-ng-digital-twin/blob/master/frontend/src/app/app/page.tsx"
click node_sessionui "https://github.com/techscholar777/andrew-ng-digital-twin/blob/master/frontend/src/components/chat/session-rail.tsx"
click node_graphui "https://github.com/techscholar777/andrew-ng-digital-twin/blob/master/frontend/src/components/KnowledgeGraphView.tsx"
click node_graphmap "https://github.com/techscholar777/andrew-ng-digital-twin/blob/master/frontend/src/lib/graphMapper.ts"
click node_voiceui "https://github.com/techscholar777/andrew-ng-digital-twin/blob/master/frontend/src/components/chat/voice-overlay.tsx"
click node_api "https://github.com/techscholar777/andrew-ng-digital-twin/blob/master/backend/app/main.py"
click node_chat "https://github.com/techscholar777/andrew-ng-digital-twin/blob/master/backend/app/routers/chat.py"
click node_rate "https://github.com/techscholar777/andrew-ng-digital-twin/blob/master/backend/app/services/rate_limit.py"
click node_stream "https://github.com/techscholar777/andrew-ng-digital-twin/blob/master/backend/app/services/streaming.py"
click node_routing "https://github.com/techscholar777/andrew-ng-digital-twin/blob/master/backend/app/services/routing.py"
click node_retrieval "https://github.com/techscholar777/andrew-ng-digital-twin/blob/master/backend/app/services/retrieval.py"
click node_embeddings "https://github.com/techscholar777/andrew-ng-digital-twin/blob/master/backend/app/services/embeddings.py"
click node_persona "https://github.com/techscholar777/andrew-ng-digital-twin/blob/master/backend/app/services/persona.py"
click node_promptcache "https://github.com/techscholar777/andrew-ng-digital-twin/blob/master/backend/app/services/prompt_cache.py"
click node_gemini "https://github.com/techscholar777/andrew-ng-digital-twin/blob/master/backend/app/services/gemini_client.py"
click node_modelconfig "https://github.com/techscholar777/andrew-ng-digital-twin/blob/master/backend/app/services/model_config.py"
click node_curriculum "https://github.com/techscholar777/andrew-ng-digital-twin/blob/master/backend/app/services/curriculum.py"
click node_graphmemory "https://github.com/techscholar777/andrew-ng-digital-twin/blob/master/backend/app/services/graph_memory.py"
click node_extractor "https://github.com/techscholar777/andrew-ng-digital-twin/blob/master/backend/app/services/triplet_extractor.py"
click node_cleanup "https://github.com/techscholar777/andrew-ng-digital-twin/blob/master/backend/app/services/tenant_cleanup.py"
click node_ttsservice "https://github.com/techscholar777/andrew-ng-digital-twin/blob/master/notebooks/kaggle_tts_server.py"
click node_browservoice "https://github.com/techscholar777/andrew-ng-digital-twin/blob/master/frontend/src/lib/browserVoice.ts"
click node_legacy "https://github.com/techscholar777/andrew-ng-digital-twin/blob/master/legacy/persona_engine.py"
click node_chunking "https://github.com/techscholar777/andrew-ng-digital-twin/blob/master/scripts/chunking.py"

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_webchat,node_sessionui,node_graphui,node_graphmap,node_voiceui,node_visitor toneBlue
class node_api,node_chat,node_rate,node_stream,node_database toneAmber
class node_routing,node_retrieval,node_embeddings,node_persona,node_promptcache,node_gemini,node_modelconfig,node_curriculum,node_legacy,node_chunking toneMint
class node_graphmemory,node_extractor,node_cleanup toneRose
class node_ttsservice,node_browservoice toneIndigo
```

## Components

### Web client

- [Chat interface](https://github.com/techscholar777/andrew-ng-digital-twin/blob/master/frontend/src/app/app/page.tsx): `frontend/src/app/app/page.tsx`
- [Session controls](https://github.com/techscholar777/andrew-ng-digital-twin/blob/master/frontend/src/components/chat/session-rail.tsx): `frontend/src/components/chat/session-rail.tsx`
- [Memory graph view](https://github.com/techscholar777/andrew-ng-digital-twin/blob/master/frontend/src/components/KnowledgeGraphView.tsx): `frontend/src/components/KnowledgeGraphView.tsx`
- [Graph mapping](https://github.com/techscholar777/andrew-ng-digital-twin/blob/master/frontend/src/lib/graphMapper.ts): `frontend/src/lib/graphMapper.ts`
- [Voice controls](https://github.com/techscholar777/andrew-ng-digital-twin/blob/master/frontend/src/components/chat/voice-overlay.tsx): `frontend/src/components/chat/voice-overlay.tsx`

### Conversation API

- [FastAPI entry](https://github.com/techscholar777/andrew-ng-digital-twin/blob/master/backend/app/main.py): `backend/app/main.py`
- [Chat and service routes](https://github.com/techscholar777/andrew-ng-digital-twin/blob/master/backend/app/routers/chat.py): `backend/app/routers/chat.py`
- [Rate limiting](https://github.com/techscholar777/andrew-ng-digital-twin/blob/master/backend/app/services/rate_limit.py): `backend/app/services/rate_limit.py`
- [Event streaming](https://github.com/techscholar777/andrew-ng-digital-twin/blob/master/backend/app/services/streaming.py): `backend/app/services/streaming.py`

### Answer and retrieval

- [Turn routing](https://github.com/techscholar777/andrew-ng-digital-twin/blob/master/backend/app/services/routing.py): `backend/app/services/routing.py`
- [Hybrid retrieval](https://github.com/techscholar777/andrew-ng-digital-twin/blob/master/backend/app/services/retrieval.py): `backend/app/services/retrieval.py`
- [Text embeddings](https://github.com/techscholar777/andrew-ng-digital-twin/blob/master/backend/app/services/embeddings.py): `backend/app/services/embeddings.py`
- [Adaptive persona](https://github.com/techscholar777/andrew-ng-digital-twin/blob/master/backend/app/services/persona.py): `backend/app/services/persona.py`
- [Prompt caching](https://github.com/techscholar777/andrew-ng-digital-twin/blob/master/backend/app/services/prompt_cache.py): `backend/app/services/prompt_cache.py`
- [Gemini generation](https://github.com/techscholar777/andrew-ng-digital-twin/blob/master/backend/app/services/gemini_client.py): `backend/app/services/gemini_client.py`
- [Model configuration](https://github.com/techscholar777/andrew-ng-digital-twin/blob/master/backend/app/services/model_config.py): `backend/app/services/model_config.py`
- [Learning curriculum](https://github.com/techscholar777/andrew-ng-digital-twin/blob/master/backend/app/services/curriculum.py): `backend/app/services/curriculum.py`
- [Legacy persona engine](https://github.com/techscholar777/andrew-ng-digital-twin/blob/master/legacy/persona_engine.py): `legacy/persona_engine.py`
- [Corpus chunking](https://github.com/techscholar777/andrew-ng-digital-twin/blob/master/scripts/chunking.py): `scripts/chunking.py`

### Context memory

- [Temporal graph memory](https://github.com/techscholar777/andrew-ng-digital-twin/blob/master/backend/app/services/graph_memory.py): `backend/app/services/graph_memory.py`
- [Memory extraction](https://github.com/techscholar777/andrew-ng-digital-twin/blob/master/backend/app/services/triplet_extractor.py): `backend/app/services/triplet_extractor.py`
- [Tenant cleanup](https://github.com/techscholar777/andrew-ng-digital-twin/blob/master/backend/app/services/tenant_cleanup.py): `backend/app/services/tenant_cleanup.py`

### Voice experience

- [Optional clone speech](https://github.com/techscholar777/andrew-ng-digital-twin/blob/master/notebooks/kaggle_tts_server.py): `notebooks/kaggle_tts_server.py`
- [Browser speech fallback](https://github.com/techscholar777/andrew-ng-digital-twin/blob/master/frontend/src/lib/browserVoice.ts): `frontend/src/lib/browserVoice.ts`

### Other components

- **Chat user**
- **PostgreSQL and pgvector**

## Connections

- Chat user → Chat interface: asks questions
- Chat interface → Chat and service routes: sends chat requests
- Chat and service routes → Turn routing: classifies turns (evidence: `backend/app/routers/chat.py`)
- Chat and service routes → Hybrid retrieval: retrieves evidence (evidence: `backend/app/routers/chat.py`)
- Hybrid retrieval → Text embeddings: embeds queries (evidence: `backend/app/services/retrieval.py`)
- Hybrid retrieval → PostgreSQL and pgvector: searches passages
- Chat and service routes → Temporal graph memory: loads context (evidence: `backend/app/routers/chat.py`)
- Temporal graph memory → PostgreSQL and pgvector: reads graph
- Chat and service routes → Adaptive persona: adapts framing (evidence: `backend/app/routers/chat.py`)
- Chat and service routes → Prompt caching: builds cached prompts (evidence: `backend/app/routers/chat.py`)
- Prompt caching → Gemini generation: uses model client (evidence: `backend/app/services/prompt_cache.py`)
- Gemini generation → Model configuration: selects model (evidence: `backend/app/services/gemini_client.py`)
- Chat and service routes → Gemini generation: generates answers
- Chat and service routes → Event streaming: streams events (evidence: `backend/app/routers/chat.py`)
- Chat and service routes → Rate limiting: checks limits (evidence: `backend/app/routers/chat.py`)
- Chat and service routes → Learning curriculum: uses learning context (evidence: `backend/app/routers/chat.py`)
- Chat and service routes → Memory extraction: schedules extraction (evidence: `backend/app/routers/chat.py`)
- Memory extraction → Gemini generation: extracts facts (evidence: `backend/app/services/triplet_extractor.py`)
- Memory extraction → Temporal graph memory: updates relations (evidence: `backend/app/services/triplet_extractor.py`)
- Memory extraction → PostgreSQL and pgvector: writes memory
- Session controls → Chat interface: supports sessions
- Chat interface → Memory graph view: shows memory
- Memory graph view → Graph mapping: maps graph data
- Chat interface → Voice controls: offers voice chat
- Voice controls → Chat and service routes: requests synthesis
- Chat and service routes → Optional clone speech: requests clone speech
- Voice controls → Browser speech fallback: falls back to speech
- Chat and service routes → PostgreSQL and pgvector: persists sessions
- FastAPI entry → Chat and service routes: registers routes (evidence: `backend/app/main.py`)
