# alexabstreiter/weekly-generator architecture

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

- Interactive diagram: https://gitdiagram.com/alexabstreiter/weekly-generator
- Repository: https://github.com/alexabstreiter/weekly-generator

## Overview

##### Main Components
- Discord Bot Component – This is the core engine that connects to Discord, listens to channels, and extracts messages. Note that the main entry point is run.py which kicks off this process.
- Message Extraction Module – It handles fetching messages (including threads) from Discord channels. This functionality may reside primarily in src/bot.py and parts of src/utils.py.
- Summary Generation Module – Managed likely by summary_generator.py along with additional logic in src/bot.py and/or src/utils.py, this module is responsible for sending extracted content to OpenAI’s API for summarization.
- Notion Integration Module – In src/notion_utils.py, this component handles saving the generated summaries to Notion.
- (Minor) Additional JavaScript Component – There’s an index.js file in the src directory. While most functionality is in Python, this file might be used either for a light-weight UI-related piece or an integration script. Either mark it as a secondary integration point or label it explicitly if it has a distinct purpose.

##### Interactions and Relationships
- The Discord Bot Component (originating from run.py and src/bot.py) initiates the connection to Discord.
- The Message Extraction Module fetches messages from various channels (indicated by Discord API permissions noted in the README), handling threaded messages and hierarchical organization.
- Extracted messages are then passed to the Summary Generation Module, which uses OpenAI’s API (as per the instructions and API key requirements) to create summaries.
- The Summary Generation Module sends the processed summaries to both the console (output directed back to the main bot process) and to Notion via the Notion Integration Module.
- Optionally, there’s an integration with Pipedrive where updates are fetched and perhaps merged with the Discord messages (this could be shown as another input stream feeding the Summary Generation Module or a parallel process).

##### Architectural Patterns and Technologies
- It’s a single application that leverages a modular architecture: separate modules for Discord interactions, message processing/summarizing, and external integrations (Notion, Pipedrive).
- Separation of concerns by mapping out distinct blocks/modules with their responsibilities.
- Integration with third-party APIs: Discord API for message extraction, OpenAI for generating summaries, Notion API for saving outputs, and Pipedrive API for updates.
- That while the main bot implementation is in Python (Python scripts and run.py), there exists a JavaScript file (index.js) which might be used for auxiliary purposes. Identify its possible role if known, or treat it as a supplementary component.

## Diagram (Mermaid)

```mermaid
flowchart TD
    Config["Config (.env)"]:::config

    subgraph "Bot Processing"
        DiscordBot["Discord Bot"]:::internal
        MessageExtraction["Message Extraction Module"]:::internal
        SummaryGeneration["Summary Generation Module"]:::internal
    end

    ConsoleOutput["Console Output"]:::internal
    NotionIntegration["Notion Integration Module"]:::internal
    PipedriveIntegration["Pipedrive Update Integration"]:::integration

    subgraph "External Services"
        DiscordAPI["Discord API"]:::external
        OpenAIAPI["OpenAI API"]:::external
        NotionAPI["Notion API"]:::external
        PipedriveAPI["Pipedrive API"]:::external
    end

    subgraph "Supplementary Components"
        JSComponent["JavaScript Integration"]:::js
    end

    Config -->|"provides"| DiscordBot
    DiscordBot -->|"extractsMessages"| MessageExtraction
    MessageExtraction -->|"sendsToSummary"| SummaryGeneration
    SummaryGeneration -->|"outputsToConsole"| ConsoleOutput
    SummaryGeneration -->|"updatesNotion"| NotionIntegration
    PipedriveIntegration -->|"feedsDataTo"| SummaryGeneration

    DiscordBot -->|"callsDiscord"| DiscordAPI
    SummaryGeneration -->|"callsOpenAI"| OpenAIAPI
    NotionIntegration -->|"callsNotion"| NotionAPI
    PipedriveIntegration -->|"callsPipedrive"| PipedriveAPI

    JSComponent -->|"integrates"| DiscordBot

    click DiscordBot "https://github.com/alexabstreiter/weekly-generator/blob/main/run.py"
    click DiscordBot "https://github.com/alexabstreiter/weekly-generator/blob/main/src/bot.py"
    click MessageExtraction "https://github.com/alexabstreiter/weekly-generator/blob/main/src/bot.py"
    click MessageExtraction "https://github.com/alexabstreiter/weekly-generator/blob/main/src/utils.py"
    click SummaryGeneration "https://github.com/alexabstreiter/weekly-generator/blob/main/summary_generator.py"
    click NotionIntegration "https://github.com/alexabstreiter/weekly-generator/blob/main/src/notion_utils.py"
    click JSComponent "https://github.com/alexabstreiter/weekly-generator/blob/main/src/index.js"

    classDef internal fill:#BBDEFB,stroke:#1E88E5,stroke-width:2px;
    classDef external fill:#FFCC80,stroke:#FB8C00,stroke-width:2px;
    classDef integration fill:#C5E1A5,stroke:#7CB342,stroke-width:2px;
    classDef js fill:#CE93D8,stroke:#8E24AA,stroke-width:2px;
    classDef config fill:#FFE082,stroke:#FFB300,stroke-width:2px;
```
