# andrewfoxfox/comp41720_lab2_harness architecture

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

- Interactive diagram: https://gitdiagram.com/andrewfoxfox/comp41720_lab2_harness
- Repository: https://github.com/andrewfoxfox/comp41720_lab2_harness

## Overview

This repository implements a distributed document-processing lab: a request reserves tenant quota, stores a pending document with an outbox event, and asynchronously processes embedding results to complete the document or compensate by releasing quota. The embedding worker is simulated and supports injected failures; SQLite state and RabbitMQ messages provide durable progress. The lab harness exercises the happy path, failures, recovery, and queue state. Its excerpt is partial, so some harness-to-service details are documented rather than fully inspectable.

Main entry points: [`embedding_service.py`](https://github.com/andrewfoxfox/comp41720_lab2_harness/blob/main/embedding_service.py) (Embedding worker), [`document_service.py`](https://github.com/andrewfoxfox/comp41720_lab2_harness/blob/main/document_service.py) (Document API), [`lab2_harness.py`](https://github.com/andrewfoxfox/comp41720_lab2_harness/blob/main/lab2_harness.py) (Lab harness), [`quota_service.py`](https://github.com/andrewfoxfox/comp41720_lab2_harness/blob/main/quota_service.py) (Quota API)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_doc["Document workflow"]
  node_document_api["Document API"]
  node_document_store[("Document state")]
  node_outbox_relay["Outbox relay"]
  node_result_consumer["Result handler"]
end

subgraph group_quota["Quota management"]
  node_quota_api["Quota API<br/>[quota_service.py]"]
  node_quota_store[("Reservation state<br/>[quota_service.py]")]
end

subgraph group_embed["Embedding worker"]
  node_embedding_worker["Embedding worker"]
  node_embedding_store[("Seen messages")]
end

subgraph group_messaging["Messaging infrastructure"]
  node_rabbit["RabbitMQ"]
  node_broker_helper["Broker helpers<br/>[common.py]"]
end

subgraph group_harness["Lab verification"]
  node_lab_harness["Lab harness<br/>[lab2_harness.py]"]
end

node_client(("Document client"))

node_client -->|"submits document"| node_document_api
node_document_api -->|"reserves quota"| node_quota_api
node_document_api -->|"writes document and outbox"| node_document_store
node_document_api -->|"reads status"| node_document_store
node_outbox_relay -->|"reads and marks published"| node_document_store
node_outbox_relay -->|"publishes tasks"| node_rabbit
node_embedding_worker -->|"consumes tasks"| node_rabbit
node_embedding_worker -->|"checks and records messages"| node_embedding_store
node_embedding_worker -->|"publishes results"| node_rabbit
node_result_consumer -->|"consumes results"| node_rabbit
node_result_consumer -->|"records outcome and deduplication"| node_document_store
node_result_consumer -->|"releases on failure"| node_quota_api
node_quota_api -->|"reads and writes reservations"| node_quota_store
node_outbox_relay -->|"connects and declares queues"| node_broker_helper
node_result_consumer -->|"connects and declares queues"| node_broker_helper
node_embedding_worker -->|"connects and declares queues"| node_broker_helper
node_broker_helper -->|"declares durable queues"| node_rabbit
node_lab_harness -->|"submits and checks status"| node_document_api
node_lab_harness -->|"checks routes and state"| node_quota_api
node_lab_harness -->|"checks service availability"| node_embedding_worker
node_lab_harness -->|"inspects queue depths"| node_rabbit

click node_document_api "https://github.com/andrewfoxfox/comp41720_lab2_harness/blob/main/document_service.py"
click node_document_store "https://github.com/andrewfoxfox/comp41720_lab2_harness/blob/main/document_service.py"
click node_outbox_relay "https://github.com/andrewfoxfox/comp41720_lab2_harness/blob/main/document_service.py"
click node_result_consumer "https://github.com/andrewfoxfox/comp41720_lab2_harness/blob/main/document_service.py"
click node_quota_api "https://github.com/andrewfoxfox/comp41720_lab2_harness/blob/main/quota_service.py"
click node_quota_store "https://github.com/andrewfoxfox/comp41720_lab2_harness/blob/main/quota_service.py"
click node_embedding_worker "https://github.com/andrewfoxfox/comp41720_lab2_harness/blob/main/embedding_service.py"
click node_embedding_store "https://github.com/andrewfoxfox/comp41720_lab2_harness/blob/main/embedding_service.py"
click node_broker_helper "https://github.com/andrewfoxfox/comp41720_lab2_harness/blob/main/common.py"
click node_lab_harness "https://github.com/andrewfoxfox/comp41720_lab2_harness/blob/main/lab2_harness.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_document_api,node_document_store,node_outbox_relay,node_result_consumer,node_client toneBlue
class node_quota_api,node_quota_store toneAmber
class node_embedding_worker,node_embedding_store toneMint
class node_rabbit,node_broker_helper toneRose
class node_lab_harness toneIndigo
```

## Components

### Document workflow

- [Document API](https://github.com/andrewfoxfox/comp41720_lab2_harness/blob/main/document_service.py): `document_service.py`
- [Document state](https://github.com/andrewfoxfox/comp41720_lab2_harness/blob/main/document_service.py): `document_service.py`
- [Outbox relay](https://github.com/andrewfoxfox/comp41720_lab2_harness/blob/main/document_service.py): `document_service.py`
- [Result handler](https://github.com/andrewfoxfox/comp41720_lab2_harness/blob/main/document_service.py): `document_service.py`

### Quota management

- [Quota API](https://github.com/andrewfoxfox/comp41720_lab2_harness/blob/main/quota_service.py): `quota_service.py`
- [Reservation state](https://github.com/andrewfoxfox/comp41720_lab2_harness/blob/main/quota_service.py): `quota_service.py`

### Embedding worker

- [Embedding worker](https://github.com/andrewfoxfox/comp41720_lab2_harness/blob/main/embedding_service.py): `embedding_service.py`
- [Seen messages](https://github.com/andrewfoxfox/comp41720_lab2_harness/blob/main/embedding_service.py): `embedding_service.py`

### Messaging infrastructure

- **RabbitMQ**
- [Broker helpers](https://github.com/andrewfoxfox/comp41720_lab2_harness/blob/main/common.py): `common.py`

### Lab verification

- [Lab harness](https://github.com/andrewfoxfox/comp41720_lab2_harness/blob/main/lab2_harness.py): `lab2_harness.py`

### Other components

- **Document client**

## Connections

- Document client → Document API: submits document (evidence: `document_service.py`)
- Document API → Quota API: reserves quota (evidence: `document_service.py`)
- Document API → Document state: writes document and outbox (evidence: `document_service.py`)
- Document API → Document state: reads status (evidence: `document_service.py`)
- Outbox relay → Document state: reads and marks published (evidence: `document_service.py`)
- Outbox relay → RabbitMQ: publishes tasks (evidence: `document_service.py`)
- Embedding worker → RabbitMQ: consumes tasks (evidence: `embedding_service.py`)
- Embedding worker → Seen messages: checks and records messages (evidence: `embedding_service.py`)
- Embedding worker → RabbitMQ: publishes results (evidence: `embedding_service.py`)
- Result handler → RabbitMQ: consumes results (evidence: `document_service.py`)
- Result handler → Document state: records outcome and deduplication (evidence: `document_service.py`)
- Result handler → Quota API: releases on failure (evidence: `document_service.py`)
- Quota API → Reservation state: reads and writes reservations (evidence: `quota_service.py`)
- Outbox relay → Broker helpers: connects and declares queues (evidence: `document_service.py`)
- Result handler → Broker helpers: connects and declares queues (evidence: `document_service.py`)
- Embedding worker → Broker helpers: connects and declares queues (evidence: `embedding_service.py`)
- Broker helpers → RabbitMQ: declares durable queues (evidence: `common.py`)
- Lab harness → Document API: submits and checks status (evidence: `lab2_harness.py`)
- Lab harness → Quota API: checks routes and state (evidence: `lab2_harness.py`)
- Lab harness → Embedding worker: checks service availability (evidence: `lab2_harness.py`)
- Lab harness → RabbitMQ: inspects queue depths (evidence: `lab2_harness.py`)
