# jadean-aryan/ai_blog_agent architecture

> Architecture diagram of the GitHub repository jadean-aryan/ai_blog_agent, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2026-06-02). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/jadean-aryan/ai_blog_agent
- Repository: https://github.com/jadean-aryan/ai_blog_agent

## Overview

1. **Overall shape**
   - BlogForge is a two-tier application: a **React/Vite single-page frontend** and a **FastAPI backend**.
   - The backend is the system of record; the frontend is a client that calls REST endpoints for content generation, SEO analysis, history, and export.

2. **Primary user workflow**
   - The core flow is: **topic entry → outline generation → section drafting → SEO analysis → export**.
   - This is not just a CRUD app: the backend orchestrates multiple generation and analysis steps around a post lifecycle.

3. **Backend API boundary**
   - `backend/main.py` exposes the FastAPI app and configures CORS for the browser client.
   - The API is split into routers by responsibility:
     - `posts.py` for post creation, listing, updates, deletion, and outline regeneration
     - `sections.py` for section generation, editing, reordering, and bulk generation
     - `seo.py` for analysis and meta-tag generation
     - `export.py` for markdown/HTML download
     - `auth.py` for login/auth-related endpoints

4. **Backend domain model and persistence**
   - Persistence is handled with **async SQLAlchemy** and a **MySQL 8** schema defined in `schema.sql`.
   - The `models/` and `schemas/` folders separate ORM entities from Pydantic request/response contracts.
   - The data model centers on posts, outlines/sections, SEO analyses, and exportable generated content; the README indicates a small, focused schema rather than a general-purpose CMS.

5. **LLM orchestration layer**
   - `services/llm_service.py` is the abstraction for all AI calls.
   - It targets an **OpenAI-compatible API** and can point at Groq, Together, or OpenAI via configuration.
   - This service is the main external dependency for content generation: it produces outlines, section copy, metadata, and related generation outputs.

6. **SEO analysis subsystem**
   - `services/seo_service.py` computes deterministic SEO metrics on the server:
     - keyword density
     - heading hierarchy quality
     - Flesch readability
     - word count
     - meta tag quality
   - The SEO pipeline is separate from LLM generation, which matters architecturally: analysis is algorithmic and reproducible, while writing is model-driven.

7. **Export subsystem**
   - `services/export_service.py` converts post content into **Markdown** and **HTML**.
   - This is an output boundary distinct from editing and analysis, so the architecture supports both browser editing and downloadable artifacts.

8. **Frontend structure**
   - The frontend is a **React 18 + Vite + Tailwind CSS** SPA.
   - Main pages reflect the product flow:
     - `HomePage.jsx` for topic setup
     - `EditorPage.jsx` for outline/section editing and SEO review
     - `HistoryPage.jsx` for prior posts and score trends
     - `LoginPage.jsx` for authentication entry

9. **Editor and SEO UI split**
   - The editor experience is broken into focused components:
     - `SectionEditor.jsx` for per-section editing/regeneration
     - `OutlinePanel.jsx` for reorderable section navigation
     - `SEOSidebar.jsx` for analysis details
     - `ScoreRing.jsx` for visual score presentation
   - This mirrors the backend separation between content editing, SEO evaluation, and generation.

10. **Client-server data flow**
   - The frontend does not contain business logic for SEO scoring or content generation; it delegates these to `frontend/src/utils/api.js`.
   - That API layer is the main integration point from the SPA into the backend routers.
   - `helpers.js` is used for presentation logic such as score coloring and formatting, not for authoritative content processing.

11. **Configuration and runtime**
   - Backend runtime depends on Python 3.11+, FastAPI, async SQLAlchemy, and environment-based settings in `backend/config.py`.
   - Frontend runtime depends on Node.js 18+.
   - The app expects a MySQL instance initialized once with `schema.sql`, then the backend can create/read/update the content graph.

12. **Architectural boundary to external services**
   - The only major external service is the **LLM provider** accessed through the backend.
   - That keeps model keys and provider URLs out of the browser, and lets the backend own generation policy, SEO scoring, and export formatting.

13. **What an architecture diagram should emphasize**
   - Put the **browser SPA** on one side, the **FastAPI API** in the middle, and two major backend dependencies behind it: **MySQL** and **LLM API**.
   - Within the backend, show four functional zones: **posts/orchestration**, **sections/editor ops**, **SEO analysis**, and **export**.
   - The main data object flowing through the system is a **blog post with associated outline sections, SEO analysis records, and export artifacts**.

