# qiayue/gitbase architecture

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

- Interactive diagram: https://gitdiagram.com/qiayue/gitbase
- Repository: https://github.com/qiayue/gitbase

## Overview

##### Main Components

a) Client-Side Layer:
- Next.js Frontend (src/app directory)
- UI Components (src/components)
- Admin Interface (/admin routes)
- Authentication System (login-related components)

b) Server-Side Layer:
- Next.js API Routes (src/app/api)
- Authentication Middleware (middleware.js)
- Content Management System

c) External Services:
- GitHub API (for content storage)
- Vercel (for deployment)

**[Client Layer]**
- ↕
**[Server Layer]**
- ↕
**[External Services]**

##### Detailed Component Breakdown

Client Layer (Top):
- Public Pages (/, /posts, /resources)
- Admin Interface (/admin/*)
- UI Components
- Authentication Forms
- Use orange for admin-related components

Server Layer (Middle):
- API Routes Handler
- Authentication Middleware
- Content Processing (Markdown → HTML)
- GitHub Integration Logic
- Use green for API components
- Use yellow for middleware components

External Services (Bottom):
- GitHub Repository
- data/json (content storage)
- data/md (markdown files)
- Vercel Platform
- Use purple for external services

##### Data Flow Indicators

- Client-to-Server API calls
- Server-to-GitHub content operations
- Authentication flow
- Content update flow

**Admin UI → API Routes → GitHub API → Repository**
- ↑                                    ↓
- Content Sync ───────────┘

**Login Page → API Routes → Middleware → Protected Routes**

##### Important Notes

- Database-free architecture
- GitHub integration as a primary storage mechanism
- Admin interface's connection to content management
- Authentication boundary between public and protected routes

## Diagram (Mermaid)

```mermaid
graph TB
    subgraph Client
        PublicPages["Public Pages"]:::client
        click PublicPages "https://github.com/qiayue/GitBase/blob/main/src/app/page.tsx"
        AdminUI["Admin Interface"]:::admin
        click AdminUI "https://github.com/qiayue/GitBase/tree/main/src/app/admin/"
        UIComponents["UI Components"]:::client
        click UIComponents "https://github.com/qiayue/GitBase/tree/main/src/components/ui/"
        LoginPage["Login Page"]:::auth
        click LoginPage "https://github.com/qiayue/GitBase/blob/main/src/app/login/page.js"
    end

    subgraph Server
        APIRoutes["API Routes"]:::api
        click APIRoutes "https://github.com/qiayue/GitBase/tree/main/src/app/api/"
        AuthMiddleware["Auth Middleware"]:::auth
        click AuthMiddleware "https://github.com/qiayue/GitBase/blob/main/middleware.js"
        ContentProcessor["Content Processor"]:::server
        click ContentProcessor "https://github.com/qiayue/GitBase/blob/main/src/lib/posts.js"
        GithubIntegration["GitHub Integration"]:::server
    end

    subgraph External
        GitHub["GitHub Repository"]:::external
        VercelPlatform["Vercel Platform"]:::external
        
        subgraph "GitHub Storage"
            JSONStorage["JSON Storage"]:::storage
            click JSONStorage "https://github.com/qiayue/GitBase/tree/main/data/json/"
            MarkdownStorage["Markdown Storage"]:::storage
            click MarkdownStorage "https://github.com/qiayue/GitBase/tree/main/data/md/"
        end
    end

    %% Client to Server Connections
    PublicPages --> APIRoutes
    AdminUI --> APIRoutes
    LoginPage --> APIRoutes

    %% Server Internal Connections
    APIRoutes --> AuthMiddleware
    APIRoutes --> ContentProcessor
    ContentProcessor --> GithubIntegration

    %% Server to External Connections
    GithubIntegration --> GitHub
    GitHub --> JSONStorage
    GitHub --> MarkdownStorage

    %% Authentication Flow
    AuthMiddleware --> AdminUI
    LoginPage --> AuthMiddleware

    %% Content Flow
    AdminUI --> ContentProcessor
    ContentProcessor --> JSONStorage
    ContentProcessor --> MarkdownStorage

    %% Deployment
    GitHub --> VercelPlatform

    %% Styles
    classDef client fill:#3b82f6,color:#fff
    classDef admin fill:#f97316,color:#fff
    classDef auth fill:#eab308,color:#000
    classDef api fill:#22c55e,color:#fff
    classDef server fill:#64748b,color:#fff
    classDef external fill:#a855f7,color:#fff
    classDef storage fill:#6b7280,color:#fff

    %% Legend
    subgraph Legend
        Client1["Client Component"]:::client
        Admin1["Admin Component"]:::admin
        Auth1["Auth Component"]:::auth
        API1["API Component"]:::api
        Server1["Server Component"]:::server
        External1["External Service"]:::external
        Storage1["Storage"]:::storage
    end
```
