# benthecoder/blog architecture

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

- Interactive diagram: https://gitdiagram.com/benthecoder/blog
- Repository: https://github.com/benthecoder/blog

## Overview

##### Main Components Identification

The project is a modern full-stack blog application built with Next.js 13+ (using the App Router). Here's how to structure the main components:

a. Frontend Layer:
- Client-side Components (under /components)
- Page Components (under /app)
- Static Assets (under /public)

b. Backend Layer:
- API Routes (under /app/api)
- Database Integrations (Planetscale for tweets, Neon for embeddings)
- Content Management (Markdown files under /posts)

c. External Services:
- OpenAI API (for embeddings)
- RSS Feed Generation
- Search Functionality

**[Client Layer]**
- ↑↓
**[Next.js App Router Layer]**
- ↑↓
**[Server Components/API Routes]**
- ↑↓
**[Data Layer]**
- ↑↓
**[External Services]**

##### Component Relationships

Key interactions:
- Content flow from Markdown files to pages
- API routes handling for search, RSS, tweets
- Database interactions for thoughts and embeddings
- Static asset serving
- Server-side rendering paths
- Client-side interactions

##### Special Features to Highlight

- Vector search system using pgvector
- Markdown processing pipeline
- RSS feed generation
- Dark mode implementation
- Dynamic routing for blog posts
- API integration points

##### Implementation Details

**[Markdown Processing]**
- PostMetadata
- RenderPost
- Content Chunks

**[Search System]**
- Vector Embeddings
- PGVector Integration
- Similarity Search

**[Content Management]**
- Blog Posts
- Projects
- Library
- Thoughts

##### Infrastructure Components

Include:
- Next.js server
- Planetscale database
- Neon database
- OpenAI API connection
- Static file serving
- API endpoints

##### Development Tooling

Integration with:
- TypeScript compilation
- Tailwind CSS processing
- RSS generation
- Embedding generation

## Diagram (Mermaid)

```mermaid
graph TB
    subgraph Client
        UI["Client UI"]:::frontend
        Theme["Theme Switch"]:::frontend
        Preview["Post Preview"]:::frontend
        click Theme "https://github.com/benthecoder/blog/blob/main/components/ThemeSwitch.tsx"
        click Preview "https://github.com/benthecoder/blog/blob/main/components/PostPreview.tsx"
    end

    subgraph "Next.js Layer"
        Pages["Page Components"]:::frontend
        Components["Client Components"]:::frontend
        Assets["Static Assets"]:::frontend
        click Pages "https://github.com/benthecoder/blog/tree/main/app/*"
        click Components "https://github.com/benthecoder/blog/tree/main/components"
        click Assets "https://github.com/benthecoder/blog/tree/main/public"
    end

    subgraph "Server Components"
        RenderPost["Render Post"]:::server
        PostMeta["Post Metadata"]:::server
        click RenderPost "https://github.com/benthecoder/blog/blob/main/components/RenderPost.tsx"
        click PostMeta "https://github.com/benthecoder/blog/blob/main/components/PostMetadata.ts"
    end

    subgraph "Content Processing"
        MarkdownProc["Markdown Processing"]:::process
        ContentChunks["Content Chunks"]:::process
        PostProcessor["Post Processor"]:::process
        click ContentChunks "https://github.com/benthecoder/blog/blob/main/utils/processMarkdownChunks.ts"
        click PostProcessor "https://github.com/benthecoder/blog/blob/main/utils/processAllPosts.ts"
    end

    subgraph "API Layer"
        SearchAPI["Search API"]:::api
        RSSApi["RSS API"]:::api
        TweetAPI["Tweet API"]:::api
        click SearchAPI "https://github.com/benthecoder/blog/blob/main/app/api/search/route.ts"
        click RSSApi "https://github.com/benthecoder/blog/blob/main/app/api/rss/route.ts"
        click TweetAPI "https://github.com/benthecoder/blog/blob/main/app/api/tweet/route.ts"
    end

    subgraph "Data Storage"
        MarkdownFiles["Markdown Files"]:::storage
        PlanetScale["PlanetScale DB"]:::db
        NeonDB["Neon DB"]:::db
        click MarkdownFiles "https://github.com/benthecoder/blog/tree/main/posts"
    end

    subgraph "External Services"
        OpenAI["OpenAI API"]:::external
        RSSGen["RSS Generator"]:::external
        EmbedGen["Embedding Generator"]:::external
        click RSSGen "https://github.com/benthecoder/blog/blob/main/scripts/rss.mjs"
        click EmbedGen "https://github.com/benthecoder/blog/blob/main/scripts/generateEmbeddings.ts"
    end

    UI --> Theme
    UI --> Preview
    UI --> Pages
    Pages --> Components
    Pages --> Assets
    Components --> RenderPost
    Components --> PostMeta
    RenderPost --> MarkdownProc
    PostMeta --> MarkdownProc
    MarkdownProc --> ContentChunks
    MarkdownProc --> PostProcessor
    ContentChunks --> PostProcessor
    SearchAPI --> NeonDB
    TweetAPI --> PlanetScale
    RSSApi --> MarkdownFiles
    MarkdownFiles --> MarkdownProc
    SearchAPI --> OpenAI
    EmbedGen --> OpenAI
    EmbedGen --> NeonDB
    RSSGen --> MarkdownFiles

    classDef frontend fill:#3498db,stroke:#2980b9,color:white
    classDef server fill:#2ecc71,stroke:#27ae60,color:white
    classDef process fill:#e67e22,stroke:#d35400,color:white
    classDef api fill:#9b59b6,stroke:#8e44ad,color:white
    classDef storage fill:#f1c40f,stroke:#f39c12,color:black
    classDef db fill:#1abc9c,stroke:#16a085,color:white
    classDef external fill:#e74c3c,stroke:#c0392b,color:white
```
