# adithya-s-k/marker-api architecture

> Architecture diagram of the GitHub repository adithya-s-k/marker-api, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2025-02-01). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/adithya-s-k/marker-api
- Repository: https://github.com/adithya-s-k/marker-api

## Overview

##### Main Components

a) Client Layer:
- Python Client Library (marker_api_client)
- REST API Interface
- Client Examples/Demos

b) API Layer:
- FastAPI Server (server.py for simple setup)
- Distributed Server (distributed_server.py)
- API Routes and Endpoints

c) Task Processing Layer:
- Celery Workers
- Redis Message Broker
- Task Queue Management

d) Core Processing:
- PDF Processing Engine (Marker)
- OCR Components
- Text Extraction
- Markdown Conversion

e) Monitoring & Management:
- Flower Dashboard
- Task Monitoring
- Worker Management

##### Component Relationships

- Client → API Server (HTTP/REST)
- API Server → Redis (Task Queue)
- Redis → Celery Workers (Task Distribution)
- Celery Workers → Core Processing Engine
- Celery Workers → Redis (Results)
- Flower → Redis (Monitoring)

##### Deployment Components

Containers for:
- Docker Containers (CPU/GPU variants)
- Kubernetes Pods (future implementation)
- Load Balancers
- Volume Mounts for Data

**Top Level (Client Interaction)**
- ↓
**Middle Level (API & Queue Management)**
- ↓
**Bottom Level (Processing & Storage)**

##### Important Flows to Highlight

a) Synchronous Flow:
**Client → API → Marker Engine → Response**

b) Asynchronous Flow:
**Client → API → Redis → Celery Workers → Marker Engine → Redis → Client**

##### Specific Implementation Details

Technical specifications:
- FastAPI running on port 8080
- Redis on port 6379
- Flower dashboard on port 5555
- GPU/CPU processing options
- Docker container relationships

##### Scaling Components

How the system scales:
- Multiple Celery workers
- Load distribution
- Resource allocation
- Worker pools

##### Additional Elements

Include:
- Configuration management
- Environment variables
- Volume mounts for data
- Security boundaries
- Network isolation

## Diagram (Mermaid)

```mermaid
graph TB
    subgraph Client
        PythonClient["Python Client Library"]:::client
        RestAPI["REST API Interface"]:::client
        Examples["Example/Demos"]:::client
    end

    subgraph API
        SimpleServer["Simple Server"]:::api
        DistServer["Distributed Server"]:::api
        APIRoutes["API Routes"]:::api
    end

    subgraph Queue
        Redis[(Redis Message Broker)]:::queue
        TaskQueue["Task Queue"]:::queue
    end

    subgraph Workers
        CeleryWorker["Celery Workers"]:::worker
        CeleryTasks["Celery Tasks"]:::worker
        CeleryRoutes["Celery Routes"]:::worker
    end

    subgraph Processing
        MarkerEngine["PDF Processing Engine"]:::processing
        OCR["OCR Components"]:::processing
        TextExtract["Text Extraction"]:::processing
        MDConvert["Markdown Conversion"]:::processing
    end

    subgraph Monitoring
        Flower["Flower Dashboard"]:::monitoring
    end

    subgraph Deployment
        DockerCPU["Docker CPU"]:::infra
        DockerGPU["Docker GPU"]:::infra
        K8s["Kubernetes"]:::infra
    end

    subgraph Config
        EnvConfig["Environment Config"]:::config
        DockerCompose["Docker Compose"]:::config
    end

    %% Relationships
    PythonClient --> SimpleServer & DistServer
    RestAPI --> SimpleServer & DistServer
    SimpleServer & DistServer --> Redis
    Redis --> CeleryWorker
    CeleryWorker --> MarkerEngine
    CeleryWorker --> Redis
    Flower --> Redis
    CeleryWorker --> OCR & TextExtract & MDConvert
    TaskQueue --> CeleryWorker
    CeleryTasks --> CeleryWorker
    CeleryRoutes --> CeleryWorker

    %% Click Events
    click PythonClient "https://github.com/adithya-s-k/marker-api/tree/master/client/marker_api_client/"
    click SimpleServer "https://github.com/adithya-s-k/marker-api/blob/master/server.py"
    click DistServer "https://github.com/adithya-s-k/marker-api/blob/master/distributed_server.py"
    click APIRoutes "https://github.com/adithya-s-k/marker-api/blob/master/marker_api/routes.py"
    click CeleryWorker "https://github.com/adithya-s-k/marker-api/blob/master/marker_api/celery_worker.py"
    click CeleryTasks "https://github.com/adithya-s-k/marker-api/blob/master/marker_api/celery_tasks.py"
    click CeleryRoutes "https://github.com/adithya-s-k/marker-api/blob/master/marker_api/celery_routes.py"
    click Examples "https://github.com/adithya-s-k/marker-api/tree/master/examples/"
    click DockerCPU "https://github.com/adithya-s-k/marker-api/blob/master/docker/Dockerfile.cpu.server"
    click DockerGPU "https://github.com/adithya-s-k/marker-api/blob/master/docker/Dockerfile.gpu.server"
    click K8s "https://github.com/adithya-s-k/marker-api/tree/master/k8s/"
    click EnvConfig "https://github.com/adithya-s-k/marker-api/blob/master/.env.example"
    click DockerCompose "https://github.com/adithya-s-k/marker-api/blob/master/docker-compose.cpu.yml"

    %% Styles
    classDef client fill:#2374ab
    classDef api fill:#48a9a6
    classDef queue fill:#e4572e
    classDef worker fill:#f3a712
    classDef processing fill:#c17817
    classDef monitoring fill:#9c528b
    classDef infra fill:#5c5c5c
    classDef config fill:#8c8c8c

    %% Legend
    subgraph Legend
        Client_L["Client Components"]:::client
        API_L["API Components"]:::api
        Queue_L["Queue Components"]:::queue
        Worker_L["Worker Components"]:::worker
        Processing_L["Processing Components"]:::processing
        Monitoring_L["Monitoring Components"]:::monitoring
        Infrastructure_L["Infrastructure"]:::infra
        Config_L["Configuration"]:::config
    end
```
