# akiratorizawa/afg-bot architecture

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

- Interactive diagram: https://gitdiagram.com/akiratorizawa/afg-bot
- Repository: https://github.com/akiratorizawa/afg-bot

## Overview

AFG is a Discord bot and Flask-based football statistics site. The main Discord workflow accepts a game-stat JSON attachment, updates season totals, builds a game report, and records per-game statistics; separate commands view or transfer player stats and announce streams. Flask reads the season and game-log databases to serve leaderboards and player profiles. The graph preserves the major sampled bot and web capabilities; database and template relationships are shown where excerpts establish them. Other service internals were not sampled, so their detailed behavior is not inferred.

Main entry points: [`bot.py`](https://github.com/akiratorizawa/afg-bot/blob/main/bot.py) (Command handlers), [`app/app.py`](https://github.com/akiratorizawa/afg-bot/blob/main/app/app.py) (Flask routes and queries), [`app/databases/s24_d1.db`](https://github.com/akiratorizawa/afg-bot/blob/main/app/databases/s24_d1.db) (Division 1 season data), [`services/stats.py`](https://github.com/akiratorizawa/afg-bot/blob/main/services/stats.py) (Season stat updates)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_discord["Discord bot"]
  node_bot["Command handlers<br/>[bot.py]"]
  node_init["Bot initialization<br/>[initialization.py]"]
  node_autocomplete["Player autocomplete<br/>[get_players.py]"]
end

subgraph group_game["Game processing"]
  node_record["Season stat updates<br/>[stats.py]"]
  node_report["Game report<br/>[game_report.py]"]
  node_logging["Game log<br/>[log_game.py]"]
  node_stream["Stream announcement<br/>[stream.py]"]
end

subgraph group_stats["Player statistics"]
  node_view["Player stat view<br/>[view_stats.py]"]
  node_transfer["Stat transfer<br/>[transfer_stats.py]"]
  node_errors["Domain errors<br/>[errors.py]"]
end

subgraph group_web["Stats website"]
  node_webapp["Flask routes and queries<br/>[app.py]"]
  node_templates["Leaderboard and profile views"]
end

subgraph group_storage["SQLite storage"]
  node_season1[("Division 1 season data<br/>[s24_d1.db]")]
  node_season2[("Division 2 season data<br/>[s24_d2.db]")]
  node_logs1[("Division 1 game logs<br/>[s24_d1_logs.db]")]
  node_logs2[("Division 2 game logs<br/>[s24_d2_logs.db]")]
end

node_user(("Discord user"))
node_roblox["Roblox user and avatar APIs"]

node_user -->|"invokes commands"| node_bot
node_bot -->|"initializes"| node_init
node_bot -->|"gets suggestions"| node_autocomplete
node_bot -->|"records stats"| node_record
node_bot -->|"builds report"| node_report
node_bot -->|"logs game"| node_logging
node_bot -->|"creates announcement"| node_stream
node_bot -->|"requests stats"| node_view
node_bot -->|"transfers stats"| node_transfer
node_record -->|"updates totals"| node_season1
node_record -->|"updates totals"| node_season2
node_logging -->|"writes game rows"| node_logs1
node_logging -->|"writes game rows"| node_logs2
node_transfer -->|"reads and updates"| node_season1
node_transfer -->|"reads and updates"| node_season2
node_view -->|"reads player stats"| node_season1
node_view -->|"gets avatar"| node_roblox
node_report -->|"gets avatars"| node_roblox
node_autocomplete -->|"queries players"| node_season1
node_webapp -->|"reads stats"| node_season1
node_webapp -->|"reads stats"| node_season2
node_webapp -->|"reads game history"| node_logs1
node_webapp -->|"reads game history"| node_logs2
node_webapp -->|"renders pages"| node_templates

click node_bot "https://github.com/akiratorizawa/afg-bot/blob/main/bot.py"
click node_init "https://github.com/akiratorizawa/afg-bot/blob/main/utility/initialization.py"
click node_autocomplete "https://github.com/akiratorizawa/afg-bot/blob/main/utility/get_players.py"
click node_record "https://github.com/akiratorizawa/afg-bot/blob/main/services/stats.py"
click node_report "https://github.com/akiratorizawa/afg-bot/blob/main/services/game_report.py"
click node_logging "https://github.com/akiratorizawa/afg-bot/blob/main/services/log_game.py"
click node_stream "https://github.com/akiratorizawa/afg-bot/blob/main/services/stream.py"
click node_view "https://github.com/akiratorizawa/afg-bot/blob/main/services/view_stats.py"
click node_transfer "https://github.com/akiratorizawa/afg-bot/blob/main/services/transfer_stats.py"
click node_errors "https://github.com/akiratorizawa/afg-bot/blob/main/services/errors.py"
click node_webapp "https://github.com/akiratorizawa/afg-bot/blob/main/app/app.py"
click node_templates "https://github.com/akiratorizawa/afg-bot/tree/main/app/templates"
click node_season1 "https://github.com/akiratorizawa/afg-bot/blob/main/app/databases/s24_d1.db"
click node_season2 "https://github.com/akiratorizawa/afg-bot/blob/main/app/databases/s24_d2.db"
click node_logs1 "https://github.com/akiratorizawa/afg-bot/blob/main/app/databases/s24_d1_logs.db"
click node_logs2 "https://github.com/akiratorizawa/afg-bot/blob/main/app/databases/s24_d2_logs.db"

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_bot,node_init,node_autocomplete,node_user,node_roblox toneBlue
class node_record,node_report,node_logging,node_stream toneAmber
class node_view,node_transfer,node_errors toneMint
class node_webapp,node_templates toneRose
class node_season1,node_season2,node_logs1,node_logs2 toneIndigo
```

## Components

### Discord bot

- [Command handlers](https://github.com/akiratorizawa/afg-bot/blob/main/bot.py): `bot.py`
- [Bot initialization](https://github.com/akiratorizawa/afg-bot/blob/main/utility/initialization.py): `utility/initialization.py`
- [Player autocomplete](https://github.com/akiratorizawa/afg-bot/blob/main/utility/get_players.py): `utility/get_players.py`

### Game processing

- [Season stat updates](https://github.com/akiratorizawa/afg-bot/blob/main/services/stats.py): `services/stats.py`
- [Game report](https://github.com/akiratorizawa/afg-bot/blob/main/services/game_report.py): `services/game_report.py`
- [Game log](https://github.com/akiratorizawa/afg-bot/blob/main/services/log_game.py): `services/log_game.py`
- [Stream announcement](https://github.com/akiratorizawa/afg-bot/blob/main/services/stream.py): `services/stream.py`

### Player statistics

- [Player stat view](https://github.com/akiratorizawa/afg-bot/blob/main/services/view_stats.py): `services/view_stats.py`
- [Stat transfer](https://github.com/akiratorizawa/afg-bot/blob/main/services/transfer_stats.py): `services/transfer_stats.py`
- [Domain errors](https://github.com/akiratorizawa/afg-bot/blob/main/services/errors.py): `services/errors.py`

### Stats website

- [Flask routes and queries](https://github.com/akiratorizawa/afg-bot/blob/main/app/app.py): `app/app.py`
- [Leaderboard and profile views](https://github.com/akiratorizawa/afg-bot/tree/main/app/templates): `app/templates`

### SQLite storage

- [Division 1 season data](https://github.com/akiratorizawa/afg-bot/blob/main/app/databases/s24_d1.db): `app/databases/s24_d1.db`
- [Division 2 season data](https://github.com/akiratorizawa/afg-bot/blob/main/app/databases/s24_d2.db): `app/databases/s24_d2.db`
- [Division 1 game logs](https://github.com/akiratorizawa/afg-bot/blob/main/app/databases/s24_d1_logs.db): `app/databases/s24_d1_logs.db`
- [Division 2 game logs](https://github.com/akiratorizawa/afg-bot/blob/main/app/databases/s24_d2_logs.db): `app/databases/s24_d2_logs.db`

### Other components

- **Discord user**
- **Roblox user and avatar APIs**

## Connections

- Discord user → Command handlers: invokes commands (evidence: `bot.py`)
- Command handlers → Bot initialization: initializes (evidence: `bot.py`)
- Command handlers → Player autocomplete: gets suggestions (evidence: `bot.py`)
- Command handlers → Season stat updates: records stats (evidence: `bot.py`)
- Command handlers → Game report: builds report (evidence: `bot.py`)
- Command handlers → Game log: logs game (evidence: `bot.py`)
- Command handlers → Stream announcement: creates announcement (evidence: `bot.py`)
- Command handlers → Player stat view: requests stats (evidence: `bot.py`)
- Command handlers → Stat transfer: transfers stats (evidence: `bot.py`)
- Season stat updates → Division 1 season data: updates totals (evidence: `services/stats.py`)
- Season stat updates → Division 2 season data: updates totals (evidence: `services/stats.py`)
- Game log → Division 1 game logs: writes game rows (evidence: `services/log_game.py`)
- Game log → Division 2 game logs: writes game rows (evidence: `services/log_game.py`)
- Stat transfer → Division 1 season data: reads and updates (evidence: `services/transfer_stats.py`)
- Stat transfer → Division 2 season data: reads and updates (evidence: `services/transfer_stats.py`)
- Player stat view → Division 1 season data: reads player stats (evidence: `services/view_stats.py`)
- Player stat view → Roblox user and avatar APIs: gets avatar (evidence: `services/view_stats.py`)
- Game report → Roblox user and avatar APIs: gets avatars (evidence: `services/game_report.py`)
- Player autocomplete → Division 1 season data: queries players (evidence: `utility/get_players.py`)
- Flask routes and queries → Division 1 season data: reads stats (evidence: `app/app.py`)
- Flask routes and queries → Division 2 season data: reads stats (evidence: `app/app.py`)
- Flask routes and queries → Division 1 game logs: reads game history (evidence: `app/app.py`)
- Flask routes and queries → Division 2 game logs: reads game history (evidence: `app/app.py`)
- Flask routes and queries → Leaderboard and profile views: renders pages (evidence: `app/app.py`)
