# sokyran/tweets-notion-saver architecture

> Architecture diagram of the GitHub repository sokyran/tweets-notion-saver, 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/sokyran/tweets-notion-saver
- Repository: https://github.com/sokyran/tweets-notion-saver

## Overview

Main Components to Include:

##### Client Layer
- Telegram Bot (User Interface)
- User's Twitter Links (Input Source)

##### Infrastructure Layer
- Cloudflare Worker (Main Application Runtime)
- Ngrok (Development Environment Only)

##### External Services
- Telegram Bot API
- Twitter API
- Notion API

##### Data Flow Representation
a. User → Telegram Bot → Cloudflare Worker
b. Cloudflare Worker → Twitter API (fetching tweet data)
c. Cloudflare Worker → Notion API (saving tweet data)
d. Cloudflare Worker → Telegram Bot API (sending confirmations)

##### Component Details
For each service component, include:
- Service name
- Primary function
- API endpoints or webhooks
- Authentication methods (indicate secret key requirements)

**[User] → [Telegram Bot] ↔ [Webhook] → [Cloudflare Worker] → [Notion DB]**
- ↑
- [Twitter API]

##### Stateless Operation: Show that no persistent storage is needed in the Worker itself

Technical Details to Include:
- TypeScript implementation (based on tsconfig.json)
- Service modularity (shown in the services directory)
- Configuration management (wrangler.toml and environment secrets)

Development vs Production Flow:
- Development: Local → Ngrok → Telegram
- Production: User → Telegram → Cloudflare Worker

## Diagram (Mermaid)

```mermaid
flowchart TB
    subgraph Client
        User([User])
        TelegramUI[Telegram Bot Interface]
        TwitterInput[Twitter Links]
    end

    subgraph Infrastructure
        Worker[Cloudflare Worker]:::worker
        Ngrok[Ngrok Tunnel]:::dev
        Webhook[Webhook Handler]
    end

    subgraph "External Services"
        TelegramAPI[Telegram Bot API]:::api
        TwitterAPI[Twitter API]:::api
        NotionAPI[Notion API]:::api
    end

    subgraph "Configuration & Types"
        Config[Configuration]:::config
        Types[Type Definitions]:::types
    end

    User --> TelegramUI
    TelegramUI --> Webhook
    TwitterInput --> Worker
    Webhook --> Worker
    Worker --> TelegramAPI
    Worker --> TwitterAPI
    Worker --> NotionAPI
    Ngrok -.- Webhook

    %% Component Relationships
    Worker --> Config
    Worker --> Types

    %% Click Events
    click Worker "https://github.com/sokyran/tweets-notion-saver/blob/main/src/index.ts"
    click TelegramUI "https://github.com/sokyran/tweets-notion-saver/blob/main/src/services/telegram.ts"
    click TwitterAPI "https://github.com/sokyran/tweets-notion-saver/blob/main/src/services/twitter.ts"
    click NotionAPI "https://github.com/sokyran/tweets-notion-saver/blob/main/src/services/notion.ts"
    click Types "https://github.com/sokyran/tweets-notion-saver/blob/main/src/types.ts"
    click Config "https://github.com/sokyran/tweets-notion-saver/blob/main/wrangler.toml"

    %% Styling
    classDef worker fill:#3182ce,color:#fff
    classDef api fill:#48bb78,color:#fff
    classDef dev fill:#718096,color:#fff
    classDef config fill:#d69e2e,color:#fff
    classDef types fill:#805ad5,color:#fff

    %% Legend
    subgraph Legend
        L1[Core Infrastructure]:::worker
        L2[External APIs]:::api
        L3[Development Tools]:::dev
        L4[Configuration]:::config
        L5[Type System]:::types
    end
```
