# antusantury/blackdiamond architecture

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

- Interactive diagram: https://gitdiagram.com/antusantury/blackdiamond
- Repository: https://github.com/antusantury/blackdiamond

## Overview

Black Diamond is a cross-platform escrow service: buyers and sellers use Telegram or the web interface to create or join a deal, fund escrow, confirm delivery, and release funds through seller withdrawal. Both interfaces share deal, database, payment, commission, notification, and security capabilities. The README documents this lifecycle and TON support; sampled code and the source index support selected implementation links. Several subsystems, including frontend behavior and some backend services, were not fully sampled, so their internal connections are omitted.

Main entry points: [`bot/handlers/unified_handler.py`](https://github.com/antusantury/blackdiamond/blob/main/bot/handlers/unified_handler.py) (Bot deal actions), [`web/join_deal.py`](https://github.com/antusantury/blackdiamond/blob/main/web/join_deal.py) (Seller join), [`web/app.py`](https://github.com/antusantury/blackdiamond/blob/main/web/app.py) (Web interface), [`shared/database/database.py`](https://github.com/antusantury/blackdiamond/blob/main/shared/database/database.py) (Deal database)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_interfaces["User interfaces"]
  node_telegram(("Telegram"))
  node_bot["Telegram bot<br/>[main.py]"]
  node_bot_workflow["Bot deal actions<br/>[unified_handler.py]"]
  node_web["Web interface<br/>[app.py]"]
  node_join["Seller join<br/>[join_deal.py]"]
  node_web_client["Web client<br/>[main.js]"]
  node_api["Cross-platform API"]
end

subgraph group_escrow["Escrow workflow"]
  node_deal["Deal processing<br/>[deal_processor.py]"]
end

subgraph group_shared["Shared services"]
  node_database[("Deal database<br/>[database.py]")]
  node_payments["Blockchain payments"]
  node_commission["Fee calculation<br/>[commission.py]"]
  node_security["Authorization"]
  node_notifications["Notifications<br/>[notifications.py]"]
  node_platform_sync["Platform synchronization<br/>[platform_sync.py]"]
end

subgraph group_integrations["External services"]
  node_ton{{"TON blockchain"}}
  node_telegram_service{{"Telegram messaging"}}
end

node_participants(("Buyer / seller"))

node_participants -->|"use"| node_telegram
node_participants -->|"use"| node_web
node_telegram -->|"send updates"| node_bot
node_bot -->|"register handlers"| node_bot_workflow
node_participants -->|"request deal actions"| node_bot_workflow
node_participants -->|"use"| node_web_client
node_web_client -.->|"request web actions"| node_web
node_participants -->|"join deal"| node_join
node_bot_workflow -->|"read and update deals"| node_database
node_bot_workflow -->|"check payments"| node_payments
node_bot_workflow -->|"calculate fees"| node_commission
node_bot_workflow -->|"authorize actions"| node_security
node_web -->|"read deal"| node_database
node_web -->|"calculate fees"| node_commission
node_join -->|"read and join deal"| node_database
node_join -->|"get payment details"| node_payments
node_join -->|"calculate fees"| node_commission
node_join -->|"notify buyer"| node_notifications
node_api -->|"access deal data"| node_database
node_api -->|"synchronize platforms"| node_platform_sync
node_api -->|"send notifications"| node_notifications
node_payments -->|"verify TON payments"| node_ton
node_notifications -->|"send messages"| node_telegram_service

click node_bot "https://github.com/antusantury/blackdiamond/blob/main/bot/main.py"
click node_bot_workflow "https://github.com/antusantury/blackdiamond/blob/main/bot/handlers/unified_handler.py"
click node_web "https://github.com/antusantury/blackdiamond/blob/main/web/app.py"
click node_join "https://github.com/antusantury/blackdiamond/blob/main/web/join_deal.py"
click node_web_client "https://github.com/antusantury/blackdiamond/blob/main/static/js/main.js"
click node_deal "https://github.com/antusantury/blackdiamond/blob/main/shared/deal_processor.py"
click node_database "https://github.com/antusantury/blackdiamond/blob/main/shared/database/database.py"
click node_payments "https://github.com/antusantury/blackdiamond/blob/main/shared/decentralized_payments.py"
click node_commission "https://github.com/antusantury/blackdiamond/blob/main/shared/commission.py"
click node_security "https://github.com/antusantury/blackdiamond/blob/main/bot/security/zero_trust_security.py"
click node_notifications "https://github.com/antusantury/blackdiamond/blob/main/shared/notifications.py"
click node_platform_sync "https://github.com/antusantury/blackdiamond/blob/main/shared/platform_sync.py"
click node_api "https://github.com/antusantury/blackdiamond/blob/main/web/cross_platform_api.py"

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,node_bot,node_bot_workflow,node_web,node_join,node_web_client,node_api toneBlue
class node_deal toneAmber
class node_database,node_payments,node_commission,node_security,node_notifications,node_platform_sync toneMint
class node_ton,node_telegram_service toneRose
class node_participants toneIndigo
```

## Components

### User interfaces

- **Telegram**
- [Telegram bot](https://github.com/antusantury/blackdiamond/blob/main/bot/main.py): `bot/main.py`
- [Bot deal actions](https://github.com/antusantury/blackdiamond/blob/main/bot/handlers/unified_handler.py): `bot/handlers/unified_handler.py`
- [Web interface](https://github.com/antusantury/blackdiamond/blob/main/web/app.py): `web/app.py`
- [Seller join](https://github.com/antusantury/blackdiamond/blob/main/web/join_deal.py): `web/join_deal.py`
- [Web client](https://github.com/antusantury/blackdiamond/blob/main/static/js/main.js): `static/js/main.js`
- [Cross-platform API](https://github.com/antusantury/blackdiamond/blob/main/web/cross_platform_api.py): `web/cross_platform_api.py`

### Escrow workflow

- [Deal processing](https://github.com/antusantury/blackdiamond/blob/main/shared/deal_processor.py): `shared/deal_processor.py`

### Shared services

- [Deal database](https://github.com/antusantury/blackdiamond/blob/main/shared/database/database.py): `shared/database/database.py`
- [Blockchain payments](https://github.com/antusantury/blackdiamond/blob/main/shared/decentralized_payments.py): `shared/decentralized_payments.py`
- [Fee calculation](https://github.com/antusantury/blackdiamond/blob/main/shared/commission.py): `shared/commission.py`
- [Authorization](https://github.com/antusantury/blackdiamond/blob/main/bot/security/zero_trust_security.py): `bot/security/zero_trust_security.py`
- [Notifications](https://github.com/antusantury/blackdiamond/blob/main/shared/notifications.py): `shared/notifications.py`
- [Platform synchronization](https://github.com/antusantury/blackdiamond/blob/main/shared/platform_sync.py): `shared/platform_sync.py`

### External services

- **TON blockchain**
- **Telegram messaging**

### Other components

- **Buyer / seller**

## Connections

- Buyer / seller → Telegram: use
- Buyer / seller → Web interface: use
- Telegram → Telegram bot: send updates
- Telegram bot → Bot deal actions: register handlers (evidence: `bot/main.py`)
- Buyer / seller → Bot deal actions: request deal actions
- Buyer / seller → Web client: use
- Web client → Web interface: request web actions
- Buyer / seller → Seller join: join deal
- Bot deal actions → Deal database: read and update deals (evidence: `bot/handlers/unified_handler.py`)
- Bot deal actions → Blockchain payments: check payments (evidence: `bot/handlers/unified_handler.py`)
- Bot deal actions → Fee calculation: calculate fees (evidence: `bot/handlers/unified_handler.py`)
- Bot deal actions → Authorization: authorize actions (evidence: `bot/handlers/unified_handler.py`)
- Web interface → Deal database: read deal (evidence: `web/app.py`)
- Web interface → Fee calculation: calculate fees (evidence: `web/app.py`)
- Seller join → Deal database: read and join deal (evidence: `web/join_deal.py`)
- Seller join → Blockchain payments: get payment details (evidence: `web/join_deal.py`)
- Seller join → Fee calculation: calculate fees (evidence: `web/join_deal.py`)
- Seller join → Notifications: notify buyer (evidence: `web/join_deal.py`)
- Cross-platform API → Deal database: access deal data (evidence: `web/cross_platform_api.py`)
- Cross-platform API → Platform synchronization: synchronize platforms (evidence: `web/cross_platform_api.py`)
- Cross-platform API → Notifications: send notifications (evidence: `web/cross_platform_api.py`)
- Blockchain payments → TON blockchain: verify TON payments
- Notifications → Telegram messaging: send messages (evidence: `shared/notifications.py`)
