# riteshdhurwey/distributed-task-queue architecture

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

- Interactive diagram: https://gitdiagram.com/riteshdhurwey/distributed-task-queue
- Repository: https://github.com/riteshdhurwey/distributed-task-queue

## Overview

This repository implements a distributed task queue: clients submit tasks or request status/retries through a Gin API; tasks are persisted, queued by ID in Redis, claimed and processed by workers, then updated with their outcome. PostgreSQL also supports startup and expired-lease recovery. The graph includes documented service/recovery behavior even where those implementations were not sampled; those edges cite the README. The in-memory queue and repository are present in the tree but their runtime use is not established by the excerpts.

Main entry points: [`cmd/server/main.go`](https://github.com/riteshdhurwey/distributed-task-queue/blob/main/cmd/server/main.go) (Server Bootstrap), [`internal/repository/postgres_repository.go`](https://github.com/riteshdhurwey/distributed-task-queue/blob/main/internal/repository/postgres_repository.go) (Postgres Repository), [`internal/service/task_service.go`](https://github.com/riteshdhurwey/distributed-task-queue/blob/main/internal/service/task_service.go) (Task Service), [`internal/repository/redis_repository.go`](https://github.com/riteshdhurwey/distributed-task-queue/blob/main/internal/repository/redis_repository.go) (Redis Queue Adapter)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_api["HTTP API"]
  node_handler["Task Handler<br/>[task_handler.go]"]
end

subgraph group_application["Task Application"]
  node_service["Task Service<br/>[task_service.go]"]
  node_recovery["Task Recovery<br/>[recovery.go]"]
  node_task["Task Model<br/>[task.go]"]
end

subgraph group_persistence["Persistence"]
  node_taskrepo["Repository Contract<br/>[task_repository.go]"]
  node_postgresrepo["Postgres Repository"]
  node_memoryrepo["Memory Repository"]
  node_postgres[("PostgreSQL")]
end

subgraph group_execution["Queue and Workers"]
  node_redisrepo["Redis Queue Adapter"]
  node_queuerepo["Queue Contract<br/>[QueueRepository.go]"]
  node_redis[("Redis ZSET")]
  node_worker["Worker<br/>[worker.go]"]
  node_processor["Task Processor<br/>[worker.go]"]
  node_localqueue["In-memory Queue<br/>[queue.go]"]
end

subgraph group_startup["Runtime Setup"]
  node_server["Server Bootstrap<br/>[main.go]"]
  node_dbconnect["Database Connector<br/>[postgres.go]"]
  node_redisconfig["Redis Connector<br/>[redis.go]"]
end

node_client(("API Client"))

node_client -->|"sends requests"| node_handler
node_server -->|"registers routes"| node_handler
node_handler -->|"delegates tasks"| node_service
node_service -.->|"uses repository"| node_taskrepo
node_service -->|"enqueues IDs"| node_redisrepo
node_service -->|"persists tasks"| node_postgresrepo
node_service -.->|"handles task data"| node_task
node_server -->|"runs recovery"| node_recovery
node_recovery -->|"loads pending tasks"| node_postgresrepo
node_recovery -->|"re-enqueues IDs"| node_redisrepo
node_server -->|"connects database"| node_dbconnect
node_server -->|"connects Redis"| node_redisconfig
node_dbconnect -->|"opens connection"| node_postgres
node_redisconfig -->|"opens connection"| node_redis
node_server -->|"constructs repository"| node_postgresrepo
node_server -->|"constructs adapter"| node_redisrepo
node_postgresrepo -->|"reads and writes"| node_postgres
node_redisrepo -->|"adds and pops IDs"| node_redis
node_worker -->|"dequeues IDs"| node_redisrepo
node_worker -->|"claims and updates"| node_postgresrepo
node_worker -->|"processes task"| node_processor
node_worker -->|"loads task data"| node_task
node_postgresrepo -->|"maps records"| node_task
node_memoryrepo -.->|"implements contract"| node_taskrepo
node_localqueue -->|"queues task values"| node_task

click node_server "https://github.com/riteshdhurwey/distributed-task-queue/blob/main/cmd/server/main.go"
click node_handler "https://github.com/riteshdhurwey/distributed-task-queue/blob/main/internal/handler/task_handler.go"
click node_service "https://github.com/riteshdhurwey/distributed-task-queue/blob/main/internal/service/task_service.go"
click node_recovery "https://github.com/riteshdhurwey/distributed-task-queue/blob/main/internal/service/recovery.go"
click node_task "https://github.com/riteshdhurwey/distributed-task-queue/blob/main/internal/model/task.go"
click node_taskrepo "https://github.com/riteshdhurwey/distributed-task-queue/blob/main/internal/repository/task_repository.go"
click node_postgresrepo "https://github.com/riteshdhurwey/distributed-task-queue/blob/main/internal/repository/postgres_repository.go"
click node_memoryrepo "https://github.com/riteshdhurwey/distributed-task-queue/blob/main/internal/repository/memory_repository.go"
click node_redisrepo "https://github.com/riteshdhurwey/distributed-task-queue/blob/main/internal/repository/redis_repository.go"
click node_queuerepo "https://github.com/riteshdhurwey/distributed-task-queue/blob/main/internal/repository/QueueRepository.go"
click node_worker "https://github.com/riteshdhurwey/distributed-task-queue/blob/main/internal/worker/worker.go"
click node_processor "https://github.com/riteshdhurwey/distributed-task-queue/blob/main/internal/worker/worker.go"
click node_localqueue "https://github.com/riteshdhurwey/distributed-task-queue/blob/main/internal/queue/queue.go"
click node_dbconnect "https://github.com/riteshdhurwey/distributed-task-queue/blob/main/internal/database/postgres.go"
click node_redisconfig "https://github.com/riteshdhurwey/distributed-task-queue/blob/main/config/redis.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_handler,node_client toneBlue
class node_service,node_recovery,node_task toneAmber
class node_taskrepo,node_postgresrepo,node_memoryrepo,node_postgres toneMint
class node_redisrepo,node_queuerepo,node_redis,node_worker,node_processor,node_localqueue toneRose
class node_server,node_dbconnect,node_redisconfig toneIndigo
```

## Components

### HTTP API

- [Task Handler](https://github.com/riteshdhurwey/distributed-task-queue/blob/main/internal/handler/task_handler.go): `internal/handler/task_handler.go`

### Task Application

- [Task Service](https://github.com/riteshdhurwey/distributed-task-queue/blob/main/internal/service/task_service.go): `internal/service/task_service.go`
- [Task Recovery](https://github.com/riteshdhurwey/distributed-task-queue/blob/main/internal/service/recovery.go): `internal/service/recovery.go`
- [Task Model](https://github.com/riteshdhurwey/distributed-task-queue/blob/main/internal/model/task.go): `internal/model/task.go`

### Persistence

- [Repository Contract](https://github.com/riteshdhurwey/distributed-task-queue/blob/main/internal/repository/task_repository.go): `internal/repository/task_repository.go`
- [Postgres Repository](https://github.com/riteshdhurwey/distributed-task-queue/blob/main/internal/repository/postgres_repository.go): `internal/repository/postgres_repository.go`
- [Memory Repository](https://github.com/riteshdhurwey/distributed-task-queue/blob/main/internal/repository/memory_repository.go): `internal/repository/memory_repository.go`
- **PostgreSQL**

### Queue and Workers

- [Redis Queue Adapter](https://github.com/riteshdhurwey/distributed-task-queue/blob/main/internal/repository/redis_repository.go): `internal/repository/redis_repository.go`
- [Queue Contract](https://github.com/riteshdhurwey/distributed-task-queue/blob/main/internal/repository/QueueRepository.go): `internal/repository/QueueRepository.go`
- **Redis ZSET**
- [Worker](https://github.com/riteshdhurwey/distributed-task-queue/blob/main/internal/worker/worker.go): `internal/worker/worker.go`
- [Task Processor](https://github.com/riteshdhurwey/distributed-task-queue/blob/main/internal/worker/worker.go): `internal/worker/worker.go`
- [In-memory Queue](https://github.com/riteshdhurwey/distributed-task-queue/blob/main/internal/queue/queue.go): `internal/queue/queue.go`

### Runtime Setup

- [Server Bootstrap](https://github.com/riteshdhurwey/distributed-task-queue/blob/main/cmd/server/main.go): `cmd/server/main.go`
- [Database Connector](https://github.com/riteshdhurwey/distributed-task-queue/blob/main/internal/database/postgres.go): `internal/database/postgres.go`
- [Redis Connector](https://github.com/riteshdhurwey/distributed-task-queue/blob/main/config/redis.go): `config/redis.go`

### Other components

- **API Client**

## Connections

- API Client → Task Handler: sends requests (evidence: `README.md`)
- Server Bootstrap → Task Handler: registers routes (evidence: `cmd/server/main.go`)
- Task Handler → Task Service: delegates tasks (evidence: `internal/handler/task_handler.go`)
- Task Service → Repository Contract: uses repository
- Task Service → Redis Queue Adapter: enqueues IDs (evidence: `README.md`)
- Task Service → Postgres Repository: persists tasks (evidence: `README.md`)
- Task Service → Task Model: handles task data
- Server Bootstrap → Task Recovery: runs recovery (evidence: `cmd/server/main.go`)
- Task Recovery → Postgres Repository: loads pending tasks (evidence: `README.md`)
- Task Recovery → Redis Queue Adapter: re-enqueues IDs (evidence: `README.md`)
- Server Bootstrap → Database Connector: connects database (evidence: `cmd/server/main.go`)
- Server Bootstrap → Redis Connector: connects Redis (evidence: `cmd/server/main.go`)
- Database Connector → PostgreSQL: opens connection (evidence: `internal/database/postgres.go`)
- Redis Connector → Redis ZSET: opens connection (evidence: `config/redis.go`)
- Server Bootstrap → Postgres Repository: constructs repository (evidence: `cmd/server/main.go`)
- Server Bootstrap → Redis Queue Adapter: constructs adapter (evidence: `cmd/server/main.go`)
- Postgres Repository → PostgreSQL: reads and writes (evidence: `README.md`)
- Redis Queue Adapter → Redis ZSET: adds and pops IDs (evidence: `internal/repository/redis_repository.go`)
- Worker → Redis Queue Adapter: dequeues IDs (evidence: `internal/worker/worker.go`)
- Worker → Postgres Repository: claims and updates (evidence: `internal/worker/worker.go`)
- Worker → Task Processor: processes task (evidence: `internal/worker/worker.go`)
- Worker → Task Model: loads task data
- Postgres Repository → Task Model: maps records (evidence: `internal/repository/postgres_repository.go`)
- Memory Repository → Repository Contract: implements contract
- In-memory Queue → Task Model: queues task values (evidence: `internal/queue/queue.go`)
