# harsh2b/reddit-persona-generator architecture

> Architecture diagram of the GitHub repository harsh2b/reddit-persona-generator, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2025-07-16). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/harsh2b/reddit-persona-generator
- Repository: https://github.com/harsh2b/reddit-persona-generator

## Overview

##### Project Type & Purpose
- This is a Python-based tool offering two user interfaces:
a. A Command-Line Interface (CLI) script (`persona_generator.py`)
b. A Streamlit-based web app (`app.py`)
- Both interfaces share the same core pipeline: scrape Reddit data, send it to an LLM, then format and save the “persona” output.

##### File Structure & Key Components
- .devcontainer/ → Development environment configuration
- app.py → Streamlit UI entry point
- persona_generator.py → Core orchestrator: coordinates scraping and LLM calls
- reddit_scraper.py → Encapsulates PRAW-based Reddit data retrieval
- requirements.txt → Python dependencies (e.g., praw, groq, streamlit)
- kojied_persona.txt → Example output
- README.md → Setup & usage instructions

##### Core Architectural Elements
a. User Interfaces
- CLI (persona_generator.py)
- Web UI (app.py via Streamlit)
b. Core Service Layer
- PersonaGenerator module (in persona_generator.py)
c. Data Retrieval
- RedditScraper module (in reddit_scraper.py) using PRAW
d. External LLM Service
- Groq API (via HTTP calls)
e. Persistence
- Local filesystem (saves `.txt` files)
f. Configuration
- `.env` for CLI secrets
- `.streamlit/secrets.toml` for web secrets

##### Component Relationships & Data Flow
1. User → CLI (`persona_generator.py`) or User → Browser → Web UI (`app.py`)
2. Interface → PersonaGenerator
3. PersonaGenerator → RedditScraper → Reddit API
4. PersonaGenerator → Groq API (send aggregated comments/posts)
5. Groq API → PersonaGenerator (persona text)
6. PersonaGenerator → Filesystem (write `<username>_persona.txt`)
7. Web UI → displays response & offers download

##### Architectural Patterns & Principles
- Single Responsibility: each Python module has one role (scraping, orchestration, UI)
- Layered design: UI layer delegates to service layer, which depends on external services
- Configuration isolation: secrets are not checked into code but loaded via `.env` or `secrets.toml`

## Diagram (Mermaid)

```mermaid
flowchart TD
    User["User"]:::user
    Browser["Browser"]:::user
    CLI["CLI Interface\n(persona_generator.py)"]:::ui
    WebUI["Web UI Interface\n(app.py)"]:::ui

    subgraph "Core Service Layer"
        PG["PersonaGenerator\n(persona_generator.py)"]:::core
        RS["RedditScraper\n(reddit_scraper.py)"]:::core
    end

    RedditAPI["Reddit API"]:::external
    GroqAPI["Groq API"]:::external
    Filesystem["Filesystem\n(kojied_persona.txt)"]:::storage
    Env[".env"]:::config
    Secrets[".streamlit/secrets.toml"]:::config

    subgraph "Repository Files"
        Dev[".devcontainer\n(devcontainer.json)"]:::config
        Req["requirements.txt"]:::docs
        Readme["README.md"]:::docs
    end

    User --> CLI
    User --> Browser
    Browser --> WebUI

    CLI --> PG
    WebUI --> PG

    CLI --> Env
    WebUI --> Secrets

    PG --> RS
    RS -->|"Reddit posts/comments"| RedditAPI
    PG -->|"LLM prompt"| GroqAPI
    GroqAPI -->|"Persona JSON/text"| PG
    PG --> Filesystem
    WebUI -->|"Display persona & download"| Filesystem

    %% Click Events
    click CLI "https://github.com/harsh2b/reddit-persona-generator/blob/main/persona_generator.py"
    click PG "https://github.com/harsh2b/reddit-persona-generator/blob/main/persona_generator.py"
    click WebUI "https://github.com/harsh2b/reddit-persona-generator/blob/main/app.py"
    click RS "https://github.com/harsh2b/reddit-persona-generator/blob/main/reddit_scraper.py"
    click Dev "https://github.com/harsh2b/reddit-persona-generator/blob/main/.devcontainer/devcontainer.json"
    click Req "https://github.com/harsh2b/reddit-persona-generator/blob/main/requirements.txt"
    click Filesystem "https://github.com/harsh2b/reddit-persona-generator/blob/main/kojied_persona.txt"
    click Readme "https://github.com/harsh2b/reddit-persona-generator/blob/main/README.md"

    classDef ui fill:#D6EFFF,stroke:#0366d6,color:#0366d6,stroke-width:1px
    classDef core fill:#CCE5FF,stroke:#0050b3,color:#003366,stroke-width:1px
    classDef external fill:#E5CCFF,stroke:#800080,color:#400040,stroke-width:1px
    classDef storage fill:#CCFFCC,stroke:#008000,color:#004000,stroke-width:1px
    classDef config fill:#FFF2CC,stroke:#b8860b,color:#6b4f00,stroke-width:1px
    classDef docs fill:#F0F0F0,stroke:#666666,color:#333333,stroke-width:1px
    classDef user fill:#F5F5F5,stroke:#888888,color:#555555,stroke-width:1px
```