14. **Ancillary feature**
   - The presence of `auth.py` and `LoginPage.jsx` indicates an authentication boundary, but the repository’s core architecture is still the content-generation pipeline rather than a heavily permissioned system.

Main entry points: [`backend/main.py`](https://github.com/jadean-aryan/ai_blog_agent/blob/main/backend/main.py) (FastAPI App), [`backend/models/models.py`](https://github.com/jadean-aryan/ai_blog_agent/blob/main/backend/models/models.py) (ORM Models), [`backend/routers/posts.py`](https://github.com/jadean-aryan/ai_blog_agent/blob/main/backend/routers/posts.py) (Posts Router), [`backend/routers/sections.py`](https://github.com/jadean-aryan/ai_blog_agent/blob/main/backend/routers/sections.py) (Sections Router)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_frontend["Frontend SPA"]
  node_frontend_app["React SPA<br/>web client<br/>[App.jsx]"]
  node_frontend_pages["Main Pages<br/>screens"]
  node_frontend_editor["Editor UI<br/>editing components"]
  node_frontend_seo["SEO UI<br/>analysis components"]
  node_frontend_api["API Client<br/>http client<br/>[api.js]"]
  node_frontend_helpers["UI Helpers<br/>presentation utils<br/>[helpers.js]"]
end

subgraph group_backend["Backend API"]
  node_backend_main["FastAPI App<br/>api entrypoint<br/>[main.py]"]
  node_backend_config["Config<br/>settings<br/>[config.py]"]
  node_backend_posts["Posts Router<br/>content orchestration<br/>[posts.py]"]
  node_backend_sections["Sections Router<br/>section ops<br/>[sections.py]"]
  node_backend_seo["SEO Router<br/>analysis API<br/>[seo.py]"]
  node_backend_export["Export Router<br/>export API<br/>[export.py]"]
  node_backend_auth["Auth Router<br/>auth boundary<br/>[auth.py]"]
  node_backend_llm["LLM Service<br/>generation service<br/>[llm_service.py]"]
  node_backend_seo_service["SEO Service<br/>metrics service<br/>[seo_service.py]"]
  node_backend_export_service["Export Service<br/>formatting service<br/>[export_service.py]"]
  node_backend_models["ORM Models<br/>persistence model<br/>[models.py]"]
  node_backend_schemas["Pydantic Schemas<br/>contracts<br/>[schemas.py]"]
end

subgraph group_external["External Services"]
  node_mysql[("MySQL 8<br/>database<br/>[schema.sql]")]
  node_llm_api{{"LLM Provider<br/>external API"}}
end

node_frontend_app -->|"renders"| node_frontend_pages
node_frontend_pages -->|"uses"| node_frontend_editor
node_frontend_pages -->|"uses"| node_frontend_seo
node_frontend_app -->|"calls"| node_frontend_api
node_frontend_editor -->|"requests"| node_frontend_api
node_frontend_seo -->|"formats"| node_frontend_helpers
node_frontend_api -->|"HTTP"| node_backend_main
node_backend_main -->|"loads"| node_backend_config
node_backend_main -->|"mounts"| node_backend_posts
node_backend_main -->|"mounts"| node_backend_sections
node_backend_main -->|"mounts"| node_backend_seo
node_backend_main -->|"mounts"| node_backend_export
node_backend_main -->|"mounts"| node_backend_auth
node_backend_posts -->|"generates"| node_backend_llm
node_backend_sections -->|"generates"| node_backend_llm
node_backend_seo -->|"analyzes"| node_backend_seo_service
node_backend_export -->|"formats"| node_backend_export_service
node_backend_posts -->|"persists"| node_backend_models
node_backend_sections -->|"persists"| node_backend_models
node_backend_seo -->|"reads/writes"| node_backend_models
node_backend_export -->|"reads"| node_backend_models
node_backend_models -->|"SQLAlchemy"| node_mysql
node_backend_schemas -->|"validates"| node_backend_posts
node_backend_schemas -->|"validates"| node_backend_sections
node_backend_schemas -->|"validates"| node_backend_seo
node_backend_llm -->|"uses"| node_llm_api

click node_frontend_app "https://github.com/jadean-aryan/ai_blog_agent/blob/main/frontend/src/App.jsx"
click node_frontend_pages "https://github.com/jadean-aryan/ai_blog_agent/tree/main/frontend/src/pages"
click node_frontend_editor "https://github.com/jadean-aryan/ai_blog_agent/tree/main/frontend/src/components/editor"
click node_frontend_seo "https://github.com/jadean-aryan/ai_blog_agent/tree/main/frontend/src/components/seo"
click node_frontend_api "https://github.com/jadean-aryan/ai_blog_agent/blob/main/frontend/src/utils/api.js"
click node_frontend_helpers "https://github.com/jadean-aryan/ai_blog_agent/blob/main/frontend/src/utils/helpers.js"
click node_backend_main "https://github.com/jadean-aryan/ai_blog_agent/blob/main/backend/main.py"
click node_backend_config "https://github.com/jadean-aryan/ai_blog_agent/blob/main/backend/config.py"
click node_backend_posts "https://github.com/jadean-aryan/ai_blog_agent/blob/main/backend/routers/posts.py"
click node_backend_sections "https://github.com/jadean-aryan/ai_blog_agent/blob/main/backend/routers/sections.py"
click node_backend_seo "https://github.com/jadean-aryan/ai_blog_agent/blob/main/backend/routers/seo.py"
click node_backend_export "https://github.com/jadean-aryan/ai_blog_agent/blob/main/backend/routers/export.py"
click node_backend_auth "https://github.com/jadean-aryan/ai_blog_agent/blob/main/backend/routers/auth.py"
click node_backend_llm "https://github.com/jadean-aryan/ai_blog_agent/blob/main/backend/services/llm_service.py"
click node_backend_seo_service "https://github.com/jadean-aryan/ai_blog_agent/blob/main/backend/services/seo_service.py"
click node_backend_export_service "https://github.com/jadean-aryan/ai_blog_agent/blob/main/backend/services/export_service.py"
click node_backend_models "https://github.com/jadean-aryan/ai_blog_agent/blob/main/backend/models/models.py"
click node_backend_schemas "https://github.com/jadean-aryan/ai_blog_agent/blob/main/backend/schemas/schemas.py"
click node_mysql "https://github.com/jadean-aryan/ai_blog_agent/blob/main/schema.sql"

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_frontend_app,node_frontend_pages,node_frontend_editor,node_frontend_seo,node_frontend_api,node_frontend_helpers toneBlue
class node_backend_main,node_backend_config,node_backend_posts,node_backend_sections,node_backend_seo,node_backend_export,node_backend_auth,node_backend_llm,node_backend_seo_service,node_backend_export_service,node_backend_models,node_backend_schemas toneAmber
class node_mysql,node_llm_api toneMint
```

## Components

### Frontend SPA

React/Vite browser client and UI composition

- [React SPA](https://github.com/jadean-aryan/ai_blog_agent/blob/main/frontend/src/App.jsx): web client · Single-page blog workflow client · `frontend/src/App.jsx`
- [Main Pages](https://github.com/jadean-aryan/ai_blog_agent/tree/main/frontend/src/pages): screens · Home, editor, history, and login routes · `frontend/src/pages`
- [Editor UI](https://github.com/jadean-aryan/ai_blog_agent/tree/main/frontend/src/components/editor): editing components · Outline and section editing surface · `frontend/src/components/editor`
- [SEO UI](https://github.com/jadean-aryan/ai_blog_agent/tree/main/frontend/src/components/seo): analysis components · SEO sidebar and score display · `frontend/src/components/seo`
- [API Client](https://github.com/jadean-aryan/ai_blog_agent/blob/main/frontend/src/utils/api.js): http client · Browser integration with backend routers · `frontend/src/utils/api.js`
- [UI Helpers](https://github.com/jadean-aryan/ai_blog_agent/blob/main/frontend/src/utils/helpers.js): presentation utils · Formatting and score presentation helpers · `frontend/src/utils/helpers.js`

### Backend API

FastAPI application, domain logic, and persistence

- [FastAPI App](https://github.com/jadean-aryan/ai_blog_agent/blob/main/backend/main.py): api entrypoint · Application setup and CORS boundary · `backend/main.py`
- [Config](https://github.com/jadean-aryan/ai_blog_agent/blob/main/backend/config.py): settings · Environment-driven backend configuration · `backend/config.py`
- [Posts Router](https://github.com/jadean-aryan/ai_blog_agent/blob/main/backend/routers/posts.py): content orchestration · Post lifecycle, outline regeneration, and CRUD · `backend/routers/posts.py`
- [Sections Router](https://github.com/jadean-aryan/ai_blog_agent/blob/main/backend/routers/sections.py): section ops · Section generation, editing, reordering, and bulk actions · `backend/routers/sections.py`
- [SEO Router](https://github.com/jadean-aryan/ai_blog_agent/blob/main/backend/routers/seo.py): analysis API · SEO analysis and meta-tag generation endpoints · `backend/routers/seo.py`
- [Export Router](https://github.com/jadean-aryan/ai_blog_agent/blob/main/backend/routers/export.py): export API · Markdown and HTML download endpoints · `backend/routers/export.py`
- [Auth Router](https://github.com/jadean-aryan/ai_blog_agent/blob/main/backend/routers/auth.py): auth boundary · Login and authentication endpoints · `backend/routers/auth.py`
- [LLM Service](https://github.com/jadean-aryan/ai_blog_agent/blob/main/backend/services/llm_service.py): generation service · OpenAI-compatible model abstraction for writing tasks · `backend/services/llm_service.py`
- [SEO Service](https://github.com/jadean-aryan/ai_blog_agent/blob/main/backend/services/seo_service.py): metrics service · Deterministic readability and keyword analysis · `backend/services/seo_service.py`
- [Export Service](https://github.com/jadean-aryan/ai_blog_agent/blob/main/backend/services/export_service.py): formatting service · Markdown and HTML artifact generation · `backend/services/export_service.py`
- [ORM Models](https://github.com/jadean-aryan/ai_blog_agent/blob/main/backend/models/models.py): persistence model · SQLAlchemy entities for posts and related records · `backend/models/models.py`
- [Pydantic Schemas](https://github.com/jadean-aryan/ai_blog_agent/blob/main/backend/schemas/schemas.py): contracts · Request and response data contracts · `backend/schemas/schemas.py`

### External Services

Datastore and model providers

- [MySQL 8](https://github.com/jadean-aryan/ai_blog_agent/blob/main/schema.sql): database · Persistent system of record for blog content · `schema.sql`
- **LLM Provider**: external API · OpenAI-compatible model endpoint used by the backend

## Connections

- React SPA → Main Pages: renders · SPA routes into product screens
- Main Pages → Editor UI: uses · Editor page composes outline and section tools
- Main Pages → SEO UI: uses · Editor and history surfaces show SEO feedback
- React SPA → API Client: calls · UI delegates all backend communication
- Editor UI → API Client: requests · Editing actions trigger API calls
- SEO UI → UI Helpers: formats · Presentation logic for scores and badges
- API Client → FastAPI App: HTTP · Browser client talks to FastAPI app
- FastAPI App → Config: loads · Startup configuration and CORS settings
- FastAPI App → Posts Router: mounts · Primary content workflow routes
- FastAPI App → Sections Router: mounts · Section editing and generation routes
- FastAPI App → SEO Router: mounts · SEO analysis routes
- FastAPI App → Export Router: mounts · Export routes
- FastAPI App → Auth Router: mounts · Authentication routes
- Posts Router → LLM Service: generates · Outline and post generation use model calls
- Sections Router → LLM Service: generates · Section drafting and regeneration use model calls
- SEO Router → SEO Service: analyzes · Deterministic SEO metrics and scores
- Export Router → Export Service: formats · Content conversion into downloadable artifacts
- Posts Router → ORM Models: persists · Post lifecycle data stored in ORM entities
- Sections Router → ORM Models: persists · Section records and ordering saved in database models
- SEO Router → ORM Models: reads/writes · SEO results associated with posts
- Export Router → ORM Models: reads · Exports are built from stored post content
- ORM Models → MySQL 8: SQLAlchemy · Async persistence to MySQL schema
- Pydantic Schemas → Posts Router: validates · Request and response contracts for post operations
- Pydantic Schemas → Sections Router: validates · Contracts for section operations
- Pydantic Schemas → SEO Router: validates · Contracts for SEO endpoints
- LLM Service → LLM Provider: uses · Backend forwards generation requests to provider
