# rfc1036/whois architecture

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

- Interactive diagram: https://gitdiagram.com/rfc1036/whois
- Repository: https://github.com/rfc1036/whois

## Overview

##### Project Type and Purpose
- This is a command-line WHOIS client and related utilities (mkpasswd) written in C.
- It contains an internal database of WHOIS servers and resource deletion lists, plus scripts to regenerate those data files.
- It is not a multi-tier web app, but an open-source tool that builds into standalone binaries and is packaged for Debian.

##### File Structure
- Source code (whois.c, utils.c, simple_recode.c, mkpasswd.c) and headers (.h) sit at the top level.
- Supporting data files (ip_del_list, as_del_list, tld_serv_list, etc.) and scripts (make_ip_del.pl, make_new_gtlds.pl, etc.) form a data-generation pipeline.
- Configuration: whois.conf, config.h, data.h
- Documentation & localization: manpages (.1, .5), README, po/ translations.
- Packaging: debian/ directory with control files, changelog, rules.
- Build orchestration: Makefile, .github/workflows/release.yml.

##### Extract Insights from README
- Core feature: “intelligent” server selection, built-in database more accurate than IANA’s.
- Contains mkpasswd utility for crypt(3) password hashing.
- Data sources: RIPE, IANA, ICANN.

##### Main Components
a. CLI Frontend
- whois binary – parses user arguments, orchestrates query
- mkpasswd binary – separate utility for password hashing
b. Core Library Modules
- Parser & Dispatcher (whois.c)
- Networking Module (sockets, TCP to WHOIS servers)
- Data Module (compiled‐in tables from data.h, config.h)
- Encoding Module (simple_recode.c, utils.c for IDN, charset handling)
c. Data-Generation Pipeline (build‐time)
- Perl scripts (make_*.pl) & list files (*.list) → generate .h lists
- make_version_h.pl → embed version in source
d. Configuration & Packaging
- Static config files (whois.conf)
- Debian packaging (debian/ directory)
- CI/CD (GitHub Actions release.yml)
e. External Services
- Public WHOIS servers (IANA, RIPE, ccTLD registries)
- System crypt(3) library for mkpasswd

##### Relationships & Data Flows
- Runtime: User’s shell → whois CLI → uses Data Module to map query to target server → Networking Module opens socket to that server → receives response → Parser formats output → tty.
- mkpasswd: User input → mkpasswd CLI → crypt(3) → prints hashed password.
- Build-time: list files + scripts → generate headers → compiled into Data Module → linked into binaries.
- Packaging: Makefile invokes build-time pipeline, compiles sources, packages via debian/rules.

##### Architectural Patterns & Principles
- Monolithic CLI binary split into functional modules (parser, net, data).
- Build-time code generation for static data.
- Clear separation of concerns: query handling vs. data management vs. networking vs. encoding.
- Localization: PO files for message translation.

## Diagram (Mermaid)

```mermaid
flowchart TB
    %% Runtime Layer
    subgraph "Runtime"
        direction TB
        User["User"]:::external
        whois["whois CLI"]:::binaries
        mkpasswd["mkpasswd CLI"]:::binaries
        subgraph "Modules"
            direction TB
            Parser["Parser & Dispatcher Module"]:::modules
            Network["Networking Module"]:::modules
            DataModule["Data Module"]:::modules
            Encoding["Encoding Module"]:::modules
        end
        ExternalWHOIS["External WHOIS Servers"]:::external
        CryptLib["crypt(3) Library"]:::external
    end

    %% Build Pipeline
    subgraph "Build Pipeline"
        direction TB
        Scripts["Data-Gen Scripts"]:::pipeline
        GenHeaders["Generated Headers"]:::pipeline
        Compiler["Compiler"]:::pipeline
    end

    %% Packaging & CI/CD
    subgraph "Packaging & CI/CD"
        direction TB
        MakefileNode["Makefile"]:::packaging
        CI["GitHub Actions CI/CD"]:::packaging
        DebianPkg["Debian Packaging"]:::packaging
    end

    %% Localization
    subgraph "Localization"
        direction TB
        PO["po/ Translations"]:::localization
    end

    %% Runtime Flows
    User -->|"runs"| whois
    User -->|"runs"| mkpasswd
    whois -->|"uses"| Parser
    whois -->|"uses"| Network
    whois -->|"uses"| DataModule
    whois -->|"uses"| Encoding
    Parser -->|"formats query"| Network
    DataModule -->|"provides server lists"| Parser
    Network -->|"TCP socket"| ExternalWHOIS
    ExternalWHOIS -->|"WHOIS response"| Network
    Network -->|"raw data"| Parser
    Parser -->|"formatted output"| User

    mkpasswd -->|"calls"| CryptLib
    CryptLib -->|"hashed password"| mkpasswd
    mkpasswd -->|"output"| User

    %% Build Pipeline Flows
    Scripts -->|"generate .h"| GenHeaders
    GenHeaders -->|"compiled into"| Compiler
    Compiler -->|"builds binaries"| whois
    Compiler -->|"builds binaries"| mkpasswd

    %% Packaging & CI/CD Flows
    MakefileNode -->|"orchestrates build"| Scripts
    MakefileNode -->|"calls"| Compiler
    MakefileNode -->|"invokes"| CI
    CI -->|"publishes artifacts"| DebianPkg
    DebianPkg -->|"produces Debian package"| whois
    DebianPkg -->|"produces Debian package"| mkpasswd

    %% Localization Link
    PO -->|"translations for"| whois
    PO -->|"translations for"| mkpasswd

    %% Click Events
    click whois "https://github.com/rfc1036/whois/blob/next/whois.c"
    click mkpasswd "https://github.com/rfc1036/whois/blob/next/mkpasswd.c"
    click Parser "https://github.com/rfc1036/whois/blob/next/whois.c"
    click Network "https://github.com/rfc1036/whois/blob/next/whois.c"
    click DataModule "https://github.com/rfc1036/whois/blob/next/data.h"
    click Encoding "https://github.com/rfc1036/whois/blob/next/simple_recode.c"
    click Scripts "https://github.com/rfc1036/whois/blob/next/make_ip_del.pl"
    click MakefileNode "https://github.com/rfc1036/whois/tree/next/Makefile"
    click CI "https://github.com/rfc1036/whois/blob/next/.github/workflows/release.yml"
    click DebianPkg "https://github.com/rfc1036/whois/tree/next/debian/"
    click PO "https://github.com/rfc1036/whois/tree/next/po/"

    %% Styles
    classDef binaries fill:#D0E8FF,stroke:#0366D6,color:#0366D6;
    classDef modules fill:#E8FDD0,stroke:#228B22,color:#228B22;
    classDef pipeline fill:#FFE8B0,stroke:#FF8C00,color:#FF8C00;
    classDef packaging fill:#E8D0FF,stroke:#6A0DAD,color:#6A0DAD;
    classDef external fill:#FFD0D0,stroke:#D20000,color:#D20000;
    classDef localization fill:#FFF5D0,stroke:#DAA520,color:#DAA520;
```
