# yoangelica/studygen architecture

> Architecture diagram of the GitHub repository yoangelica/studygen, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2025-05-23). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/yoangelica/studygen
- Repository: https://github.com/yoangelica/studygen

## Overview

##### Project type and purpose
- StudyGen is a lightweight, single‐repository “full-stack” Python application.
- It exposes a Streamlit web UI (frontend) and a RAG (Retrieval-Augmented Generation) backend pipeline in one service.
- Purpose: let users upload source materials (PDFs, web pages, YouTube URLs), store embeddings, and generate exam-style questions via local LLMs.

##### File structure
- Top level:
- README.md, pyproject.toml, .env/.gitignore – project config and dependencies
- src/app.py – Streamlit UI code
- src/rag.py – RAG pipeline (document loading, chunking, embeddings, vector store, LLM calls)
- No separate “frontend” or “backend” services; both live in the Python process.
- External services invoked:
- Ollama (LLM + embedding models)
- Chroma (local vector database)
- LangSmith (for tracing/logging)

##### Extract architecture insights from README
- Orchestration: LangChain
- Embeddings: nomic-embed-text via Ollama
- Question generation: llama3.2 via Ollama
- Storage: Chroma vector store
- UI: Streamlit served by “uv run streamlit”

##### Main components
a. Streamlit Web UI (Component A)
b. RAG Orchestrator (Component B – src/rag.py with LangChain)
c. Vector Store (Component C – local Chroma DB)
d. Embedding & LLM Service (Component D – Ollama daemon hosting: nomic-embed-text & llama3.2)
e. External Tracing/Logging (Component E – LangSmith API)
f. User-provided Content Source (Component F – PDFs, URLs, YouTube)

##### Relationships and interactions
- User (browser) ► Streamlit UI
- UI ► RAG Orchestrator (passes uploaded content metadata)
- Orchestrator ► Embedding Service (“nomic-embed-text” via Ollama) ► Vector Store (Chroma)
- Orchestrator ► LLM Service (“llama3.2” via Ollama) ► Generated questions ► UI
- Orchestrator ► LangSmith API (trace calls, logging)
- Vector Store persists embeddings locally between sessions

##### Architectural patterns & design principles
- Modular separation: UI layer vs. RAG pipeline layer
- Micro-service-style integration with Ollama & Chroma as external dependencies
- Single process vs. external “model as a service” components
- RAG pattern: embedding + vector retrieval + generation

##### Technologies & frameworks
- Python + Streamlit (web UI)
- LangChain (RAG orchestration)
- Ollama (local LLM/embedding service)
- Chroma (local vector DB)
- LangSmith (API for observability/tracing)

- Use arrowheads to show request/response or data flow
- Data flows: “Chunks → embeddings,” “Query → retrieval,” “Prompt → generation”
- Environment variables (.env) near the UI or orchestrator for configuration context

## Diagram (Mermaid)

```mermaid
flowchart TD
    %% User Interaction
    User["User (Browser)"]:::external
    Content["User Content Sources\n(PDFs, URLs, YouTube)"]:::external

    %% Frontend Layer
    A(["Streamlit Web UI\n(src/app.py)"]):::frontend

    %% Backend Orchestration
    B["RAG Orchestrator\n(src/rag.py)"]:::backend

    %% Data Store
    C[(Chroma Vector Store)]:::datastore

    %% External Model Service
    D["Ollama Service\n(nomic-embed-text & llama3.2)"]:::external

    %% External Tracing/Logging
    E["LangSmith API"]:::external

    %% Project Config & Ignore
    Config["Project Config\n(pyproject.toml)"]:::external
    Gitignore["Project Ignore Rules\n(.gitignore)"]:::external

    %% Flows
    User -->|"Access UI"| A
    Content -->|"Upload materials"| A
    A -->|"Pass metadata"| B

    B -->|"Chunks → embeddings"| D
    D -->|"Store embeddings"| C

    B -->|"Query → retrieval"| C
    B -->|"Prompt → generation"| D
    D -->|"Generated questions"| A

    B -->|"Trace events"| E

    %% Config & Ignore context
    Config --- A
    Config --- B
    Gitignore --- C

    %% Click Events
    click A "https://github.com/yoangelica/studygen/blob/main/src/app.py"
    click B "https://github.com/yoangelica/studygen/blob/main/src/rag.py"
    click C "https://github.com/yoangelica/studygen/blob/main/src/rag.py"
    click D "https://github.com/yoangelica/studygen/blob/main/src/rag.py"
    click E "https://github.com/yoangelica/studygen/blob/main/src/rag.py"
    click Config "https://github.com/yoangelica/studygen/blob/main/pyproject.toml"
    click Gitignore "https://github.com/yoangelica/studygen/blob/main/.gitignore"

    %% Styles
    classDef frontend fill:#aecbfa,stroke:#1f77b4,color:#1f77b4;
    classDef backend fill:#c5e1a5,stroke:#2e7d32,color:#2e7d32;
    classDef datastore fill:#ffcc80,stroke:#ef6c00,color:#ef6c00;
    classDef external fill:#e0e0e0,stroke:#757575,color:#424242;
```
