# bhushan4work/roastmyblog architecture

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

- Interactive diagram: https://gitdiagram.com/bhushan4work/roastmyblog
- Repository: https://github.com/bhushan4work/roastmyblog

## Overview

#### Purpose and Runtime
RoastMyBlog is a unified Next.js 15 full-stack application that accepts blog URLs or pasted text, extracts/analyzes writing, generates AI critique, and stores analysis history. It runs as a React 19 client UI plus Next.js route handlers, backed by MongoDB and Google/Groq AI APIs.

Key entry points:
- `src/app/page.tsx`
- `src/app/layout.tsx`
- `src/app/api/analyze/route.ts`
- `src/app/api/stats/route.ts`

#### Client Interaction Layer
The root page coordinates user submission, loading state, API calls, and result rendering. Presentation is separated into focused UI components for the landing/input experience, progress indication, and returned roast content.

- `src/app/page.tsx`
- `src/components/Hero.tsx`
- `src/components/Results.tsx`
- `src/components/Loading.tsx`

#### HTTP API Boundary
Next.js route handlers are the server boundary between browser interactions and backend workflows. The analysis endpoint is the primary orchestration entry point; the stats endpoint exposes persisted-history-derived data to the UI.

- `src/app/api/analyze/route.ts`
- `src/app/api/stats/route.ts`
- `src/lib/api.ts`

#### Content Acquisition and Normalization
Submitted URLs require server-side fetching and article extraction before analysis. The scraper service, supported by Cheerio, JSDOM, and Readability, isolates usable blog text; text utilities provide shared cleanup or preparation behavior before downstream analyzers and model prompts consume it.

- `src/services/scraperService.ts`
- `src/utils/textUtil.ts`

#### Analysis Pipeline
Analysis combines local deterministic assessments with AI-generated feedback. Readability and structure analyzers establish writing-specific signals, while the analyzer service composes these signals and the extracted or pasted source into the application’s final analysis workflow.

- `src/services/analyzerService.ts`
- `src/analyzers/readabilityAnalyzer.ts`
- `src/analyzers/structureAnalyzer.ts`

#### AI Provider Integration
AI generation is isolated behind a service boundary rather than called directly from routes or components. `groqService` represents the external LLM integration; the README also establishes Google Generative AI as a required provider. This boundary is where provider prompts, requests, failures, and model responses should remain contained.

- `src/services/groqService.ts`
- `src/services/analyzerService.ts`

#### Persistence and Domain Model
Completed analyses are persisted as roast/history records in MongoDB. The database service owns persistence operations, while the model defines the stored domain shape. API handlers and analysis orchestration should exchange typed application data rather than database-specific structures where possible.

- `src/models/Roast.ts`
- `src/services/roastDbService.ts`
- `src/types/index.ts`

#### Infrastructure and External Dependencies
Deployment requires Node.js, a Next.js-compatible runtime, and environment-provided credentials: `MONGODB_URI`, `GOOGLE_API_KEY`, and `GROQ_API_KEY`. External boundaries include arbitrary target websites for scraping, MongoDB/Atlas for history, and Google/Groq model APIs for critique generation. Styling is application-local through Tailwind and global CSS, not a separate frontend service.

- `next.config.ts`
- `src/app/globals.css`
- `tailwind.config.ts`

