# greencoda/tasq architecture

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

- Interactive diagram: https://gitdiagram.com/greencoda/tasq
- Repository: https://github.com/greencoda/tasq

## Overview

Tasq is a Go task queue backed by SQL, with PostgreSQL and MySQL implementations. An application submits tasks through a producer; a configured consumer polls for eligible work, dispatches learned handlers, and records outcomes. The client exposes separate inspection and cleanup capabilities, while repository implementations persist queue state. The examples document setup and the broader usage flow; the consumer and repository excerpts show polling, task-state updates, and database access. Other component internals were not sampled, so their links are limited to documented example usage.

Main entry points: [`repository.go`](https://github.com/greencoda/tasq/blob/master/repository.go) (Repository Interface), [`repository/mysql/mysql.go`](https://github.com/greencoda/tasq/blob/master/repository/mysql/mysql.go) (MySQL Repository), [`repository/postgres/postgres.go`](https://github.com/greencoda/tasq/blob/master/repository/postgres/postgres.go) (PostgreSQL Repository), [`consumer.go`](https://github.com/greencoda/tasq/blob/master/consumer.go) (Task Consumer)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_api["Queue API"]
  node_client["Tasq Client<br/>[client.go]"]
  node_producer["Task Producer<br/>[producer.go]"]
  node_task["Task Model<br/>[task.go]"]
end

subgraph group_execution["Task Execution"]
  node_consumer["Task Consumer<br/>[consumer.go]"]
  node_handler(("Task Handler"))
end

subgraph group_storage["SQL Persistence"]
  node_repository_api["Repository Interface<br/>[repository.go]"]
  node_mysql_repo["MySQL Repository<br/>[mysql.go]"]
  node_mysql_mapping["MySQL Task Mapping<br/>[mysqlTask.go]"]
  node_mysql_db[("MySQL Database")]
  node_postgres_repo["PostgreSQL Repository<br/>[postgres.go]"]
  node_postgres_mapping["PostgreSQL Task Mapping<br/>[postgresTask.go]"]
  node_postgres_db[("PostgreSQL Database")]
end

subgraph group_operations["Queue Operations"]
  node_inspector["Queue Inspector<br/>[inspector.go]"]
  node_cleaner["Task Cleaner<br/>[cleaner.go]"]
end

node_application(("Application"))

node_application -->|"creates"| node_client
node_application -->|"submits through"| node_producer
node_application -->|"configures"| node_consumer
node_application -->|"inspects with"| node_inspector
node_application -->|"cleans with"| node_cleaner
node_client -->|"wraps"| node_repository_api
node_consumer -->|"polls and updates"| node_repository_api
node_consumer -->|"dispatches"| node_handler
node_producer -.->|"submits tasks"| node_repository_api
node_inspector -.->|"queries tasks"| node_repository_api
node_cleaner -.->|"cleans tasks"| node_repository_api
node_mysql_repo -.->|"implements"| node_repository_api
node_postgres_repo -.->|"implements"| node_repository_api
node_mysql_repo -->|"converts records"| node_mysql_mapping
node_postgres_repo -->|"converts records"| node_postgres_mapping
node_mysql_repo -->|"reads and writes"| node_mysql_db
node_postgres_repo -->|"reads and writes"| node_postgres_db

click node_client "https://github.com/greencoda/tasq/blob/master/client.go"
click node_producer "https://github.com/greencoda/tasq/blob/master/producer.go"
click node_task "https://github.com/greencoda/tasq/blob/master/task.go"
click node_consumer "https://github.com/greencoda/tasq/blob/master/consumer.go"
click node_inspector "https://github.com/greencoda/tasq/blob/master/inspector.go"
click node_cleaner "https://github.com/greencoda/tasq/blob/master/cleaner.go"
click node_repository_api "https://github.com/greencoda/tasq/blob/master/repository.go"
click node_mysql_repo "https://github.com/greencoda/tasq/blob/master/repository/mysql/mysql.go"
click node_mysql_mapping "https://github.com/greencoda/tasq/blob/master/repository/mysql/mysqlTask.go"
click node_postgres_repo "https://github.com/greencoda/tasq/blob/master/repository/postgres/postgres.go"
click node_postgres_mapping "https://github.com/greencoda/tasq/blob/master/repository/postgres/postgresTask.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_client,node_producer,node_task toneBlue
class node_consumer,node_handler toneAmber
class node_repository_api,node_mysql_repo,node_mysql_mapping,node_mysql_db,node_postgres_repo,node_postgres_mapping,node_postgres_db toneMint
class node_inspector,node_cleaner toneRose
class node_application toneIndigo
```

## Components

### Queue API

- [Tasq Client](https://github.com/greencoda/tasq/blob/master/client.go): `client.go`
- [Task Producer](https://github.com/greencoda/tasq/blob/master/producer.go): `producer.go`
- [Task Model](https://github.com/greencoda/tasq/blob/master/task.go): `task.go`

### Task Execution

- [Task Consumer](https://github.com/greencoda/tasq/blob/master/consumer.go): `consumer.go`
- **Task Handler**

### SQL Persistence

- [Repository Interface](https://github.com/greencoda/tasq/blob/master/repository.go): `repository.go`
- [MySQL Repository](https://github.com/greencoda/tasq/blob/master/repository/mysql/mysql.go): `repository/mysql/mysql.go`
- [MySQL Task Mapping](https://github.com/greencoda/tasq/blob/master/repository/mysql/mysqlTask.go): `repository/mysql/mysqlTask.go`
- **MySQL Database**
- [PostgreSQL Repository](https://github.com/greencoda/tasq/blob/master/repository/postgres/postgres.go): `repository/postgres/postgres.go`
- [PostgreSQL Task Mapping](https://github.com/greencoda/tasq/blob/master/repository/postgres/postgresTask.go): `repository/postgres/postgresTask.go`
- **PostgreSQL Database**

### Queue Operations

- [Queue Inspector](https://github.com/greencoda/tasq/blob/master/inspector.go): `inspector.go`
- [Task Cleaner](https://github.com/greencoda/tasq/blob/master/cleaner.go): `cleaner.go`

### Other components

- **Application**

## Connections

- Application → Tasq Client: creates
- Application → Task Producer: submits through
- Application → Task Consumer: configures
- Application → Queue Inspector: inspects with
- Application → Task Cleaner: cleans with
- Tasq Client → Repository Interface: wraps (evidence: `client.go`)
- Task Consumer → Repository Interface: polls and updates (evidence: `consumer.go`)
- Task Consumer → Task Handler: dispatches (evidence: `consumer.go`)
- Task Producer → Repository Interface: submits tasks
- Queue Inspector → Repository Interface: queries tasks
- Task Cleaner → Repository Interface: cleans tasks
- MySQL Repository → Repository Interface: implements
- PostgreSQL Repository → Repository Interface: implements
- MySQL Repository → MySQL Task Mapping: converts records (evidence: `repository/mysql/mysqlTask.go`)
- PostgreSQL Repository → PostgreSQL Task Mapping: converts records (evidence: `repository/postgres/postgresTask.go`)
- MySQL Repository → MySQL Database: reads and writes (evidence: `repository/mysql/mysql.go`)
- PostgreSQL Repository → PostgreSQL Database: reads and writes (evidence: `repository/postgres/postgres.go`)
