# digitalmethodsinitiative/4cat architecture

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

- Interactive diagram: https://gitdiagram.com/digitalmethodsinitiative/4cat
- Repository: https://github.com/digitalmethodsinitiative/4cat

## Overview

4CAT is a web-based research toolkit for collecting social-platform data, importing datasets, and analyzing them with downloadable processors and visualizations. The documented user flow is to create or upload a dataset, then download it or run further analysis. The graph preserves those product stages and the job, configuration, and LLM layers visible in the sampled source. Some web-to-backend wiring and unsampled subsystem internals are not shown, so those connections are omitted rather than inferred.

Main entry points: [`backend/lib/worker.py`](https://github.com/digitalmethodsinitiative/4cat/blob/master/backend/lib/worker.py) (Worker execution), [`webtool`](https://github.com/digitalmethodsinitiative/4cat/tree/master/webtool) (Web application), [`datasources`](https://github.com/digitalmethodsinitiative/4cat/tree/master/datasources) (Platform sources), [`backend/lib/search.py`](https://github.com/digitalmethodsinitiative/4cat/blob/master/backend/lib/search.py) (Search framework)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_interface["User interface"]
  node_web["Web application"]
  node_views["Web views"]
end

subgraph group_collection["Collection and import"]
  node_sources["Platform sources"]
  node_search["Search framework<br/>[search.py]"]
  node_imports["Data imports"]
  node_mapping["Item mapping<br/>[item_mapping.py]"]
end

subgraph group_analysis["Dataset analysis"]
  node_processors["Analysis processors"]
  node_llm_processor["LLM prompting<br/>[llm_prompter.py]"]
  node_llm_adapter["LLM adapter<br/>[adapter.py]"]
  node_results["Dataset results<br/>[dataset.py]"]
end

subgraph group_runtime["Runtime services"]
  node_processor_runtime["Processor runtime<br/>[processor.py]"]
  node_manager["Job manager<br/>[manager.py]"]
  node_worker["Worker execution<br/>[worker.py]"]
  node_queue["Job queue<br/>[queue.py]"]
  node_llm_manager["LLM model manager<br/>[llm_manager.py]"]
end

subgraph group_state["State and models"]
  node_dataset[("Dataset management<br/>[dataset.py]")]
  node_database[("Database access<br/>[database.py]")]
  node_config["Configuration<br/>[config_manager.py]"]
  node_llm_client["LLM server client<br/>[llm_client.py]"]
end

node_researcher(("Researcher"))
node_llm_servers(("LLM servers"))

node_researcher -->|"uses"| node_web
node_web -.->|"presents"| node_views
node_researcher -->|"selects source"| node_sources
node_researcher -->|"uploads data"| node_imports
node_sources -->|"implements searches"| node_search
node_search -->|"maps items"| node_mapping
node_researcher -->|"creates dataset"| node_dataset
node_dataset -->|"analyzes dataset"| node_processors
node_processors -->|"uses runtime"| node_processor_runtime
node_manager -->|"starts workers"| node_worker
node_worker -->|"uses queue"| node_queue
node_worker -->|"opens connection"| node_database
node_config -->|"reads settings"| node_database
node_llm_processor -->|"uses adapter"| node_llm_adapter
node_llm_manager -->|"manages models"| node_llm_client
node_llm_client -->|"sends requests"| node_llm_servers
node_researcher -->|"downloads or analyzes"| node_results

click node_web "https://github.com/digitalmethodsinitiative/4cat/tree/master/webtool"
click node_views "https://github.com/digitalmethodsinitiative/4cat/tree/master/webtool/views"
click node_sources "https://github.com/digitalmethodsinitiative/4cat/tree/master/datasources"
click node_search "https://github.com/digitalmethodsinitiative/4cat/blob/master/backend/lib/search.py"
click node_imports "https://github.com/digitalmethodsinitiative/4cat/tree/master/datasources/upload"
click node_mapping "https://github.com/digitalmethodsinitiative/4cat/blob/master/common/lib/item_mapping.py"
click node_dataset "https://github.com/digitalmethodsinitiative/4cat/blob/master/common/lib/dataset.py"
click node_processors "https://github.com/digitalmethodsinitiative/4cat/tree/master/processors"
click node_processor_runtime "https://github.com/digitalmethodsinitiative/4cat/blob/master/backend/lib/processor.py"
click node_manager "https://github.com/digitalmethodsinitiative/4cat/blob/master/backend/lib/manager.py"
click node_worker "https://github.com/digitalmethodsinitiative/4cat/blob/master/backend/lib/worker.py"
click node_queue "https://github.com/digitalmethodsinitiative/4cat/blob/master/common/lib/queue.py"
click node_database "https://github.com/digitalmethodsinitiative/4cat/blob/master/common/lib/database.py"
click node_config "https://github.com/digitalmethodsinitiative/4cat/blob/master/common/config_manager.py"
click node_llm_processor "https://github.com/digitalmethodsinitiative/4cat/blob/master/processors/machine_learning/llm_prompter.py"
click node_llm_adapter "https://github.com/digitalmethodsinitiative/4cat/blob/master/common/lib/llm/adapter.py"
click node_llm_client "https://github.com/digitalmethodsinitiative/4cat/blob/master/common/lib/llm/llm_client.py"
click node_llm_manager "https://github.com/digitalmethodsinitiative/4cat/blob/master/backend/workers/llm_manager.py"
click node_results "https://github.com/digitalmethodsinitiative/4cat/blob/master/common/lib/dataset.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_web,node_views toneBlue
class node_sources,node_search,node_imports,node_mapping toneAmber
class node_processors,node_llm_processor,node_llm_adapter,node_results,node_llm_servers toneMint
class node_processor_runtime,node_manager,node_worker,node_queue,node_llm_manager toneRose
class node_dataset,node_database,node_config,node_llm_client,node_researcher toneIndigo
```

## Components

### User interface

- [Web application](https://github.com/digitalmethodsinitiative/4cat/tree/master/webtool): `webtool`
- [Web views](https://github.com/digitalmethodsinitiative/4cat/tree/master/webtool/views): `webtool/views`

### Collection and import

- [Platform sources](https://github.com/digitalmethodsinitiative/4cat/tree/master/datasources): `datasources`
- [Search framework](https://github.com/digitalmethodsinitiative/4cat/blob/master/backend/lib/search.py): `backend/lib/search.py`
- [Data imports](https://github.com/digitalmethodsinitiative/4cat/tree/master/datasources/upload): `datasources/upload`
- [Item mapping](https://github.com/digitalmethodsinitiative/4cat/blob/master/common/lib/item_mapping.py): `common/lib/item_mapping.py`

### Dataset analysis

- [Analysis processors](https://github.com/digitalmethodsinitiative/4cat/tree/master/processors): `processors`
- [LLM prompting](https://github.com/digitalmethodsinitiative/4cat/blob/master/processors/machine_learning/llm_prompter.py): `processors/machine_learning/llm_prompter.py`
- [LLM adapter](https://github.com/digitalmethodsinitiative/4cat/blob/master/common/lib/llm/adapter.py): `common/lib/llm/adapter.py`
- [Dataset results](https://github.com/digitalmethodsinitiative/4cat/blob/master/common/lib/dataset.py): `common/lib/dataset.py`

### Runtime services

- [Processor runtime](https://github.com/digitalmethodsinitiative/4cat/blob/master/backend/lib/processor.py): `backend/lib/processor.py`
- [Job manager](https://github.com/digitalmethodsinitiative/4cat/blob/master/backend/lib/manager.py): `backend/lib/manager.py`
- [Worker execution](https://github.com/digitalmethodsinitiative/4cat/blob/master/backend/lib/worker.py): `backend/lib/worker.py`
- [Job queue](https://github.com/digitalmethodsinitiative/4cat/blob/master/common/lib/queue.py): `common/lib/queue.py`
- [LLM model manager](https://github.com/digitalmethodsinitiative/4cat/blob/master/backend/workers/llm_manager.py): `backend/workers/llm_manager.py`

### State and models

- [Dataset management](https://github.com/digitalmethodsinitiative/4cat/blob/master/common/lib/dataset.py): `common/lib/dataset.py`
- [Database access](https://github.com/digitalmethodsinitiative/4cat/blob/master/common/lib/database.py): `common/lib/database.py`
- [Configuration](https://github.com/digitalmethodsinitiative/4cat/blob/master/common/config_manager.py): `common/config_manager.py`
- [LLM server client](https://github.com/digitalmethodsinitiative/4cat/blob/master/common/lib/llm/llm_client.py): `common/lib/llm/llm_client.py`

### Other components

- **Researcher**
- **LLM servers**

## Connections

- Researcher → Web application: uses
- Web application → Web views: presents (evidence: `webtool/views/views_llm.py`)
- Researcher → Platform sources: selects source
- Researcher → Data imports: uploads data
- Platform sources → Search framework: implements searches (evidence: `datasources/bsky/search_bsky.py`)
- Search framework → Item mapping: maps items (evidence: `datasources/bsky/search_bsky.py`)
- Researcher → Dataset management: creates dataset
- Dataset management → Analysis processors: analyzes dataset
- Analysis processors → Processor runtime: uses runtime (evidence: `processors/text-analysis/generate_embeddings.py`)
- Job manager → Worker execution: starts workers (evidence: `backend/lib/manager.py`)
- Worker execution → Job queue: uses queue (evidence: `backend/lib/worker.py`)
- Worker execution → Database access: opens connection (evidence: `backend/lib/worker.py`)
- Configuration → Database access: reads settings (evidence: `common/config_manager.py`)
- LLM prompting → LLM adapter: uses adapter (evidence: `processors/machine_learning/llm_prompter.py`)
- LLM model manager → LLM server client: manages models (evidence: `backend/workers/llm_manager.py`)
- LLM server client → LLM servers: sends requests (evidence: `common/lib/llm/llm_client.py`)
- Researcher → Dataset results: downloads or analyzes
