> For the complete documentation index, see [llms.txt](https://taskflow-1.gitbook.io/taskflow-docs/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://taskflow-1.gitbook.io/taskflow-docs/architecture.md).

# Architecture

How the components in `system-overview.md` interact at runtime, and why the boundaries sit where they do.

## Request lifecycle (synchronous)

1. The browser (`web-app`) sends a REST call to `api-service` with a bearer token.
2. `api-service` validates the token, applies the business rules, and reads/writes PostgreSQL (the primary).
3. Side-effect work (notifications, webhooks, digests) is enqueued to Redis as part of the request, so email and webhook latency never sit on the request path.

## Asynchronous work

* `worker` consumes RQ queues on Redis. Job payloads carry IDs, never PII: the worker resolves what it needs (for example a digest recipient's email) from the database read-replica at run time.
* A failed job retries with exponential backoff and lands in a dead-letter list after 5 attempts (see `incident-runbook.md`).
* Report generation reads the read-replica, never the primary, so a heavy report cannot starve the request path.

## Realtime board presence

Presence (who is viewing a board, cursor positions) runs over Redis pub/sub channels scoped per project. It is ephemeral by design: nothing is persisted, and a Redis restart costs presence only, never data.

## Scaling posture

* `api-service` is stateless; scale it horizontally. All shared state lives in PostgreSQL and Redis.
* One PostgreSQL primary, one read-replica. Because `api-service` is the only writer (see `system-overview.md`), the write path stays auditable.
* The hot read path is the board list, which is why list endpoints use cursor pagination backed by a `(project_id, status, id)` index (see ADR-0002 and `taskflow-api-docs`, `data-model.md`).

## Failure domains

| Failure                 | Effect                                                   | First move                                                       |
| ----------------------- | -------------------------------------------------------- | ---------------------------------------------------------------- |
| PostgreSQL primary down | `/health` reports `db: down`; writes and most reads fail | `incident-runbook.md`, "API returning 5xx"                       |
| Redis down              | Queues and presence stop; API reads still serve          | Restart Redis; expect queued work to resume, presence to rebuild |
| `worker` down           | Queue depth grows; digests and webhooks delayed          | `incident-runbook.md`, "Worker queue backing up"                 |
| Read-replica lag        | Worker and reports read stale data                       | Alert at 30 s lag (see `observability.md`)                       |


---

# Agent Instructions
This documentation is published with GitBook. GitBook is the documentation platform designed so that both humans and AI agents can read, navigate, and reason over technical content effectively. Learn more at gitbook.com.

## Querying This Documentation
If you need additional information that is not directly available in this page, you can query the documentation by asking a question.

Perform an HTTP GET request on the following URL with the `ask` and `goal` query parameters:

```
GET https://taskflow-1.gitbook.io/taskflow-docs/architecture.md?ask=<question>&goal=<user_goal>
```

`ask` is the immediate question: it should be specific, self-contained, and written in natural language.
`goal` is what the user is ultimately trying to achieve, the reason they need the answer. Sharing it helps GitBook give you a better, more relevant answer. A goal is most helpful when it describes the outcome the user wants rather than restating the question. For example, with `ask=how do I create an API token`, a goal like `automate deployments from our CI pipeline` lets GitBook tailor the answer to that use case.

The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
