How jadean-aryan/ai_blog_agent works
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: main.py FastAPI App · models.py ORM Models · posts.py Posts Router · sections.py Sections Router
Components 20
Frontend SPA
React/Vite browser client and UI composition
- React SPA · Single-page blog workflow client
frontend/src/App.jsx - Main Pages · Home, editor, history, and login routes
frontend/src/pages - Editor UI · Outline and section editing surface
frontend/src/components/editor - SEO UI · SEO sidebar and score display
frontend/src/components/seo - API Client · Browser integration with backend routers
frontend/src/utils/api.js - UI Helpers · Formatting and score presentation helpers
frontend/src/utils/helpers.js
Backend API
FastAPI application, domain logic, and persistence
- FastAPI App · Application setup and CORS boundary
backend/main.py - Config · Environment-driven backend configuration
backend/config.py - Posts Router · Post lifecycle, outline regeneration, and CRUD
backend/routers/posts.py - Sections Router · Section generation, editing, reordering, and bulk actions
backend/routers/sections.py - SEO Router · SEO analysis and meta-tag generation endpoints
backend/routers/seo.py - Export Router · Markdown and HTML download endpoints
backend/routers/export.py - Auth Router · Login and authentication endpoints
backend/routers/auth.py - LLM Service · OpenAI-compatible model abstraction for writing tasks
backend/services/llm_service.py - SEO Service · Deterministic readability and keyword analysis
backend/services/seo_service.py - Export Service · Markdown and HTML artifact generation
backend/services/export_service.py - ORM Models · SQLAlchemy entities for posts and related records
backend/models/models.py - Pydantic Schemas · Request and response data contracts
backend/schemas/schemas.py
External Services
Datastore and model providers
- MySQL 8 · Persistent system of record for blog content
schema.sql - LLM Provider · OpenAI-compatible model endpoint used by the backend
Connections 26
- 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