# puravparab/claude-pokemon architecture

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

- Interactive diagram: https://gitdiagram.com/puravparab/claude-pokemon
- Repository: https://github.com/puravparab/claude-pokemon

## Overview

##### Main Components
- Twitch Monitoring Agent: This component includes files like monitor.py and the monitor/ package (with capture.py, context.py, llm.py, prompts.py, server.py, stream/twitch.html, validate.py). It is responsible for:
- Capturing screenshots from the Twitch stream.
- Feeding the screenshots to an LLM for game analysis.
- Saving the analysis and additional metadata into a context file (context.jsonl).
- Posting Agent: This component is represented by post.py and the post/ package (with context.py, llm.py, prompts.py, tweet.py, utils.py, validate.py). It is responsible for:
- Aggregating events from the past 5 minutes along with long-running agent notes.
- Formulating a tweet via interaction with an LLM and determining if the tweet should be posted.
- Posting updates to Twitter (X), and saving tweets to posts.jsonl.
- External Integrations/Services:
- Twitch platform (input source for the monitoring agent).
- Openrouter API (providing LLM capabilities for both analysis and tweet generation).
- Twitter (X) API (for posting the finished tweet updates).
- Configuration and Environment: The .env file (referenced by the .env.template) provides the necessary environment variables (credentials, intervals, and API keys) to connect with external services.

- From Twitch Stream → Monitoring Agent: Indicate that screenshots are captured periodically.
- Monitoring Agent → LLM Module (via Openrouter API): Shows the processing of screenshots to extract game analysis and metadata.
- LLM Analysis → Monitoring Agent → Context Store (context.jsonl): Data storage of the processed game events.
- Context File → Posting Agent: The posting agent retrieves recent events for evaluation.
- Posting Agent → LLM Module (for tweet formulation): Process candidate tweet with additional notes.
- Posting Agent → Twitter API: Final output posted to Twitter.

##### Architectural Patterns & Technologies
- Modularity: The clear separation of responsibilities into two distinct agents (monitor and post) is an example of modular design.
- Use of Python: Note that the project runs under Python 3.12, managed by uv (a Python package manager) as shown by instructions and uv.lock.

##### Final Recommendation for the Principal Software Engineer
- Integration and intermediary steps (LLM analysis, context file update, tweet formulation) as separate nodes.

## Diagram (Mermaid)

```mermaid
graph TD
    %% External Nodes
    TS["Twitch Stream"]:::external
    ORA["Openrouter API"]:::external
    TAPI["Twitter (X) API"]:::external
    CFG["Configuration"]:::config

    %% Monitoring Agent Subgraph
    subgraph "Monitoring Agent"
        M0["Twitch Monitor"]:::agent
        M1["Image Capture"]:::internal
        M2["LLM Analysis"]:::internal
        M3["Context Manager"]:::internal
        M4["Prompts"]:::internal
        M5["Server"]:::internal
        M7["Twitch Page"]:::internal
    end

    %% Posting Agent Subgraph
    subgraph "Posting Agent"
        P0["Tweet Poster"]:::agent
        P1["Context Aggregator"]:::internal
        P2["Tweet Generator"]:::internal
        P3["Post Prompts"]:::internal
        P4["Tweet Dispatcher"]:::internal
        P5["Utils"]:::internal
        P6["Post Validation"]:::internal
    end

    %% Connections for Monitoring Agent
    TS -->|"stream_input"| M0
    CFG -->|"config"| M0
    M0 -->|"capture"| M1
    M1 -->|"analyze"| M2
    M2 -->|"LLM_request"| ORA
    ORA -->|"analysis_result"| M2
    M2 -->|"store_context"| M3
    M0 -->|"apply_prompts"| M4
    M0 -->|"run_server"| M5
    M5 -->|"serve_page"| M7

    %% Connection from Monitoring to Posting
    M3 -->|"share_context"| P1

    %% Connections for Posting Agent
    CFG -->|"config"| P0
    P1 -->|"retrieve_context"| P2
    P2 -->|"LLM_tweet_request"| ORA
    ORA -->|"tweet_result"| P2
    P2 -->|"apply_prompts"| P3
    P2 -->|"validate_tweet"| P6
    P2 -->|"dispatch_tweet"| P4
    P2 -->|"support_via_utils"| P5
    P4 -->|"post_tweet"| TAPI

    %% Click Events for Monitoring Agent
    click M0 "https://github.com/puravparab/claude-pokemon/blob/main/monitor.py"
    click M1 "https://github.com/puravparab/claude-pokemon/blob/main/monitor/capture.py"
    click M2 "https://github.com/puravparab/claude-pokemon/blob/main/monitor/llm.py"
    click M3 "https://github.com/puravparab/claude-pokemon/blob/main/monitor/context.py"
    click M4 "https://github.com/puravparab/claude-pokemon/blob/main/monitor/prompts.py"
    click M5 "https://github.com/puravparab/claude-pokemon/blob/main/monitor/server.py"
    click M7 "https://github.com/puravparab/claude-pokemon/blob/main/monitor/stream/twitch.html"

    %% Click Events for Posting Agent
    click P0 "https://github.com/puravparab/claude-pokemon/blob/main/post.py"
    click P1 "https://github.com/puravparab/claude-pokemon/blob/main/post/context.py"
    click P2 "https://github.com/puravparab/claude-pokemon/blob/main/post/llm.py"
    click P3 "https://github.com/puravparab/claude-pokemon/blob/main/post/prompts.py"
    click P4 "https://github.com/puravparab/claude-pokemon/blob/main/post/tweet.py"
    click P5 "https://github.com/puravparab/claude-pokemon/blob/main/post/utils.py"
    click P6 "https://github.com/puravparab/claude-pokemon/blob/main/post/validate.py"

    %% Click Event for Configuration
    click CFG "https://github.com/puravparab/claude-pokemon/blob/main/.env.template"

    %% Styles
    classDef agent fill:#8FBC8F,stroke:#333,stroke-width:2px;
    classDef internal fill:#ADD8E6,stroke:#333,stroke-width:2px;
    classDef external fill:#FFE4B5,stroke:#333,stroke-width:2px;
    classDef config fill:#DDA0DD,stroke:#333,stroke-width:2px;
```
