# tejastice/ai-keisuke architecture

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

- Interactive diagram: https://gitdiagram.com/tejastice/ai-keisuke
- Repository: https://github.com/tejastice/ai-keisuke

## Overview

AI けいすけ is a Discord bot whose main workflow starts with a user reacting to a message or attachment in an activated channel, then returns an AI-generated result in Discord. The README documents six reaction-based capabilities, premium limits, custom prompts, and statistics; the sampled source excerpts show prompt-file loading and portions of the X-post flow. The implementation is concentrated in main.py, so several responsibilities share that path. Other internal dispatch and integration details are not shown in the excerpts.

Main entry points: [`main.py`](https://github.com/tejastice/ai-keisuke/blob/main/main.py) (Bot runtime), [`data/user_data`](https://github.com/tejastice/ai-keisuke/tree/main/data/user_data) (User data), [`data/activity_logs`](https://github.com/tejastice/ai-keisuke/tree/main/data/activity_logs) (Activity logs), [`prompt/x_post.txt`](https://github.com/tejastice/ai-keisuke/blob/main/prompt/x_post.txt) (X prompt)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_interaction["Discord interaction"]
  node_discord["Discord"]
  node_bot["Bot runtime<br/>[main.py]"]
end

subgraph group_generation["AI generation"]
  node_xpost["X post<br/>[main.py]"]
  node_transcription["Transcription<br/>[main.py]"]
  node_explanation["AI explanation<br/>[main.py]"]
  node_praise["Praise message<br/>[main.py]"]
  node_memo["Obsidian memo<br/>[main.py]"]
  node_article["Structured article<br/>[main.py]"]
end

subgraph group_account["Plans and statistics"]
  node_plans["Plan and usage checks<br/>[main.py]"]
  node_stats["Usage statistics<br/>[main.py]"]
  node_user_data[("User data")]
  node_activity_logs[("Activity logs")]
end

subgraph group_assets["Prompt assets"]
  node_prompt_x["X prompt<br/>[x_post.txt]"]
  node_prompt_explain["Explanation prompt"]
  node_prompt_praise["Praise prompt<br/>[heart_praise.txt]"]
  node_prompt_memo["Memo prompt<br/>[pencil_memo.txt]"]
  node_prompt_article["Article prompt<br/>[article.txt]"]
end

node_user(("Discord user"))
node_openai["OpenAI API"]

node_user -->|"reacts"| node_discord
node_discord -->|"delivers interaction"| node_bot
node_bot -->|"dispatches"| node_xpost
node_bot -->|"dispatches"| node_transcription
node_bot -->|"dispatches"| node_explanation
node_bot -->|"dispatches"| node_praise
node_bot -->|"dispatches"| node_memo
node_bot -->|"dispatches"| node_article
node_xpost -->|"generates with"| node_openai
node_transcription -->|"transcribes with"| node_openai
node_explanation -->|"explains with"| node_openai
node_praise -->|"generates with"| node_openai
node_memo -->|"generates with"| node_openai
node_article -->|"generates with"| node_openai
node_xpost -->|"reads prompt"| node_prompt_x
node_explanation -.->|"reads prompt"| node_prompt_explain
node_praise -.->|"reads prompt"| node_prompt_praise
node_memo -->|"reads prompt"| node_prompt_memo
node_article -->|"reads prompt"| node_prompt_article
node_bot -.->|"enforces limits"| node_plans
node_plans -.->|"updates usage"| node_user_data
node_bot -.->|"collects activity"| node_stats
node_stats -.->|"reads and writes"| node_activity_logs

click node_bot "https://github.com/tejastice/ai-keisuke/blob/main/main.py"
click node_xpost "https://github.com/tejastice/ai-keisuke/blob/main/main.py"
click node_transcription "https://github.com/tejastice/ai-keisuke/blob/main/main.py"
click node_explanation "https://github.com/tejastice/ai-keisuke/blob/main/main.py"
click node_praise "https://github.com/tejastice/ai-keisuke/blob/main/main.py"
click node_memo "https://github.com/tejastice/ai-keisuke/blob/main/main.py"
click node_article "https://github.com/tejastice/ai-keisuke/blob/main/main.py"
click node_prompt_x "https://github.com/tejastice/ai-keisuke/blob/main/prompt/x_post.txt"
click node_prompt_explain "https://github.com/tejastice/ai-keisuke/blob/main/prompt/question_explain.txt"
click node_prompt_praise "https://github.com/tejastice/ai-keisuke/blob/main/prompt/heart_praise.txt"
click node_prompt_memo "https://github.com/tejastice/ai-keisuke/blob/main/prompt/pencil_memo.txt"
click node_prompt_article "https://github.com/tejastice/ai-keisuke/blob/main/prompt/article.txt"
click node_plans "https://github.com/tejastice/ai-keisuke/blob/main/main.py"
click node_stats "https://github.com/tejastice/ai-keisuke/blob/main/main.py"
click node_user_data "https://github.com/tejastice/ai-keisuke/tree/main/data/user_data"
click node_activity_logs "https://github.com/tejastice/ai-keisuke/tree/main/data/activity_logs"

classDef toneNeutral fill:#f8fafc,stroke:#334155,stroke-width:1.5px,color:#0f172a
classDef toneBlue fill:#dbeafe,stroke:#2563eb,stroke-width:1.5px,color:#172554
classDef toneAmber fill:#fef3c7,stroke:#d97706,stroke-width:1.5px,color:#78350f
classDef toneMint fill:#dcfce7,stroke:#16a34a,stroke-width:1.5px,color:#14532d
classDef toneRose fill:#ffe4e6,stroke:#e11d48,stroke-width:1.5px,color:#881337
classDef toneIndigo fill:#e0e7ff,stroke:#4f46e5,stroke-width:1.5px,color:#312e81
classDef toneTeal fill:#ccfbf1,stroke:#0f766e,stroke-width:1.5px,color:#134e4a
class node_discord,node_bot,node_user toneBlue
class node_xpost,node_transcription,node_explanation,node_praise,node_memo,node_article toneAmber
class node_plans,node_stats,node_user_data,node_activity_logs,node_openai toneMint
class node_prompt_x,node_prompt_explain,node_prompt_praise,node_prompt_memo,node_prompt_article toneRose
```

## Components

### Discord interaction

- **Discord**
- [Bot runtime](https://github.com/tejastice/ai-keisuke/blob/main/main.py): `main.py`

### AI generation

- [X post](https://github.com/tejastice/ai-keisuke/blob/main/main.py): `main.py`
- [Transcription](https://github.com/tejastice/ai-keisuke/blob/main/main.py): `main.py`
- [AI explanation](https://github.com/tejastice/ai-keisuke/blob/main/main.py): `main.py`
- [Praise message](https://github.com/tejastice/ai-keisuke/blob/main/main.py): `main.py`
- [Obsidian memo](https://github.com/tejastice/ai-keisuke/blob/main/main.py): `main.py`
- [Structured article](https://github.com/tejastice/ai-keisuke/blob/main/main.py): `main.py`

### Plans and statistics

- [Plan and usage checks](https://github.com/tejastice/ai-keisuke/blob/main/main.py): `main.py`
- [Usage statistics](https://github.com/tejastice/ai-keisuke/blob/main/main.py): `main.py`
- [User data](https://github.com/tejastice/ai-keisuke/tree/main/data/user_data): `data/user_data`
- [Activity logs](https://github.com/tejastice/ai-keisuke/tree/main/data/activity_logs): `data/activity_logs`

### Prompt assets

- [X prompt](https://github.com/tejastice/ai-keisuke/blob/main/prompt/x_post.txt): `prompt/x_post.txt`
- [Explanation prompt](https://github.com/tejastice/ai-keisuke/blob/main/prompt/question_explain.txt): `prompt/question_explain.txt`
- [Praise prompt](https://github.com/tejastice/ai-keisuke/blob/main/prompt/heart_praise.txt): `prompt/heart_praise.txt`
- [Memo prompt](https://github.com/tejastice/ai-keisuke/blob/main/prompt/pencil_memo.txt): `prompt/pencil_memo.txt`
- [Article prompt](https://github.com/tejastice/ai-keisuke/blob/main/prompt/article.txt): `prompt/article.txt`

### Other components

- **Discord user**
- **OpenAI API**

## Connections

- Discord user → Discord: reacts (evidence: `README.md`)
- Discord → Bot runtime: delivers interaction (evidence: `README.md`)
- Bot runtime → X post: dispatches (evidence: `README.md`)
- Bot runtime → Transcription: dispatches (evidence: `README.md`)
- Bot runtime → AI explanation: dispatches (evidence: `README.md`)
- Bot runtime → Praise message: dispatches (evidence: `README.md`)
- Bot runtime → Obsidian memo: dispatches (evidence: `README.md`)
- Bot runtime → Structured article: dispatches (evidence: `README.md`)
- X post → OpenAI API: generates with (evidence: `README.md`)
- Transcription → OpenAI API: transcribes with (evidence: `README.md`)
- AI explanation → OpenAI API: explains with (evidence: `README.md`)
- Praise message → OpenAI API: generates with (evidence: `README.md`)
- Obsidian memo → OpenAI API: generates with (evidence: `README.md`)
- Structured article → OpenAI API: generates with (evidence: `README.md`)
- X post → X prompt: reads prompt (evidence: `main.py`)
- AI explanation → Explanation prompt: reads prompt
- Praise message → Praise prompt: reads prompt
- Obsidian memo → Memo prompt: reads prompt (evidence: `main.py`)
- Structured article → Article prompt: reads prompt (evidence: `main.py`)
- Bot runtime → Plan and usage checks: enforces limits (evidence: `README.md`)
- Plan and usage checks → User data: updates usage (evidence: `README.md`)
- Bot runtime → Usage statistics: collects activity (evidence: `README.md`)
- Usage statistics → Activity logs: reads and writes (evidence: `README.md`)
