# masiama/libri-crawler architecture

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

- Interactive diagram: https://gitdiagram.com/masiama/libri-crawler
- Repository: https://github.com/masiama/libri-crawler

## Overview

Libri Crawler is a Redis-driven book-crawling daemon. A command naming a source is validated and locked, then the runner discovers and fetches pages, turns book pages into structured records, and publishes book, progress, and completion events; it also downloads available cover images into shared local storage. The source adapters are documented for four bookstores. The graph follows the sampled runner and adapters; unsampled source implementations are shown as source components, but their internal behavior is not inferred.

Main entry points: [`cmd/crawler/runner.go`](https://github.com/masiama/libri-crawler/blob/main/cmd/crawler/runner.go) (Crawl runner), [`internal/redis/client.go`](https://github.com/masiama/libri-crawler/blob/main/internal/redis/client.go) (Redis client), [`cmd/crawler/server.go`](https://github.com/masiama/libri-crawler/blob/main/cmd/crawler/server.go) (Crawl manager), [`internal/scraper/chitaigorod.go`](https://github.com/masiama/libri-crawler/blob/main/internal/scraper/chitaigorod.go) (Chitai-Gorod adapter)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_control["Crawl control"]
  node_main["Daemon entry<br/>[main.go]"]
  node_manager["Crawl manager<br/>[server.go]"]
  node_runner["Crawl runner<br/>[runner.go]"]
end

subgraph group_sources["Book sources"]
  node_azon["Azon adapter<br/>[azon.go]"]
  node_chitai["Chitai-Gorod adapter<br/>[chitaigorod.go]"]
  node_kniga["Kniga.lv adapter<br/>[knigalv.go]"]
  node_mnogoknig["Mnogoknig adapter<br/>[mnogoknig.go]"]
end

subgraph group_processing["Crawl processing"]
  node_scraper["Scraper runtime<br/>[scraper.go]"]
  node_fetcher["HTTP fetcher<br/>[fetcher.go]"]
  node_scraper_types["Scraped book types<br/>[types.go]"]
  node_downloader["Image downloader<br/>[downloader.go]"]
end

subgraph group_outputs["Events and images"]
  node_redis_client["Redis client<br/>[client.go]"]
  node_redis_service[("Redis service")]
  node_event_types["Crawl events<br/>[events.go]"]
  node_storage[("Cover storage<br/>[storage.go]")]
end

node_command_source(("Command producer"))
node_event_consumer(("Event consumer"))
node_book_sites(("Bookstore websites"))
node_shared_api(("Shared image consumer"))

node_command_source -->|"enqueues command"| node_redis_service
node_main -->|"listens for commands"| node_redis_client
node_main -->|"dispatches command"| node_manager
node_manager -->|"locks source"| node_redis_client
node_manager -->|"runs crawl"| node_runner
node_runner -->|"creates scraper"| node_scraper
node_runner -->|"selects source handler"| node_azon
node_runner -->|"selects source handler"| node_chitai
node_runner -->|"selects source handler"| node_kniga
node_runner -->|"selects source handler"| node_mnogoknig
node_book_sites -.->|"serves page requests"| node_fetcher
node_chitai -->|"probes image"| node_fetcher
node_runner -->|"checks and publishes"| node_redis_client
node_manager -->|"publishes errors"| node_redis_client
node_redis_client -->|"reads and writes"| node_redis_service
node_redis_client -->|"encodes events"| node_event_types
node_redis_service -->|"delivers crawl events"| node_event_consumer
node_runner -->|"queues book images"| node_downloader
node_downloader -->|"fetches image"| node_fetcher
node_downloader -->|"saves cover"| node_storage
node_storage -->|"shares image files"| node_shared_api
node_azon -->|"returns book records"| node_scraper_types
node_chitai -->|"returns book records"| node_scraper_types
node_mnogoknig -->|"returns book records"| node_scraper_types

click node_main "https://github.com/masiama/libri-crawler/blob/main/cmd/crawler/main.go"
click node_manager "https://github.com/masiama/libri-crawler/blob/main/cmd/crawler/server.go"
click node_runner "https://github.com/masiama/libri-crawler/blob/main/cmd/crawler/runner.go"
click node_redis_client "https://github.com/masiama/libri-crawler/blob/main/internal/redis/client.go"
click node_event_types "https://github.com/masiama/libri-crawler/blob/main/internal/redis/events.go"
click node_scraper "https://github.com/masiama/libri-crawler/blob/main/internal/scraper/scraper.go"
click node_fetcher "https://github.com/masiama/libri-crawler/blob/main/internal/fetcher/fetcher.go"
click node_azon "https://github.com/masiama/libri-crawler/blob/main/internal/scraper/azon.go"
click node_chitai "https://github.com/masiama/libri-crawler/blob/main/internal/scraper/chitaigorod.go"
click node_kniga "https://github.com/masiama/libri-crawler/blob/main/internal/scraper/knigalv.go"
click node_mnogoknig "https://github.com/masiama/libri-crawler/blob/main/internal/scraper/mnogoknig.go"
click node_scraper_types "https://github.com/masiama/libri-crawler/blob/main/internal/scraper/types.go"
click node_downloader "https://github.com/masiama/libri-crawler/blob/main/internal/downloader/downloader.go"
click node_storage "https://github.com/masiama/libri-crawler/blob/main/internal/downloader/storage.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_main,node_manager,node_runner toneBlue
class node_azon,node_chitai,node_kniga,node_mnogoknig toneAmber
class node_scraper,node_fetcher,node_scraper_types,node_downloader toneMint
class node_redis_client,node_redis_service,node_event_types,node_storage toneRose
class node_command_source,node_event_consumer,node_book_sites,node_shared_api toneIndigo
```

## Components

### Crawl control

- [Daemon entry](https://github.com/masiama/libri-crawler/blob/main/cmd/crawler/main.go): `cmd/crawler/main.go`
- [Crawl manager](https://github.com/masiama/libri-crawler/blob/main/cmd/crawler/server.go): `cmd/crawler/server.go`
- [Crawl runner](https://github.com/masiama/libri-crawler/blob/main/cmd/crawler/runner.go): `cmd/crawler/runner.go`

### Book sources

- [Azon adapter](https://github.com/masiama/libri-crawler/blob/main/internal/scraper/azon.go): `internal/scraper/azon.go`
- [Chitai-Gorod adapter](https://github.com/masiama/libri-crawler/blob/main/internal/scraper/chitaigorod.go): `internal/scraper/chitaigorod.go`
- [Kniga.lv adapter](https://github.com/masiama/libri-crawler/blob/main/internal/scraper/knigalv.go): `internal/scraper/knigalv.go`
- [Mnogoknig adapter](https://github.com/masiama/libri-crawler/blob/main/internal/scraper/mnogoknig.go): `internal/scraper/mnogoknig.go`

### Crawl processing

- [Scraper runtime](https://github.com/masiama/libri-crawler/blob/main/internal/scraper/scraper.go): `internal/scraper/scraper.go`
- [HTTP fetcher](https://github.com/masiama/libri-crawler/blob/main/internal/fetcher/fetcher.go): `internal/fetcher/fetcher.go`
- [Scraped book types](https://github.com/masiama/libri-crawler/blob/main/internal/scraper/types.go): `internal/scraper/types.go`
- [Image downloader](https://github.com/masiama/libri-crawler/blob/main/internal/downloader/downloader.go): `internal/downloader/downloader.go`

### Events and images

- [Redis client](https://github.com/masiama/libri-crawler/blob/main/internal/redis/client.go): `internal/redis/client.go`
- **Redis service**
- [Crawl events](https://github.com/masiama/libri-crawler/blob/main/internal/redis/events.go): `internal/redis/events.go`
- [Cover storage](https://github.com/masiama/libri-crawler/blob/main/internal/downloader/storage.go): `internal/downloader/storage.go`

### Other components

- **Command producer**
- **Event consumer**
- **Bookstore websites**
- **Shared image consumer**

## Connections

- Command producer → Redis service: enqueues command (evidence: `README.md`)
- Daemon entry → Redis client: listens for commands (evidence: `cmd/crawler/main.go`)
- Daemon entry → Crawl manager: dispatches command (evidence: `cmd/crawler/main.go`)
- Crawl manager → Redis client: locks source (evidence: `cmd/crawler/server.go`)
- Crawl manager → Crawl runner: runs crawl (evidence: `cmd/crawler/server.go`)
- Crawl runner → Scraper runtime: creates scraper (evidence: `cmd/crawler/runner.go`)
- Crawl runner → Azon adapter: selects source handler (evidence: `cmd/crawler/runner.go`)
- Crawl runner → Chitai-Gorod adapter: selects source handler (evidence: `cmd/crawler/runner.go`)
- Crawl runner → Kniga.lv adapter: selects source handler (evidence: `cmd/crawler/runner.go`)
- Crawl runner → Mnogoknig adapter: selects source handler (evidence: `cmd/crawler/runner.go`)
- Bookstore websites → HTTP fetcher: serves page requests
- Chitai-Gorod adapter → HTTP fetcher: probes image (evidence: `internal/scraper/chitaigorod.go`)
- Crawl runner → Redis client: checks and publishes (evidence: `cmd/crawler/runner.go`)
- Crawl manager → Redis client: publishes errors (evidence: `cmd/crawler/server.go`)
- Redis client → Redis service: reads and writes (evidence: `internal/redis/client.go`)
- Redis client → Crawl events: encodes events (evidence: `internal/redis/client.go`)
- Redis service → Event consumer: delivers crawl events (evidence: `README.md`)
- Crawl runner → Image downloader: queues book images (evidence: `cmd/crawler/runner.go`)
- Image downloader → HTTP fetcher: fetches image (evidence: `internal/downloader/downloader.go`)
- Image downloader → Cover storage: saves cover (evidence: `internal/downloader/downloader.go`)
- Cover storage → Shared image consumer: shares image files (evidence: `README.md`)
- Azon adapter → Scraped book types: returns book records (evidence: `internal/scraper/azon.go`)
- Chitai-Gorod adapter → Scraped book types: returns book records (evidence: `internal/scraper/chitaigorod.go`)
- Mnogoknig adapter → Scraped book types: returns book records (evidence: `internal/scraper/mnogoknig.go`)
