# yashasvi1914/ai-chatbot architecture

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

- Interactive diagram: https://gitdiagram.com/yashasvi1914/ai-chatbot
- Repository: https://github.com/yashasvi1914/ai-chatbot

## Overview

This repository implements a browser-based AI chatbot with a FastAPI backend. The main workflow sends a user message from the frontend to the chat endpoint, generates a Gemini response, converts it to HTML, and displays it. The backend also exposes separate YouTube transcript retrieval and transcript summarization endpoints; the README does not document these capabilities, but they are explicit in the sampled API source. No transcript or summary UI is shown. The graph follows visible calls and routes; external Gemini and YouTube service details are limited to what the source demonstrates.

Main entry points: [`backend/index.py`](https://github.com/yashasvi1914/ai-chatbot/blob/main/backend/index.py) (Chat endpoint), [`frontend/app.js`](https://github.com/yashasvi1914/ai-chatbot/blob/main/frontend/app.js) (Chat interface), [`backend/gemini_service.py`](https://github.com/yashasvi1914/ai-chatbot/blob/main/backend/gemini_service.py) (Gemini generation service)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_client["Chat client"]
  node_chat_ui["Chat interface<br/>[app.js]"]
end

subgraph group_api["Backend API"]
  node_fastapi["FastAPI application<br/>[index.py]"]
  node_chat_endpoint["Chat endpoint<br/>[index.py]"]
  node_markdown_render["Markdown conversion<br/>[index.py]"]
  node_transcript_endpoint["Transcript endpoint<br/>[index.py]"]
  node_summarize_endpoint["Summarization endpoint<br/>[index.py]"]
  node_prompt_builder["Study prompt<br/>[index.py]"]
  node_json_extract["Structured result parsing<br/>[index.py]"]
end

subgraph group_ai["AI services"]
  node_gemini_service["Gemini generation service<br/>[gemini_service.py]"]
end

node_browser_user(("User"))
node_youtube_transcripts["YouTube transcript API"]
node_gemini["Google Gemini"]

node_browser_user -->|"enters messages"| node_chat_ui
node_chat_ui -->|"posts message"| node_chat_endpoint
node_fastapi -->|"registers route"| node_chat_endpoint
node_chat_endpoint -->|"generates reply"| node_gemini_service
node_gemini_service -->|"requests generation"| node_gemini
node_chat_endpoint -->|"converts reply"| node_markdown_render
node_chat_endpoint -->|"returns HTML reply"| node_chat_ui
node_fastapi -->|"registers route"| node_transcript_endpoint
node_transcript_endpoint -->|"fetches transcript"| node_youtube_transcripts
node_fastapi -->|"registers route"| node_summarize_endpoint
node_summarize_endpoint -->|"builds prompt"| node_prompt_builder
node_summarize_endpoint -->|"generates study material"| node_gemini_service
node_summarize_endpoint -->|"parses model output"| node_json_extract

click node_chat_ui "https://github.com/yashasvi1914/ai-chatbot/blob/main/frontend/app.js"
click node_fastapi "https://github.com/yashasvi1914/ai-chatbot/blob/main/backend/index.py"
click node_chat_endpoint "https://github.com/yashasvi1914/ai-chatbot/blob/main/backend/index.py"
click node_markdown_render "https://github.com/yashasvi1914/ai-chatbot/blob/main/backend/index.py"
click node_transcript_endpoint "https://github.com/yashasvi1914/ai-chatbot/blob/main/backend/index.py"
click node_summarize_endpoint "https://github.com/yashasvi1914/ai-chatbot/blob/main/backend/index.py"
click node_prompt_builder "https://github.com/yashasvi1914/ai-chatbot/blob/main/backend/index.py"
click node_json_extract "https://github.com/yashasvi1914/ai-chatbot/blob/main/backend/index.py"
click node_gemini_service "https://github.com/yashasvi1914/ai-chatbot/blob/main/backend/gemini_service.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_chat_ui,node_browser_user toneBlue
class node_fastapi,node_chat_endpoint,node_markdown_render,node_transcript_endpoint,node_summarize_endpoint,node_prompt_builder,node_json_extract toneAmber
class node_gemini_service,node_youtube_transcripts toneMint
class node_gemini toneIndigo
```

## Components

### Chat client

- [Chat interface](https://github.com/yashasvi1914/ai-chatbot/blob/main/frontend/app.js): `frontend/app.js`

### Backend API

- [FastAPI application](https://github.com/yashasvi1914/ai-chatbot/blob/main/backend/index.py): `backend/index.py`
- [Chat endpoint](https://github.com/yashasvi1914/ai-chatbot/blob/main/backend/index.py): `backend/index.py`
- [Markdown conversion](https://github.com/yashasvi1914/ai-chatbot/blob/main/backend/index.py): `backend/index.py`
- [Transcript endpoint](https://github.com/yashasvi1914/ai-chatbot/blob/main/backend/index.py): `backend/index.py`
- [Summarization endpoint](https://github.com/yashasvi1914/ai-chatbot/blob/main/backend/index.py): `backend/index.py`
- [Study prompt](https://github.com/yashasvi1914/ai-chatbot/blob/main/backend/index.py): `backend/index.py`
- [Structured result parsing](https://github.com/yashasvi1914/ai-chatbot/blob/main/backend/index.py): `backend/index.py`

### AI services

- [Gemini generation service](https://github.com/yashasvi1914/ai-chatbot/blob/main/backend/gemini_service.py): `backend/gemini_service.py`

### Other components

- **User**
- **YouTube transcript API**
- **Google Gemini**

## Connections

- User → Chat interface: enters messages (evidence: `frontend/app.js`)
- Chat interface → Chat endpoint: posts message (evidence: `frontend/app.js`)
- FastAPI application → Chat endpoint: registers route (evidence: `backend/index.py`)
- Chat endpoint → Gemini generation service: generates reply (evidence: `backend/index.py`)
- Gemini generation service → Google Gemini: requests generation (evidence: `backend/gemini_service.py`)
- Chat endpoint → Markdown conversion: converts reply (evidence: `backend/index.py`)
- Chat endpoint → Chat interface: returns HTML reply (evidence: `frontend/app.js`)
- FastAPI application → Transcript endpoint: registers route (evidence: `backend/index.py`)
- Transcript endpoint → YouTube transcript API: fetches transcript (evidence: `backend/index.py`)
- FastAPI application → Summarization endpoint: registers route (evidence: `backend/index.py`)
- Summarization endpoint → Study prompt: builds prompt (evidence: `backend/index.py`)
- Summarization endpoint → Gemini generation service: generates study material (evidence: `backend/index.py`)
- Summarization endpoint → Structured result parsing: parses model output (evidence: `backend/index.py`)