Main entry points: [`src/services/analyzerService.ts`](https://github.com/bhushan4work/roastmyblog/blob/main/src/services/analyzerService.ts) (Analysis orchestrator), [`src/app/page.tsx`](https://github.com/bhushan4work/roastmyblog/blob/main/src/app/page.tsx) (Root page), [`src/app/api/analyze/route.ts`](https://github.com/bhushan4work/roastmyblog/blob/main/src/app/api/analyze/route.ts) (Analyze endpoint), [`src/services/roastDbService.ts`](https://github.com/bhushan4work/roastmyblog/blob/main/src/services/roastDbService.ts) (Roast repository)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_client["React client"]
  node_layout["App layout<br/>Next.js layout<br/>[layout.tsx]"]
  node_page["Root page<br/>React coordinator<br/>[page.tsx]"]
  node_hero["Input landing<br/>React component<br/>[Hero.tsx]"]
  node_loading["Progress UI<br/>React component<br/>[Loading.tsx]"]
  node_results["Roast results<br/>React component<br/>[Results.tsx]"]
  node_api_client["API client<br/>HTTP helper<br/>[api.ts]"]
end

subgraph group_server["Next.js server"]
  node_analyze_route["Analyze endpoint<br/>Route handler<br/>[route.ts]"]
  node_stats_route["Stats endpoint<br/>Route handler<br/>[route.ts]"]
end

subgraph group_analysis["Analysis pipeline"]
  node_scraper["Article extraction<br/>Scraper service<br/>[scraperService.ts]"]
  node_text_util["Text preparation<br/>Text utility<br/>[textUtil.ts]"]
  node_analyzer["Analysis orchestrator<br/>Analyzer service<br/>[analyzerService.ts]"]
  node_readability["Readability signals<br/>Analyzer"]
  node_structure["Structure signals<br/>Analyzer"]
  node_groq["LLM gateway<br/>AI provider service<br/>[groqService.ts]"]
end

subgraph group_data["Persistence"]
  node_roast_db["Roast repository<br/>Database service<br/>[roastDbService.ts]"]
  node_roast_model["Roast record<br/>Domain model<br/>[Roast.ts]"]
  node_types["Application types<br/>Type contracts<br/>[index.ts]"]
end

subgraph group_external["External systems"]
  node_websites(("Target websites<br/>External content"))
  node_mongodb[("MongoDB / Atlas<br/>Database")]
  node_ai_providers(("Groq and Google AI<br/>Model APIs"))
end

node_layout -->|"hosts"| node_page
node_page -->|"renders"| node_hero
node_page -->|"renders state"| node_loading
node_page -->|"renders"| node_results
node_page -->|"submits via"| node_api_client
node_api_client -->|"analyze request"| node_analyze_route
node_api_client -->|"history stats"| node_stats_route
node_analyze_route -->|"URL source"| node_scraper
node_scraper -->|"fetches"| node_websites
node_scraper -->|"normalizes"| node_text_util
node_analyze_route -->|"source text"| node_analyzer
node_text_util -->|"prepared text"| node_analyzer
node_analyzer -->|"measures"| node_readability
node_analyzer -->|"measures"| node_structure
node_analyzer -->|"requests critique"| node_groq
node_groq -->|"generates via"| node_ai_providers
node_analyze_route -->|"persists result"| node_roast_db
node_stats_route -->|"queries history"| node_roast_db
node_roast_db -->|"stores"| node_roast_model
node_roast_db -->|"reads and writes"| node_mongodb
node_analyze_route -.->|"uses contracts"| node_types
node_analyzer -.->|"returns typed data"| node_types

click node_layout "https://github.com/bhushan4work/roastmyblog/blob/main/src/app/layout.tsx"
click node_page "https://github.com/bhushan4work/roastmyblog/blob/main/src/app/page.tsx"
click node_hero "https://github.com/bhushan4work/roastmyblog/blob/main/src/components/Hero.tsx"
click node_loading "https://github.com/bhushan4work/roastmyblog/blob/main/src/components/Loading.tsx"
click node_results "https://github.com/bhushan4work/roastmyblog/blob/main/src/components/Results.tsx"
click node_api_client "https://github.com/bhushan4work/roastmyblog/blob/main/src/lib/api.ts"
click node_analyze_route "https://github.com/bhushan4work/roastmyblog/blob/main/src/app/api/analyze/route.ts"
click node_stats_route "https://github.com/bhushan4work/roastmyblog/blob/main/src/app/api/stats/route.ts"
click node_scraper "https://github.com/bhushan4work/roastmyblog/blob/main/src/services/scraperService.ts"
click node_text_util "https://github.com/bhushan4work/roastmyblog/blob/main/src/utils/textUtil.ts"
click node_analyzer "https://github.com/bhushan4work/roastmyblog/blob/main/src/services/analyzerService.ts"
click node_readability "https://github.com/bhushan4work/roastmyblog/blob/main/src/analyzers/readabilityAnalyzer.ts"
click node_structure "https://github.com/bhushan4work/roastmyblog/blob/main/src/analyzers/structureAnalyzer.ts"
click node_groq "https://github.com/bhushan4work/roastmyblog/blob/main/src/services/groqService.ts"
click node_roast_db "https://github.com/bhushan4work/roastmyblog/blob/main/src/services/roastDbService.ts"
click node_roast_model "https://github.com/bhushan4work/roastmyblog/blob/main/src/models/Roast.ts"
click node_types "https://github.com/bhushan4work/roastmyblog/blob/main/src/types/index.ts"

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_layout,node_page,node_hero,node_loading,node_results,node_api_client toneBlue
class node_analyze_route,node_stats_route toneAmber
class node_scraper,node_text_util,node_analyzer,node_readability,node_structure,node_groq toneMint
class node_roast_db,node_roast_model,node_types toneRose
class node_websites,node_mongodb,node_ai_providers toneIndigo
```

## Components

### React client

- [App layout](https://github.com/bhushan4work/roastmyblog/blob/main/src/app/layout.tsx): Next.js layout · `src/app/layout.tsx`
- [Root page](https://github.com/bhushan4work/roastmyblog/blob/main/src/app/page.tsx): React coordinator · Owns submission, loading state, and result rendering. · `src/app/page.tsx`
- [Input landing](https://github.com/bhushan4work/roastmyblog/blob/main/src/components/Hero.tsx): React component · `src/components/Hero.tsx`
- [Progress UI](https://github.com/bhushan4work/roastmyblog/blob/main/src/components/Loading.tsx): React component · `src/components/Loading.tsx`
- [Roast results](https://github.com/bhushan4work/roastmyblog/blob/main/src/components/Results.tsx): React component · `src/components/Results.tsx`
- [API client](https://github.com/bhushan4work/roastmyblog/blob/main/src/lib/api.ts): HTTP helper · `src/lib/api.ts`

### Next.js server

- [Analyze endpoint](https://github.com/bhushan4work/roastmyblog/blob/main/src/app/api/analyze/route.ts): Route handler · Primary backend workflow entry point. · `src/app/api/analyze/route.ts`
- [Stats endpoint](https://github.com/bhushan4work/roastmyblog/blob/main/src/app/api/stats/route.ts): Route handler · `src/app/api/stats/route.ts`

### Analysis pipeline

- [Article extraction](https://github.com/bhushan4work/roastmyblog/blob/main/src/services/scraperService.ts): Scraper service · Fetches URLs and extracts usable article text. · `src/services/scraperService.ts`
- [Text preparation](https://github.com/bhushan4work/roastmyblog/blob/main/src/utils/textUtil.ts): Text utility · `src/utils/textUtil.ts`
- [Analysis orchestrator](https://github.com/bhushan4work/roastmyblog/blob/main/src/services/analyzerService.ts): Analyzer service · Combines source text, local signals, and AI critique. · `src/services/analyzerService.ts`
- [Readability signals](https://github.com/bhushan4work/roastmyblog/blob/main/src/analyzers/readabilityAnalyzer.ts): Analyzer · `src/analyzers/readabilityAnalyzer.ts`
- [Structure signals](https://github.com/bhushan4work/roastmyblog/blob/main/src/analyzers/structureAnalyzer.ts): Analyzer · `src/analyzers/structureAnalyzer.ts`
- [LLM gateway](https://github.com/bhushan4work/roastmyblog/blob/main/src/services/groqService.ts): AI provider service · Contains model prompts, requests, and provider failures. · `src/services/groqService.ts`

### Persistence

- [Roast repository](https://github.com/bhushan4work/roastmyblog/blob/main/src/services/roastDbService.ts): Database service · `src/services/roastDbService.ts`
- [Roast record](https://github.com/bhushan4work/roastmyblog/blob/main/src/models/Roast.ts): Domain model · `src/models/Roast.ts`
- [Application types](https://github.com/bhushan4work/roastmyblog/blob/main/src/types/index.ts): Type contracts · `src/types/index.ts`

### External systems

- **Target websites**: External content · Arbitrary submitted blog URLs.
- **MongoDB / Atlas**: Database · Stores completed analysis history.
- **Groq and Google AI**: Model APIs · External critique-generation providers.

## Connections

- App layout → Root page: hosts
- Root page → Input landing: renders
- Root page → Progress UI: renders state
- Root page → Roast results: renders
- Root page → API client: submits via
- API client → Analyze endpoint: analyze request
- API client → Stats endpoint: history stats
- Analyze endpoint → Article extraction: URL source
- Article extraction → Target websites: fetches
- Article extraction → Text preparation: normalizes
- Analyze endpoint → Analysis orchestrator: source text
- Text preparation → Analysis orchestrator: prepared text
- Analysis orchestrator → Readability signals: measures
- Analysis orchestrator → Structure signals: measures
- Analysis orchestrator → LLM gateway: requests critique
- LLM gateway → Groq and Google AI: generates via
- Analyze endpoint → Roast repository: persists result
- Stats endpoint → Roast repository: queries history
- Roast repository → Roast record: stores
- Roast repository → MongoDB / Atlas: reads and writes
- Analyze endpoint → Application types: uses contracts
- Analysis orchestrator → Application types: returns typed data
