# iqbwl/whoisbot architecture

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

- Interactive diagram: https://gitdiagram.com/iqbwl/whoisbot
- Repository: https://github.com/iqbwl/whoisbot

## Overview

WhoisBot accepts Telegram /whois commands or exposes the same lookup engine as a library. The command handler parses options, delegates lookup orchestration, and formats a Telegram-friendly response; the engine routes IPs to RIR WHOIS and domains through RDAP/WHOIS according to flags and fallback rules. The graph preserves the distinct Telegram, routing, protocol-client, and formatting/data layers. Relationships are cited where shown; unsampled start handling and static registry content are not expanded beyond documented behavior.

Main entry points: [`src/services/lookupService.js`](https://github.com/iqbwl/whoisbot/blob/master/src/services/lookupService.js) (Lookup orchestrator), [`src/bot/handlers/whois.js`](https://github.com/iqbwl/whoisbot/blob/master/src/bot/handlers/whois.js) (WHOIS command), [`src/bot/bot.js`](https://github.com/iqbwl/whoisbot/blob/master/src/bot/bot.js) (Bot registration), [`src/services/whoisClient.js`](https://github.com/iqbwl/whoisbot/blob/master/src/services/whoisClient.js) (WHOIS client)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_telegram["Telegram interface"]
  node_entry["Application entry<br/>[index.js]"]
  node_bot["Bot registration<br/>[bot.js]"]
  node_start["Start handler<br/>[start.js]"]
  node_command["WHOIS command<br/>[whois.js]"]
end

subgraph group_routing["Lookup routing"]
  node_lookup["Lookup orchestrator<br/>[lookupService.js]"]
  node_validator["Input and RIR routing<br/>[validator.js]"]
end

subgraph group_protocols["Registry protocols"]
  node_rdap["RDAP client<br/>[rdapClient.js]"]
  node_whois["WHOIS client<br/>[whoisClient.js]"]
  node_http["HTTP transport<br/>[httpClient.js]"]
end

subgraph group_presentation["Results and configuration"]
  node_format_domain["Domain formatting<br/>[domainFormatter.js]"]
  node_format_ip["IP formatting<br/>[ipFormatter.js]"]
  node_telegram_format["Telegram text helpers<br/>[telegram.js]"]
  node_config["Runtime configuration<br/>[index.js]"]
  node_data[("Registry data loader<br/>[dataLoader.js]")]
end

node_user(("Telegram user"))
node_telegram_api(("Telegram API"))
node_rdap_service(("RDAP registries"))
node_whois_service(("WHOIS servers"))

node_user -->|"sends commands"| node_bot
node_entry -->|"creates bot"| node_bot
node_entry -->|"exports lookup"| node_lookup
node_bot -->|"registers start"| node_start
node_bot -->|"registers messages"| node_command
node_command -->|"requests lookup"| node_lookup
node_command -->|"escapes text"| node_telegram_format
node_command -->|"replies and edits"| node_telegram_api
node_bot -.->|"runs bot"| node_telegram_api
node_lookup -->|"normalizes and classifies"| node_validator
node_lookup -->|"queries IP or domain"| node_whois
node_lookup -->|"queries RDAP"| node_rdap
node_lookup -->|"formats domain result"| node_format_domain
node_lookup -->|"formats IP result"| node_format_ip
node_rdap -->|"fetches JSON"| node_http
node_rdap -->|"reads registry map"| node_data
node_whois -->|"reads server map"| node_data
node_whois -->|"detects RIR"| node_validator
node_http -->|"requests RDAP"| node_rdap_service
node_whois -->|"queries port 43"| node_whois_service
node_validator -->|"uses RIR settings"| node_config
node_validator -->|"checks registry maps"| node_data
node_command -->|"reads output limits"| node_config

click node_entry "https://github.com/iqbwl/whoisbot/blob/master/index.js"
click node_bot "https://github.com/iqbwl/whoisbot/blob/master/src/bot/bot.js"
click node_start "https://github.com/iqbwl/whoisbot/blob/master/src/bot/handlers/start.js"
click node_command "https://github.com/iqbwl/whoisbot/blob/master/src/bot/handlers/whois.js"
click node_lookup "https://github.com/iqbwl/whoisbot/blob/master/src/services/lookupService.js"
click node_validator "https://github.com/iqbwl/whoisbot/blob/master/src/utils/validator.js"
click node_rdap "https://github.com/iqbwl/whoisbot/blob/master/src/services/rdapClient.js"
click node_whois "https://github.com/iqbwl/whoisbot/blob/master/src/services/whoisClient.js"
click node_http "https://github.com/iqbwl/whoisbot/blob/master/src/utils/httpClient.js"
click node_format_domain "https://github.com/iqbwl/whoisbot/blob/master/src/formatters/domainFormatter.js"
click node_format_ip "https://github.com/iqbwl/whoisbot/blob/master/src/formatters/ipFormatter.js"
click node_telegram_format "https://github.com/iqbwl/whoisbot/blob/master/src/utils/telegram.js"
click node_config "https://github.com/iqbwl/whoisbot/blob/master/src/config/index.js"
click node_data "https://github.com/iqbwl/whoisbot/blob/master/src/config/dataLoader.js"

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_entry,node_bot,node_start,node_command,node_user toneBlue
class node_lookup,node_validator toneAmber
class node_rdap,node_whois,node_http,node_telegram_api,node_whois_service toneMint
class node_format_domain,node_format_ip,node_telegram_format,node_config,node_data toneRose
class node_rdap_service toneIndigo
```

## Components

### Telegram interface

- [Application entry](https://github.com/iqbwl/whoisbot/blob/master/index.js): `index.js`
- [Bot registration](https://github.com/iqbwl/whoisbot/blob/master/src/bot/bot.js): `src/bot/bot.js`
- [Start handler](https://github.com/iqbwl/whoisbot/blob/master/src/bot/handlers/start.js): `src/bot/handlers/start.js`
- [WHOIS command](https://github.com/iqbwl/whoisbot/blob/master/src/bot/handlers/whois.js): `src/bot/handlers/whois.js`

### Lookup routing

- [Lookup orchestrator](https://github.com/iqbwl/whoisbot/blob/master/src/services/lookupService.js): `src/services/lookupService.js`
- [Input and RIR routing](https://github.com/iqbwl/whoisbot/blob/master/src/utils/validator.js): `src/utils/validator.js`

### Registry protocols

- [RDAP client](https://github.com/iqbwl/whoisbot/blob/master/src/services/rdapClient.js): `src/services/rdapClient.js`
- [WHOIS client](https://github.com/iqbwl/whoisbot/blob/master/src/services/whoisClient.js): `src/services/whoisClient.js`
- [HTTP transport](https://github.com/iqbwl/whoisbot/blob/master/src/utils/httpClient.js): `src/utils/httpClient.js`

### Results and configuration

- [Domain formatting](https://github.com/iqbwl/whoisbot/blob/master/src/formatters/domainFormatter.js): `src/formatters/domainFormatter.js`
- [IP formatting](https://github.com/iqbwl/whoisbot/blob/master/src/formatters/ipFormatter.js): `src/formatters/ipFormatter.js`
- [Telegram text helpers](https://github.com/iqbwl/whoisbot/blob/master/src/utils/telegram.js): `src/utils/telegram.js`
- [Runtime configuration](https://github.com/iqbwl/whoisbot/blob/master/src/config/index.js): `src/config/index.js`
- [Registry data loader](https://github.com/iqbwl/whoisbot/blob/master/src/config/dataLoader.js): `src/config/dataLoader.js`

### Other components

- **Telegram user**
- **Telegram API**
- **RDAP registries**
- **WHOIS servers**

## Connections

- Telegram user → Bot registration: sends commands (evidence: `README.md`)
- Application entry → Bot registration: creates bot (evidence: `index.js`)
- Application entry → Lookup orchestrator: exports lookup (evidence: `index.js`)
- Bot registration → Start handler: registers start (evidence: `src/bot/bot.js`)
- Bot registration → WHOIS command: registers messages (evidence: `src/bot/bot.js`)
- WHOIS command → Lookup orchestrator: requests lookup (evidence: `src/bot/handlers/whois.js`)
- WHOIS command → Telegram text helpers: escapes text (evidence: `src/bot/handlers/whois.js`)
- WHOIS command → Telegram API: replies and edits (evidence: `src/bot/handlers/whois.js`)
- Bot registration → Telegram API: runs bot
- Lookup orchestrator → Input and RIR routing: normalizes and classifies (evidence: `src/services/lookupService.js`)
- Lookup orchestrator → WHOIS client: queries IP or domain (evidence: `src/services/lookupService.js`)
- Lookup orchestrator → RDAP client: queries RDAP (evidence: `src/services/lookupService.js`)
- Lookup orchestrator → Domain formatting: formats domain result (evidence: `src/services/lookupService.js`)
- Lookup orchestrator → IP formatting: formats IP result (evidence: `src/services/lookupService.js`)
- RDAP client → HTTP transport: fetches JSON (evidence: `src/services/rdapClient.js`)
- RDAP client → Registry data loader: reads registry map (evidence: `src/services/rdapClient.js`)
- WHOIS client → Registry data loader: reads server map (evidence: `src/services/whoisClient.js`)
- WHOIS client → Input and RIR routing: detects RIR (evidence: `src/services/whoisClient.js`)
- HTTP transport → RDAP registries: requests RDAP
- WHOIS client → WHOIS servers: queries port 43 (evidence: `src/services/whoisClient.js`)
- Input and RIR routing → Runtime configuration: uses RIR settings (evidence: `src/utils/validator.js`)
- Input and RIR routing → Registry data loader: checks registry maps (evidence: `src/utils/validator.js`)
- WHOIS command → Runtime configuration: reads output limits (evidence: `src/bot/handlers/whois.js`)
