# raghavendragg/ai-blog-generator architecture

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

- Interactive diagram: https://gitdiagram.com/raghavendragg/ai-blog-generator
- Repository: https://github.com/raghavendragg/ai-blog-generator

## Overview

##### Project type and purpose
- This is a single‐module, full‐stack style Python application that provides an interactive web UI (Streamlit) and orchestrates a simple graph-based AI agent (LangGraph + LangChain/OpenAI) to generate SEO-friendly blog posts.
- Purpose: Given a user topic, generate a blog title and a 1000-word blog post, stream the results live in the browser, and allow export.

##### File structure
- Top‐level:
- blog_generator_app.py – contains both the Streamlit frontend and the LangGraph orchestration code
- README.md – project documentation and high-level architecture
- .env – environment variables for API keys
- No separate “frontend” or “backend” directories because Streamlit and orchestration logic are co-located.
- Key configurations: .env for API credentials; requirements.txt implied by README; no separate deployment scripts.

##### Extract architecture insights from the README
- Core architectural elements:
- Streamlit UI layer
- LangGraph StateGraph orchestrator
- Two graph nodes: Title Generation and Content Generation
- OpenAI (via LangChain) as the LLM service
- Real-time streaming of partial outputs to the UI
- External dependencies: OpenAI API, optional LangSmith/Groq for monitoring or multimodal extensions.

##### Main components and their interactions
a. Components
- User’s Web Browser (Streamlit frontend)
- Streamlit Server (Python process hosting app)
- LangGraph StateGraph (in-process orchestrator)
- Node A: Title Generation (invokes LLM for title)
- Node B: Content Generation (invokes LLM for body)
- OpenAI API (external LLM endpoint)
- .txt Export Module (local file writer)
- Environment Variables Manager (.env loader)
b. Relationships & data flow
1. User enters topic in the browser →
2. Streamlit Server receives input →
3. Streamlit code initializes a LangGraph StateGraph →
4. StateGraph invokes Node A → calls OpenAI API → streams title back → updates UI →
5. On title completion, StateGraph invokes Node B → calls OpenAI API → streams content back → updates UI →
6. User clicks “Download” → .txt Export Module writes file → delivered to user.
c. Architectural patterns / principles
- Graph-based agent pattern: decouples each processing step into nodes in a StateGraph
- Streaming pipeline: each node emits partial results as they arrive
- Single-page, server-driven UI via Streamlit
d. Key technologies
- Python + Streamlit for UI
- LangGraph for workflow orchestration
- LangChain OpenAI adapter for LLM calls
- python-dotenv for secure config
- OpenAI API (and optional LangSmith/Groq)

## Diagram (Mermaid)

```mermaid
flowchart TD
    %% User layer
    subgraph "User"
        direction TB
        Browser["User Browser"]:::external
    end

    %% Application layer
    subgraph "Application (Python Service)"
        direction TB
        Env[".env Loader"]:::config
        UI["Streamlit UI"]:::internal
        SG["StateGraph Orchestrator"]:::internal
        Title["TitleGen Node (calls LLM)"]:::internal
        Content["ContentGen Node (calls LLM)"]:::internal
        Export[".txt Export Module"]:::internal
    end

    %% External services
    subgraph "External Services"
        direction TB
        OpenAI["OpenAI API"]:::external
    end

    %% Documentation
    Doc["README.md"]:::config

    %% Data Flow
    Browser -->|enters topic| UI
    UI -->|initialize| SG
    SG -->|invoke| Title
    Title -->|request| OpenAI
    OpenAI -->|stream title| Title
    Title -->|streamed title| UI
    UI -->|trigger next| SG
    SG -->|invoke| Content
    Content -->|request| OpenAI
    OpenAI -->|stream content| Content
    Content -->|streamed content| UI
    UI -->|on download click| Export
    Export -->|writes file| Browser

    %% Configuration flow
    Env -.-> UI
    Env -.-> SG

    %% Documentation reference
    Doc -.-> UI

    %% Click Events
    click UI "https://github.com/raghavendragg/ai-blog-generator/blob/main/blog_generator_app.py"
    click SG "https://github.com/raghavendragg/ai-blog-generator/blob/main/blog_generator_app.py"
    click Title "https://github.com/raghavendragg/ai-blog-generator/blob/main/blog_generator_app.py"
    click Content "https://github.com/raghavendragg/ai-blog-generator/blob/main/blog_generator_app.py"
    click Export "https://github.com/raghavendragg/ai-blog-generator/blob/main/blog_generator_app.py"
    click Env "https://github.com/raghavendragg/ai-blog-generator/blob/main/.env"
    click Doc "https://github.com/raghavendragg/ai-blog-generator/blob/main/README.md"

    %% Styles
    classDef internal fill:#D0E8FF,stroke:#0366d6,color:#0366d6;
    classDef external fill:#D4FCE8,stroke:#28a745,color:#28a745;
    classDef config fill:#F0F0F0,stroke:#888888,color:#333333;
```
