# heartleo/zlib architecture

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

- Interactive diagram: https://gitdiagram.com/heartleo/zlib
- Repository: https://github.com/heartleo/zlib

## Overview

zlib is a terminal client for Z-Library. Its principal workflow is login or import cookies, persist a session, then search interactively or statically, select a book, and download it; history, profile, domain diagnostics, themes, and Kindle delivery are additional capabilities. The CLI coordinates the domain client, which supports HTML and EAPI modes and challenge handling. Several command implementations are represented by their exact tree paths, but their source was not sampled; those relationships are included only where the README documents them.

Main entry points: [`internal/cli/login.go`](https://github.com/heartleo/zlib/blob/main/internal/cli/login.go) (Login), [`internal/cli/search.go`](https://github.com/heartleo/zlib/blob/main/internal/cli/search.go) (Search), [`client.go`](https://github.com/heartleo/zlib/blob/main/client.go) (HTTP client), [`cmd/zlib/main.go`](https://github.com/heartleo/zlib/blob/main/cmd/zlib/main.go) (CLI entry)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_cli["Terminal workflows"]
  node_entry["CLI entry<br/>[main.go]"]
  node_login["Login<br/>[login.go]"]
  node_search["Search<br/>[search.go]"]
  node_interactive_search["Search picker"]
  node_downloads_cli["Download command<br/>[download.go]"]
  node_history["History browser<br/>[history.go]"]
  node_profile_cli["Profile command<br/>[profile.go]"]
  node_doctor["Domain doctor<br/>[doctor.go]"]
  node_kindle_cli["Kindle delivery<br/>[kindle.go]"]
  node_themes["Themes<br/>[theme.go]"]
end

subgraph group_client["Z-Library access"]
  node_http_client["HTTP client<br/>[client.go]"]
  node_eapi["EAPI access<br/>[eapi.go]"]
  node_domain_probe["Domain probing<br/>[domain_probe.go]"]
  node_challenge["Challenge solver<br/>[challenge.go]"]
end

subgraph group_domain["Book operations"]
  node_search_core["Search engine<br/>[search.go]"]
  node_parser["Page parser<br/>[parser.go]"]
  node_book["Book details<br/>[book.go]"]
  node_download_core["File download<br/>[download.go]"]
  node_profile_core["Usage profile<br/>[profile.go]"]
  node_kindle_core["Kindle sender<br/>[kindle.go]"]
end

subgraph group_state["Local settings"]
  node_config[("Session settings<br/>[session.go]")]
end

node_user(("User"))
node_zlibrary{{"Z-Library service"}}
node_smtp{{"SMTP service"}}

node_user -->|"runs commands"| node_entry
node_entry -->|"routes login"| node_login
node_user -->|"searches books"| node_search
node_search -->|"queries"| node_search_core
node_search -->|"opens picker"| node_interactive_search
node_interactive_search -->|"starts download"| node_download_core
node_user -->|"requests download"| node_downloads_cli
node_downloads_cli -->|"downloads book"| node_download_core
node_user -->|"browses history"| node_history
node_user -->|"checks quota"| node_profile_cli
node_user -->|"checks domains"| node_doctor
node_user -->|"sends book"| node_kindle_cli
node_kindle_cli -->|"sends file"| node_kindle_core
node_kindle_core -->|"emails file"| node_smtp
node_user -->|"sets theme"| node_themes
node_login -->|"saves session"| node_config
node_login -->|"authenticates"| node_http_client
node_http_client -.->|"sends requests"| node_zlibrary
node_http_client -->|"solves challenge"| node_challenge
node_search_core -.->|"parses results"| node_parser
node_book -.->|"loads details"| node_zlibrary
node_eapi -.->|"calls API"| node_zlibrary
node_domain_probe -.->|"probes domains"| node_zlibrary
node_profile_cli -.->|"loads profile"| node_profile_core
node_history -.->|"loads history"| node_zlibrary

click node_entry "https://github.com/heartleo/zlib/blob/main/cmd/zlib/main.go"
click node_login "https://github.com/heartleo/zlib/blob/main/internal/cli/login.go"
click node_search "https://github.com/heartleo/zlib/blob/main/internal/cli/search.go"
click node_interactive_search "https://github.com/heartleo/zlib/blob/main/internal/cli/search_interactive.go"
click node_downloads_cli "https://github.com/heartleo/zlib/blob/main/internal/cli/download.go"
click node_history "https://github.com/heartleo/zlib/blob/main/internal/cli/history.go"
click node_profile_cli "https://github.com/heartleo/zlib/blob/main/internal/cli/profile.go"
click node_doctor "https://github.com/heartleo/zlib/blob/main/internal/cli/doctor.go"
click node_kindle_cli "https://github.com/heartleo/zlib/blob/main/internal/cli/kindle.go"
click node_themes "https://github.com/heartleo/zlib/blob/main/internal/cli/theme.go"
click node_config "https://github.com/heartleo/zlib/blob/main/internal/config/session.go"
click node_http_client "https://github.com/heartleo/zlib/blob/main/client.go"
click node_eapi "https://github.com/heartleo/zlib/blob/main/eapi.go"
click node_domain_probe "https://github.com/heartleo/zlib/blob/main/domain_probe.go"
click node_challenge "https://github.com/heartleo/zlib/blob/main/challenge.go"
click node_search_core "https://github.com/heartleo/zlib/blob/main/search.go"
click node_parser "https://github.com/heartleo/zlib/blob/main/parser.go"
click node_book "https://github.com/heartleo/zlib/blob/main/book.go"
click node_download_core "https://github.com/heartleo/zlib/blob/main/download.go"
click node_profile_core "https://github.com/heartleo/zlib/blob/main/profile.go"
click node_kindle_core "https://github.com/heartleo/zlib/blob/main/kindle.go"

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_login,node_search,node_interactive_search,node_downloads_cli,node_history,node_profile_cli,node_doctor,node_kindle_cli,node_themes,node_user toneBlue
class node_http_client,node_eapi,node_domain_probe,node_challenge toneAmber
class node_search_core,node_parser,node_book,node_download_core,node_profile_core,node_kindle_core toneMint
class node_config toneRose
class node_zlibrary,node_smtp toneIndigo
```

## Components

### Terminal workflows

- [CLI entry](https://github.com/heartleo/zlib/blob/main/cmd/zlib/main.go): `cmd/zlib/main.go`
- [Login](https://github.com/heartleo/zlib/blob/main/internal/cli/login.go): `internal/cli/login.go`
- [Search](https://github.com/heartleo/zlib/blob/main/internal/cli/search.go): `internal/cli/search.go`
- [Search picker](https://github.com/heartleo/zlib/blob/main/internal/cli/search_interactive.go): `internal/cli/search_interactive.go`
- [Download command](https://github.com/heartleo/zlib/blob/main/internal/cli/download.go): `internal/cli/download.go`
- [History browser](https://github.com/heartleo/zlib/blob/main/internal/cli/history.go): `internal/cli/history.go`
- [Profile command](https://github.com/heartleo/zlib/blob/main/internal/cli/profile.go): `internal/cli/profile.go`
- [Domain doctor](https://github.com/heartleo/zlib/blob/main/internal/cli/doctor.go): `internal/cli/doctor.go`
- [Kindle delivery](https://github.com/heartleo/zlib/blob/main/internal/cli/kindle.go): `internal/cli/kindle.go`
- [Themes](https://github.com/heartleo/zlib/blob/main/internal/cli/theme.go): `internal/cli/theme.go`

### Z-Library access

- [HTTP client](https://github.com/heartleo/zlib/blob/main/client.go): `client.go`
- [EAPI access](https://github.com/heartleo/zlib/blob/main/eapi.go): `eapi.go`
- [Domain probing](https://github.com/heartleo/zlib/blob/main/domain_probe.go): `domain_probe.go`
- [Challenge solver](https://github.com/heartleo/zlib/blob/main/challenge.go): `challenge.go`

### Book operations

- [Search engine](https://github.com/heartleo/zlib/blob/main/search.go): `search.go`
- [Page parser](https://github.com/heartleo/zlib/blob/main/parser.go): `parser.go`
- [Book details](https://github.com/heartleo/zlib/blob/main/book.go): `book.go`
- [File download](https://github.com/heartleo/zlib/blob/main/download.go): `download.go`
- [Usage profile](https://github.com/heartleo/zlib/blob/main/profile.go): `profile.go`
- [Kindle sender](https://github.com/heartleo/zlib/blob/main/kindle.go): `kindle.go`

### Local settings

- [Session settings](https://github.com/heartleo/zlib/blob/main/internal/config/session.go): `internal/config/session.go`

### Other components

- **User**
- **Z-Library service**
- **SMTP service**

## Connections

- User → CLI entry: runs commands (evidence: `README.md`)
- CLI entry → Login: routes login
- User → Search: searches books (evidence: `README.md`)
- Search → Search engine: queries (evidence: `internal/cli/search.go`)
- Search → Search picker: opens picker (evidence: `internal/cli/search.go`)
- Search picker → File download: starts download (evidence: `README.md`)
- User → Download command: requests download (evidence: `README.md`)
- Download command → File download: downloads book (evidence: `README.md`)
- User → History browser: browses history (evidence: `README.md`)
- User → Profile command: checks quota (evidence: `README.md`)
- User → Domain doctor: checks domains (evidence: `README.md`)
- User → Kindle delivery: sends book (evidence: `README.md`)
- Kindle delivery → Kindle sender: sends file (evidence: `internal/cli/kindle.go`)
- Kindle sender → SMTP service: emails file (evidence: `README.md`)
- User → Themes: sets theme (evidence: `README.md`)
- Login → Session settings: saves session (evidence: `internal/cli/login.go`)
- Login → HTTP client: authenticates (evidence: `internal/cli/login.go`)
- HTTP client → Z-Library service: sends requests
- HTTP client → Challenge solver: solves challenge (evidence: `client.go`)
- Search engine → Page parser: parses results
- Book details → Z-Library service: loads details
- EAPI access → Z-Library service: calls API
- Domain probing → Z-Library service: probes domains
- Profile command → Usage profile: loads profile
- History browser → Z-Library service: loads history
