# sarth28/jlpt-grammar-chatbot architecture

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

- Interactive diagram: https://gitdiagram.com/sarth28/jlpt-grammar-chatbot
- Repository: https://github.com/sarth28/jlpt-grammar-chatbot

## Overview

Sensei-AI lets a student ask a JLPT grammar question in a Streamlit chat, retrieves a matching grammar point from MySQL-backed data using sentence embeddings, and asks a language model to explain it. The main.py module also loads the dataset into MySQL at startup and precomputes embeddings for retrieval. The README documents the frontend/backend split, database, semantic search, and environment configuration. The dataset and external services are not included in the tree; relationships shown here are limited to the supplied source and README.

Main entry points: [`main.py`](https://github.com/sarth28/jlpt-grammar-chatbot/blob/main/main.py) (Ask endpoint), [`app.py`](https://github.com/sarth28/jlpt-grammar-chatbot/blob/main/app.py) (Streamlit chat)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_frontend["Chat interface"]
  node_chat["Streamlit chat<br/>[app.py]"]
end

subgraph group_backend["Tutoring backend"]
  node_ask_api["Ask endpoint<br/>[main.py]"]
  node_response_generation["Response generation<br/>[main.py]"]
  node_environment["Environment config"]
end

subgraph group_data["Grammar data and retrieval"]
  node_retrieval["Grammar retrieval<br/>[main.py]"]
  node_sentence_model["Sentence encoder<br/>[main.py]"]
  node_dataset["JLPT dataset"]
  node_mysql[("MySQL grammar table<br/>[main.py]")]
end

node_student(("Student"))
node_groq{{"Groq language model"}}

node_student -->|"asks"| node_chat
node_chat -->|"requests"| node_ask_api
node_ask_api -->|"retrieves"| node_retrieval
node_retrieval -->|"encodes and ranks"| node_sentence_model
node_retrieval -->|"reads grammar"| node_mysql
node_dataset -->|"loads into"| node_mysql
node_ask_api -->|"generates answer"| node_response_generation
node_response_generation -->|"requests completion"| node_groq
node_environment -->|"configures key"| node_response_generation
node_ask_api -->|"returns answer"| node_chat

click node_chat "https://github.com/sarth28/jlpt-grammar-chatbot/blob/main/app.py"
click node_ask_api "https://github.com/sarth28/jlpt-grammar-chatbot/blob/main/main.py"
click node_retrieval "https://github.com/sarth28/jlpt-grammar-chatbot/blob/main/main.py"
click node_sentence_model "https://github.com/sarth28/jlpt-grammar-chatbot/blob/main/main.py"
click node_mysql "https://github.com/sarth28/jlpt-grammar-chatbot/blob/main/main.py"
click node_response_generation "https://github.com/sarth28/jlpt-grammar-chatbot/blob/main/main.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 toneBlue
class node_ask_api,node_response_generation,node_environment toneAmber
class node_retrieval,node_sentence_model,node_dataset,node_mysql toneMint
class node_student,node_groq toneIndigo
```

## Components

### Chat interface

- [Streamlit chat](https://github.com/sarth28/jlpt-grammar-chatbot/blob/main/app.py): `app.py`

### Tutoring backend

- [Ask endpoint](https://github.com/sarth28/jlpt-grammar-chatbot/blob/main/main.py): `main.py`
- [Response generation](https://github.com/sarth28/jlpt-grammar-chatbot/blob/main/main.py): `main.py`
- **Environment config**

### Grammar data and retrieval

- [Grammar retrieval](https://github.com/sarth28/jlpt-grammar-chatbot/blob/main/main.py): `main.py`
- [Sentence encoder](https://github.com/sarth28/jlpt-grammar-chatbot/blob/main/main.py): `main.py`
- **JLPT dataset**
- [MySQL grammar table](https://github.com/sarth28/jlpt-grammar-chatbot/blob/main/main.py): `main.py`

### Other components

- **Student**
- **Groq language model**

## Connections

- Student → Streamlit chat: asks (evidence: `app.py`)
- Streamlit chat → Ask endpoint: requests (evidence: `app.py`)
- Ask endpoint → Grammar retrieval: retrieves (evidence: `main.py`)
- Grammar retrieval → Sentence encoder: encodes and ranks (evidence: `main.py`)
- Grammar retrieval → MySQL grammar table: reads grammar (evidence: `main.py`)
- JLPT dataset → MySQL grammar table: loads into (evidence: `main.py`)
- Ask endpoint → Response generation: generates answer (evidence: `main.py`)
- Response generation → Groq language model: requests completion (evidence: `main.py`)
- Environment config → Response generation: configures key (evidence: `main.py`)
- Ask endpoint → Streamlit chat: returns answer (evidence: `app.py`)
