# berrysauce/pinned architecture

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

- Interactive diagram: https://gitdiagram.com/berrysauce/pinned
- Repository: https://github.com/berrysauce/pinned

## Overview

Key Components to Include:

##### Client Layer
- External clients making HTTP GET requests
- Endpoint format (/get/{username})
- Optional query parameter (?pretty)

##### Cloudflare Infrastructure
- Cloudflare Workers runtime environment
- Caching layer (5-minute cache)
- Edge network distribution

##### External Services
- GitHub's website (as the data source)
- HTML scraping component

##### Data Flow
- Request handling
- Cache checking
- HTML fetching and parsing
- Response formatting

- [Client Applications]
- ↓
- [Cloudflare Edge Network]
- ↓
- [Cloudflare Worker (Pinned API)]
- ↓
- [Cache Layer]
- ↕
- [GitHub Website]

##### Component Details
- A component for the TypeScript runtime (indicated by tsconfig.json)
- HTML parsing mechanism
- JSON response formatter

##### Specific Elements
- Request validation
- Cache check/update logic
- Error handling paths
- Response formatting (pretty vs. standard)

##### Technical Specifications
- TypeScript implementation
- Cloudflare Workers as the deployment platform
- Caching duration (5 minutes)

Important Considerations:

##### Rate limiting if implemented

- High-level architecture (client → edge → worker → GitHub)
- Specific implementation details (TypeScript, caching, parsing)
- Error handling flows
- Response formatting options

Use standardized symbols:
- Rectangles for processing components
- Diamonds for decision points
- Clouds for external services

- Special symbols
- Caching indicators

Remember to include notes about:
- The stateless nature of the service
- Edge deployment benefits
- Caching strategy
- Error handling patterns

This will give other engineers a clear understanding of how the system works while highlighting its scalability and reliability features.

## Diagram (Mermaid)

```mermaid
flowchart TB
    %% Styles
    classDef client fill:#2196F3,color:white
    classDef cloudflare fill:#4CAF50,color:white
    classDef github fill:#FF9800,color:white
    classDef cache fill:#9C27B0,color:white
    classDef config fill:#607D8B,color:white
    classDef error fill:#f44336,color:white

    %% Client Layer
    client[Client Applications]:::client
    endpoint["GET /get/{username}"]:::client

    %% Cloudflare Layer
    subgraph cf [Cloudflare Infrastructure]
        edge[Cloudflare Edge Network]:::cloudflare
        worker["Cloudflare Worker (Pinned API)"]:::cloudflare
        cache[(Cache Layer<br>5-minute TTL)]:::cache
        validator{Request<br>Validation}:::cloudflare
        parser[HTML Parser]:::cloudflare
        formatter{Pretty Print?}:::cloudflare
    end

    %% Configuration
    config1["TypeScript Config"]:::config
    config2["Worker Config"]:::config
    config3["Dependencies"]:::config

    %% GitHub Layer
    github[GitHub Website]:::github

    %% Error Handling
    error1[Invalid Request]:::error
    error2[Fetch Error]:::error
    error3[Parse Error]:::error

    %% Connections
    client --> endpoint
    endpoint --> edge
    edge --> worker
    worker --> validator
    validator -->|Valid| cache
    validator -->|Invalid| error1
    cache -->|Miss| github
    cache -->|Hit| formatter
    github -->|Success| parser
    github -->|Failure| error2
    parser -->|Success| cache
    parser -->|Failure| error3
    formatter -->|Yes| response1[Pretty JSON]
    formatter -->|No| response2[Compact JSON]

    %% Click Events
    click worker "https://github.com/berrysauce/pinned/blob/main/src/index.ts"
    click config1 "https://github.com/berrysauce/pinned/blob/main/tsconfig.json"
    click config2 "https://github.com/berrysauce/pinned/blob/main/wrangler.toml"
    click config3 "https://github.com/berrysauce/pinned/blob/main/package.json"

    %% Legend
    subgraph Legend
        l1[Client Components]:::client
        l2[Cloudflare Components]:::cloudflare
        l3[GitHub Components]:::github
        l4[(Cache Components)]:::cache
        l5[Configuration]:::config
        l6[Error States]:::error
    end
```
