# emon100/mypastebin architecture

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

- Interactive diagram: https://gitdiagram.com/emon100/mypastebin
- Repository: https://github.com/emon100/mypastebin

## Overview

##### Project type and purpose
- This is a full-stack, serverless pastebin application (“MyPastebin”) with:
- A React+TypeScript+Material-UI single-page frontend
- A Cloudflare Workers backend (REST API)
- A Cloudflare KV store for persistence
- Cloudflare Turnstile for CAPTCHA protection
- “Admin Panel” endpoints for management

##### File structure
- Top-level files:
- index.html, public/ – static shell & assets for the SPA
- src/ – frontend source code (App.tsx, components, assets)
- src/worker/index.ts – backend entrypoint
- wrangler.toml – Worker config
- .env* / .dev.vars* – environment variables for frontend & worker
- vite.config.ts, tsconfig*.json, eslint.config.js – build & lint
- Patterns:
- SPA served by Vite (dev) or static build
- Serverless API (Workers) calling KV namespace
- Separation of front-end and back-end env vars

##### README for additional insights
- The frontend calls the Worker API at VITE_API_URL
- Worker endpoints: create paste, view paste, admin list/delete
- Turnstile is used on both create-paste and admin operations
- Deployment involves Wrangler for Cloudflare

##### Detailed breakdown
- CreatePaste component → POST `/api/paste`
- ViewPaste component → GET `/api/paste/:id`
- AdminPanel component → GET/DELETE `/api/admin/*`
- Turnstile widget integrated on CreatePaste/AdminPanel forms
- HTTP handler (routes requests)
- Turnstile validation module
- KV read/write layer
- Configuration flow: Wrangler reads `.dev.vars` → sets secrets in Worker

Summary

## Diagram (Mermaid)

```mermaid
flowchart TD
    %% External Entities
    Browser["Client Browser"]:::external

    %% Frontend Tier
    subgraph "Frontend Tier"
        direction TB
        subgraph "Static Assets"
            direction TB
            FA1["index.html"]:::config
            FA2["public/"]:::config
        end
        subgraph "SPA Source"
            direction TB
            FE1["src/main.tsx"]:::frontend
            FE2["src/App.tsx"]:::frontend
            FE3["src/App.css"]:::frontend
            FE4["src/index.css"]:::frontend
            FE5["src/assets/"]:::frontend
            FE6["src/vite-env.d.ts"]:::frontend
        end
        subgraph "UI Components"
            direction TB
            CP["CreatePaste"]:::frontend
            VP["ViewPaste"]:::frontend
            AP["AdminPanel"]:::frontend
        end
    end

    %% Backend Tier
    subgraph "Backend Tier"
        direction TB
        subgraph "Cloudflare Worker"
            direction TB
            W["src/worker/index.ts"]:::compute
        end
        CFKV["Cloudflare KV"]:::storage
        Turn["Cloudflare Turnstile"]:::external
    end

    %% Configuration
    subgraph "Configuration"
        direction TB
        E1[".env.example"]:::config
        E2[".dev.vars.example"]:::config
        C1["wrangler.toml"]:::config
        C2["vite.config.ts"]:::config
        C3["tsconfig.json"]:::config
        C4["tsconfig.app.json"]:::config
        C5["tsconfig.node.json"]:::config
        C6["eslint.config.js"]:::config
    end

    %% Relationships
    Browser -->|"Load SPA"| FA1
    Browser --> FA2
    FA1 --> FE1
    FA2 --> FE1
    FE1 --> CP
    FE1 --> VP
    FE1 --> AP

    CP -->|"POST /api/paste"| W
    VP -->|"GET /api/paste/:id"| W
    AP -->|"GET/DELETE /api/admin/*"| W

    W -->|"read/write"| CFKV
    W -->|"Validate CAPTCHA"| Turn

    E1 -->|"frontend env vars"| FE1
    E2 -->|"worker env vars"| W
    C1 -->|"deployment config"| W
    C2 -->|"build config"| FE1
    C3 -->|"tsconfig"| FE1
    C4 -->|"tsconfig"| FE1
    C5 -->|"tsconfig"| FE1
    C6 -->|"linter config"| FE1

    %% Click Events
    click FA1 "https://github.com/emon100/mypastebin/blob/main/index.html"
    click FA2 "https://github.com/emon100/mypastebin/tree/main/public/"
    click FE1 "https://github.com/emon100/mypastebin/blob/main/src/main.tsx"
    click FE2 "https://github.com/emon100/mypastebin/blob/main/src/App.tsx"
    click FE3 "https://github.com/emon100/mypastebin/blob/main/src/App.css"
    click FE4 "https://github.com/emon100/mypastebin/blob/main/src/index.css"
    click FE5 "https://github.com/emon100/mypastebin/tree/main/src/assets/"
    click FE6 "https://github.com/emon100/mypastebin/blob/main/src/vite-env.d.ts"
    click CP "https://github.com/emon100/mypastebin/blob/main/src/components/CreatePaste.tsx"
    click VP "https://github.com/emon100/mypastebin/blob/main/src/components/ViewPaste.tsx"
    click AP "https://github.com/emon100/mypastebin/blob/main/src/components/AdminPanel.tsx"
    click W "https://github.com/emon100/mypastebin/blob/main/src/worker/index.ts"
    click C1 "https://github.com/emon100/mypastebin/blob/main/wrangler.toml"
    click E1 "https://github.com/emon100/mypastebin/blob/main/.env.example"
    click E2 "https://github.com/emon100/mypastebin/blob/main/.dev.vars.example"
    click C2 "https://github.com/emon100/mypastebin/blob/main/vite.config.ts"
    click C3 "https://github.com/emon100/mypastebin/blob/main/tsconfig.json"
    click C4 "https://github.com/emon100/mypastebin/blob/main/tsconfig.app.json"
    click C5 "https://github.com/emon100/mypastebin/blob/main/tsconfig.node.json"
    click C6 "https://github.com/emon100/mypastebin/blob/main/eslint.config.js"

    %% Styles
    classDef frontend fill:#cce5ff,stroke:#004085,color:#004085
    classDef compute fill:#d4edda,stroke:#155724,color:#155724
    classDef storage fill:#fff3cd,stroke:#856404,color:#856404
    classDef external fill:#e2e3e5,stroke:#6c757d,color:#6c757d
    classDef config fill:#f8d7da,stroke:#721c24,color:#721c24
```
