# notskamr/mdbin architecture

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

- Interactive diagram: https://gitdiagram.com/notskamr/mdbin
- Repository: https://github.com/notskamr/mdbin

## Overview

##### Main Components

a. Frontend Layer:
- Sub-components:
- Pages (routing layer)
- Layouts
- Components (Header, Footer, Welcome)
- Assets

b. API/Server Functions:
- Endpoints:
- Edit handler
- Raw content handler
- Custom URL handler

c. Database Layer:
- Database interactions from utils/db.ts

d. Cloudflare Infrastructure:
- CDN distribution

##### Component Relationships

- User requests → Cloudflare CDN
- CDN → Astro.js Frontend
- Frontend → Server Functions
- Server Functions → Database
- Database → Server Functions → Frontend

##### Specific Implementation Details

Technical elements:
- Astro.js as the main framework (shown in astro.config.mjs)
- Tailwind CSS for styling (indicated by tailwind.config.mjs)
- Authentication/Security layer (utils/hashing.ts)
- Validation layer (utils/validation.ts)

##### Additional Elements

- Environment configurations
- URL routing patterns
- Markdown processing flow

**[User/Client] → [Cloudflare CDN]**
- ↓
**[Astro.js Frontend]**
- ↓
**[Server Functions]**
- ↓
**[Database Layer]**

Key Considerations:

##### Security measures and validation flow

Remember to:
- Use consistent symbols throughout
- Notes about scalability and Cloudflare's global distribution
- Error handling paths
- Where environment variables are used

## Diagram (Mermaid)

```mermaid
flowchart TB
    subgraph Client
        User[User/Browser]
    end

    subgraph CDN
        CF[Cloudflare CDN]
    end

    subgraph Frontend
        AstroFE[Astro.js Frontend]:::frontend
        
        subgraph Pages
            HomePage["Home Page"]:::frontend
            CustomURLPage["Custom URL Pages"]:::frontend
            EditPage["Edit Page"]:::frontend
            RawPage["Raw Page"]:::frontend
        end
        
        subgraph Layouts
            MainLayout["Main Layout"]:::frontend
            BaseLayout["Base Layout"]:::frontend
        end
        
        subgraph Components
            Header["Header"]:::frontend
            Footer["Footer"]:::frontend
            Welcome["Welcome"]:::frontend
        end
        
        Assets["Frontend Assets"]:::frontend
    end

    subgraph ServerFunctions
        EditHandler["Edit Handler"]:::api
        RawHandler["Raw Handler"]:::api
        CustomURLHandler["Custom URL Handler"]:::api
    end

    subgraph Database
        D1["Cloudflare D1"]:::db
        KV["Cloudflare KV"]:::db
        DBUtils["Database Utils"]:::db
    end

    subgraph Security
        Auth["Authentication"]:::security
        Validation["Validation"]:::security
    end

    subgraph Config
        AstroConfig["Astro Config"]:::config
        TailwindConfig["Tailwind Config"]:::config
        EnvConfig["Environment Config"]:::config
        CFConfig["Cloudflare Config"]:::config
    end

    User --> CF
    CF --> AstroFE
    AstroFE --> |Routes| Pages
    Pages --> |Layout| Layouts
    Pages --> |UI| Components
    Pages --> |Static| Assets
    Pages --> ServerFunctions
    ServerFunctions --> Security
    ServerFunctions --> Database
    Database --> ServerFunctions
    ServerFunctions --> Pages

    %% Click Events
    click HomePage "https://github.com/notskamr/mdbin/blob/main/src/pages/index.astro"
    click CustomURLPage "https://github.com/notskamr/mdbin/tree/main/src/pages/[customUrl]/"
    click EditHandler "https://github.com/notskamr/mdbin/blob/main/src/pages/[customUrl]/edit.ts"
    click RawHandler "https://github.com/notskamr/mdbin/blob/main/src/pages/[customUrl]/raw.ts"
    click Header "https://github.com/notskamr/mdbin/blob/main/src/components/Header.astro"
    click Footer "https://github.com/notskamr/mdbin/blob/main/src/components/Footer.astro"
    click Welcome "https://github.com/notskamr/mdbin/blob/main/src/components/Welcome.astro"
    click MainLayout "https://github.com/notskamr/mdbin/blob/main/src/layouts/MainLayout.astro"
    click BaseLayout "https://github.com/notskamr/mdbin/blob/main/src/layouts/Layout.astro"
    click DBUtils "https://github.com/notskamr/mdbin/blob/main/src/utils/db.ts"
    click Auth "https://github.com/notskamr/mdbin/blob/main/src/utils/hashing.ts"
    click Validation "https://github.com/notskamr/mdbin/blob/main/src/utils/validation.ts"
    click Assets "https://github.com/notskamr/mdbin/tree/main/src/assets/"
    click AstroConfig "https://github.com/notskamr/mdbin/blob/main/astro.config.mjs"
    click TailwindConfig "https://github.com/notskamr/mdbin/blob/main/tailwind.config.mjs"
    click EnvConfig "https://github.com/notskamr/mdbin/blob/main/.env.example"
    click CFConfig "https://github.com/notskamr/mdbin/blob/main/wrangler.toml"

    %% Styles
    classDef frontend fill:#3b82f6,color:white
    classDef api fill:#22c55e,color:white
    classDef db fill:#eab308,color:black
    classDef security fill:#ef4444,color:white
    classDef config fill:#8b5cf6,color:white

    %% Legend
    subgraph Legend
        Frontend_["Frontend"]:::frontend
        API_["API"]:::api
        DB_["Database"]:::db
        Security_["Security"]:::security
        Config_["Configuration"]:::config
    end
```
