# systemreset-ca/bruhlegends architecture

> Architecture diagram of the GitHub repository systemreset-ca/bruhlegends, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2026-09-21). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/systemreset-ca/bruhlegends
- Repository: https://github.com/systemreset-ca/bruhlegends
- Video tour (about a minute): https://gitdiagram.com/systemreset-ca/bruhlegends/video

## Overview

BRUH Legends is a Telegram bot and Mini App for crypto-call attribution, market tracking, community reputation, group administration, and gated Solana tipping. The principal workflow is Telegram update receipt, durable processing, call validation and tracking, score/leaderboard updates, and optional tip settlement; the Mini App exposes authenticated group, reputation, wallet, and data controls. The tree and sampled files confirm webhook durability, session verification, delivery idempotency, and Supabase persistence. Several bot handlers and scheduled workers are represented from documented capabilities but were not sampled directly.

Main entry points: [`src/lib/bot.server.ts`](https://github.com/systemreset-ca/bruhlegends/blob/main/src/lib/bot.server.ts) (Bot Runtime), [`src/lib/miniapp.functions.ts`](https://github.com/systemreset-ca/bruhlegends/blob/main/src/lib/miniapp.functions.ts) (Mini App API), [`src/lib/account-tip.functions.ts`](https://github.com/systemreset-ca/bruhlegends/blob/main/src/lib/account-tip.functions.ts) (Tip Request), [`src/lib/telegram-updates.server.ts`](https://github.com/systemreset-ca/bruhlegends/blob/main/src/lib/telegram-updates.server.ts) (Update Processor)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_telegram["Telegram Runtime"]
  node_telegram_webhook["Update Webhook<br/>[webhook.ts]"]
  node_telegram_updates["Update Processor"]
  node_telegram_delivery["Delivery Queue"]
  node_bot_runtime["Bot Runtime<br/>[bot.server.ts]"]
end

subgraph group_reputation["Calls And Reputation"]
  node_call_tracking["Call Tracking<br/>[calls.server.ts]"]
  node_market_tracking["Market Tracking<br/>[market.server.ts]"]
  node_scoring["BRUH Scoring<br/>[scoring.server.ts]"]
  node_leaderboards["Community Leaderboards"]
  node_participation["Participation Ledger"]
  node_moderation["Group Moderation"]
end

subgraph group_wallet["Wallet And Tipping"]
  node_wallet_onboarding["Wallet Onboarding"]
  node_tip_request["Tip Request"]
  node_tip_preparation["Tip Preparation"]
  node_tip_execution["Tip Execution"]
  node_tip_settlement["Tip Settlement"]
  node_wallet_vault["Encrypted Wallet Vault"]
end

subgraph group_miniapp["Mini App"]
  node_miniapp_ui["Mini App UI<br/>[app.tsx]"]
  node_miniapp_api["Mini App API"]
  node_session_auth["Session Authentication<br/>[session.server.ts]"]
end

subgraph group_platform["Persistence And Integrations"]
  node_database[("Supabase Database<br/>[client.server.ts]")]
end

node_telegram_user(("Telegram User"))
node_telegram_service(("Telegram Platform"))
node_solana_network(("Solana Network"))
node_market_service(("Market Data Service"))

node_telegram_user -->|"sends updates"| node_telegram_service
node_telegram_service -->|"posts updates"| node_telegram_webhook
node_telegram_webhook -->|"stores and processes"| node_telegram_updates
node_telegram_updates -->|"dispatches update"| node_bot_runtime
node_telegram_updates -->|"queues delivery"| node_telegram_delivery
node_telegram_delivery -->|"persists actions"| node_database
node_bot_runtime -->|"records calls"| node_call_tracking
node_call_tracking -->|"refreshes metrics"| node_market_tracking
node_market_tracking -.->|"reads prices"| node_market_service
node_call_tracking -->|"feeds scores"| node_scoring
node_scoring -->|"updates rankings"| node_leaderboards
node_bot_runtime -->|"applies settings"| node_moderation
node_bot_runtime -->|"records actions"| node_participation
node_bot_runtime -->|"creates tip"| node_tip_request
node_tip_request -->|"prepares tip"| node_tip_preparation
node_tip_request -->|"executes tip"| node_tip_execution
node_tip_request -->|"settles tip"| node_tip_settlement
node_tip_preparation -->|"authorizes wallet"| node_wallet_vault
node_tip_execution -->|"submits transfer"| node_solana_network
node_tip_settlement -->|"credits history"| node_database
node_telegram_delivery -->|"sends replies"| node_telegram_service
node_miniapp_ui -->|"calls app actions"| node_miniapp_api
node_miniapp_api -->|"resolves session"| node_session_auth
node_miniapp_api -->|"reads rankings"| node_leaderboards
node_miniapp_api -->|"reads credits"| node_participation
node_miniapp_api -->|"starts wallet setup"| node_wallet_onboarding
node_session_auth -->|"reads sessions"| node_database
node_wallet_onboarding -->|"creates wallet"| node_wallet_vault
node_database -->|"stores receipts"| node_telegram_updates

click node_telegram_webhook "https://github.com/systemreset-ca/bruhlegends/blob/main/src/routes/api/public/telegram/webhook.ts"
click node_telegram_updates "https://github.com/systemreset-ca/bruhlegends/blob/main/src/lib/telegram-updates.server.ts"
click node_telegram_delivery "https://github.com/systemreset-ca/bruhlegends/blob/main/src/lib/telegram-delivery-context.server.ts"
click node_bot_runtime "https://github.com/systemreset-ca/bruhlegends/blob/main/src/lib/bot.server.ts"
click node_call_tracking "https://github.com/systemreset-ca/bruhlegends/blob/main/src/lib/calls.server.ts"
click node_market_tracking "https://github.com/systemreset-ca/bruhlegends/blob/main/src/lib/market.server.ts"
click node_scoring "https://github.com/systemreset-ca/bruhlegends/blob/main/src/lib/scoring.server.ts"
click node_leaderboards "https://github.com/systemreset-ca/bruhlegends/blob/main/src/lib/community-leaderboard.server.ts"
click node_participation "https://github.com/systemreset-ca/bruhlegends/blob/main/src/lib/participation.server.ts"
click node_moderation "https://github.com/systemreset-ca/bruhlegends/blob/main/src/lib/moderation.server.ts"
click node_miniapp_ui "https://github.com/systemreset-ca/bruhlegends/blob/main/src/routes/app.tsx"
click node_miniapp_api "https://github.com/systemreset-ca/bruhlegends/blob/main/src/lib/miniapp.functions.ts"
click node_session_auth "https://github.com/systemreset-ca/bruhlegends/blob/main/src/lib/session.server.ts"
click node_wallet_onboarding "https://github.com/systemreset-ca/bruhlegends/blob/main/src/lib/wallet-onboarding.server.ts"
click node_tip_request "https://github.com/systemreset-ca/bruhlegends/blob/main/src/lib/account-tip.functions.ts"
click node_tip_preparation "https://github.com/systemreset-ca/bruhlegends/blob/main/src/lib/account-tip-preparation.server.ts"
click node_tip_execution "https://github.com/systemreset-ca/bruhlegends/blob/main/src/lib/account-tip-execution.server.ts"
click node_tip_settlement "https://github.com/systemreset-ca/bruhlegends/blob/main/src/lib/account-tip-settlement.server.ts"
click node_wallet_vault "https://github.com/systemreset-ca/bruhlegends/blob/main/src/lib/account-wallet-vault.server.ts"
click node_database "https://github.com/systemreset-ca/bruhlegends/blob/main/src/integrations/supabase/client.server.ts"

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_telegram_webhook,node_telegram_updates,node_telegram_delivery,node_bot_runtime,node_telegram_user toneBlue
class node_call_tracking,node_market_tracking,node_scoring,node_leaderboards,node_participation,node_moderation toneAmber
class node_wallet_onboarding,node_tip_request,node_tip_preparation,node_tip_execution,node_tip_settlement,node_wallet_vault toneMint
class node_miniapp_ui,node_miniapp_api,node_session_auth toneRose
class node_database,node_telegram_service,node_solana_network,node_market_service toneIndigo
```

## Components

### Telegram Runtime

- [Update Webhook](https://github.com/systemreset-ca/bruhlegends/blob/main/src/routes/api/public/telegram/webhook.ts): `src/routes/api/public/telegram/webhook.ts`
- [Update Processor](https://github.com/systemreset-ca/bruhlegends/blob/main/src/lib/telegram-updates.server.ts): `src/lib/telegram-updates.server.ts`
- [Delivery Queue](https://github.com/systemreset-ca/bruhlegends/blob/main/src/lib/telegram-delivery-context.server.ts): `src/lib/telegram-delivery-context.server.ts`
- [Bot Runtime](https://github.com/systemreset-ca/bruhlegends/blob/main/src/lib/bot.server.ts): `src/lib/bot.server.ts`

### Calls And Reputation

- [Call Tracking](https://github.com/systemreset-ca/bruhlegends/blob/main/src/lib/calls.server.ts): `src/lib/calls.server.ts`
- [Market Tracking](https://github.com/systemreset-ca/bruhlegends/blob/main/src/lib/market.server.ts): `src/lib/market.server.ts`
- [BRUH Scoring](https://github.com/systemreset-ca/bruhlegends/blob/main/src/lib/scoring.server.ts): `src/lib/scoring.server.ts`
- [Community Leaderboards](https://github.com/systemreset-ca/bruhlegends/blob/main/src/lib/community-leaderboard.server.ts): `src/lib/community-leaderboard.server.ts`
- [Participation Ledger](https://github.com/systemreset-ca/bruhlegends/blob/main/src/lib/participation.server.ts): `src/lib/participation.server.ts`
- [Group Moderation](https://github.com/systemreset-ca/bruhlegends/blob/main/src/lib/moderation.server.ts): `src/lib/moderation.server.ts`

### Wallet And Tipping

- [Wallet Onboarding](https://github.com/systemreset-ca/bruhlegends/blob/main/src/lib/wallet-onboarding.server.ts): `src/lib/wallet-onboarding.server.ts`
- [Tip Request](https://github.com/systemreset-ca/bruhlegends/blob/main/src/lib/account-tip.functions.ts): `src/lib/account-tip.functions.ts`
- [Tip Preparation](https://github.com/systemreset-ca/bruhlegends/blob/main/src/lib/account-tip-preparation.server.ts): `src/lib/account-tip-preparation.server.ts`
- [Tip Execution](https://github.com/systemreset-ca/bruhlegends/blob/main/src/lib/account-tip-execution.server.ts): `src/lib/account-tip-execution.server.ts`
- [Tip Settlement](https://github.com/systemreset-ca/bruhlegends/blob/main/src/lib/account-tip-settlement.server.ts): `src/lib/account-tip-settlement.server.ts`
- [Encrypted Wallet Vault](https://github.com/systemreset-ca/bruhlegends/blob/main/src/lib/account-wallet-vault.server.ts): `src/lib/account-wallet-vault.server.ts`

### Mini App

- [Mini App UI](https://github.com/systemreset-ca/bruhlegends/blob/main/src/routes/app.tsx): `src/routes/app.tsx`
- [Mini App API](https://github.com/systemreset-ca/bruhlegends/blob/main/src/lib/miniapp.functions.ts): `src/lib/miniapp.functions.ts`
- [Session Authentication](https://github.com/systemreset-ca/bruhlegends/blob/main/src/lib/session.server.ts): `src/lib/session.server.ts`

### Persistence And Integrations

- [Supabase Database](https://github.com/systemreset-ca/bruhlegends/blob/main/src/integrations/supabase/client.server.ts): `src/integrations/supabase/client.server.ts`

### Other components

- **Telegram User**
- **Telegram Platform**
- **Solana Network**
- **Market Data Service**

## Connections

- Telegram User → Telegram Platform: sends updates
- Telegram Platform → Update Webhook: posts updates
- Update Webhook → Update Processor: stores and processes
- Update Processor → Bot Runtime: dispatches update
- Update Processor → Delivery Queue: queues delivery
- Delivery Queue → Supabase Database: persists actions
- Bot Runtime → Call Tracking: records calls
- Call Tracking → Market Tracking: refreshes metrics
- Market Tracking → Market Data Service: reads prices
- Call Tracking → BRUH Scoring: feeds scores
- BRUH Scoring → Community Leaderboards: updates rankings
- Bot Runtime → Group Moderation: applies settings
- Bot Runtime → Participation Ledger: records actions
- Bot Runtime → Tip Request: creates tip
- Tip Request → Tip Preparation: prepares tip
- Tip Request → Tip Execution: executes tip
- Tip Request → Tip Settlement: settles tip
- Tip Preparation → Encrypted Wallet Vault: authorizes wallet
- Tip Execution → Solana Network: submits transfer
- Tip Settlement → Supabase Database: credits history
- Delivery Queue → Telegram Platform: sends replies
- Mini App UI → Mini App API: calls app actions
- Mini App API → Session Authentication: resolves session
- Mini App API → Community Leaderboards: reads rankings
- Mini App API → Participation Ledger: reads credits
- Mini App API → Wallet Onboarding: starts wallet setup
- Session Authentication → Supabase Database: reads sessions
- Wallet Onboarding → Encrypted Wallet Vault: creates wallet
- Supabase Database → Update Processor: stores receipts
