# sarthak-shubham/mochi architecture

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

- Interactive diagram: https://gitdiagram.com/sarthak-shubham/mochi
- Repository: https://github.com/sarthak-shubham/mochi

## Overview

Mochi is a webhook event relay: operators register HTTP endpoints and subscribe them to event types; publishers submit events, which Mochi persists, queues for matching subscribers, delivers asynchronously, and tracks delivery outcomes for lookup. The graph separates HTTP handling, Redis-backed state and routing, and background delivery. Source excerpts show the principal calls and Redis stream flow; the empty README provides no additional documented capabilities, and unsampled files are not inferred.

Main entry points: [`internal/worker/worker.go`](https://github.com/sarthak-shubham/mochi/blob/main/internal/worker/worker.go) (Delivery workers), [`internal/api/handlers.go`](https://github.com/sarthak-shubham/mochi/blob/main/internal/api/handlers.go) (Event publish and lookup), [`internal/api/server.go`](https://github.com/sarthak-shubham/mochi/blob/main/internal/api/server.go) (HTTP server), [`cmd/mochi/main.go`](https://github.com/sarthak-shubham/mochi/blob/main/cmd/mochi/main.go) (Service startup)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_runtime["Runtime"]
  node_config["Configuration<br/>[config.go]"]
  node_process["Service startup<br/>[main.go]"]
end

subgraph group_http["HTTP API"]
  node_api_server["HTTP server<br/>[server.go]"]
  node_endpoint_api["Endpoint subscriptions<br/>[handlers.go]"]
  node_event_api["Event publish and lookup<br/>[handlers.go]"]
  node_response_helpers["HTTP helpers<br/>[helpers.go]"]
end

subgraph group_state["State and routing"]
  node_endpoint_state["Endpoint and subscriptions<br/>[endpoints.go]"]
  node_event_state["Events and deliveries<br/>[events.go]"]
  node_store_core["Store and keys<br/>[store.go]"]
end

subgraph group_delivery["Delivery"]
  node_queue["Delivery stream<br/>[events.go]"]
  node_worker["Delivery workers<br/>[worker.go]"]
end

node_operator(("Operator"))
node_publisher(("Event publisher"))
node_subscriber(("Subscriber endpoint"))
node_redis[("Redis")]
node_webhook(("Webhook receiver"))

node_operator -->|"manages endpoints"| node_api_server
node_publisher -->|"publishes events"| node_api_server
node_api_server -->|"routes endpoint requests"| node_endpoint_api
node_api_server -->|"routes event requests"| node_event_api
node_endpoint_api -->|"writes responses"| node_response_helpers
node_event_api -->|"writes responses"| node_response_helpers
node_endpoint_api -->|"manages subscriptions"| node_endpoint_state
node_event_api -->|"saves and reads events"| node_event_state
node_event_api -->|"finds subscribers"| node_endpoint_state
node_event_api -->|"schedules deliveries"| node_queue
node_process -->|"loads settings"| node_config
node_process -->|"creates store"| node_store_core
node_process -->|"starts workers"| node_worker
node_process -->|"starts server"| node_api_server
node_store_core -->|"uses client"| node_redis
node_endpoint_state -->|"reads and writes"| node_redis
node_event_state -->|"reads and writes"| node_redis
node_event_state -->|"enqueues messages"| node_queue
node_worker -->|"reads and acknowledges"| node_queue
node_worker -->|"loads and records delivery"| node_event_state
node_worker -->|"loads endpoint"| node_endpoint_state
node_worker -->|"posts event"| node_webhook
node_webhook -->|"returns HTTP result"| node_worker
node_subscriber -.->|"receives delivery"| node_webhook

click node_config "https://github.com/sarthak-shubham/mochi/blob/main/internal/config/config.go"
click node_process "https://github.com/sarthak-shubham/mochi/blob/main/cmd/mochi/main.go"
click node_api_server "https://github.com/sarthak-shubham/mochi/blob/main/internal/api/server.go"
click node_endpoint_api "https://github.com/sarthak-shubham/mochi/blob/main/internal/api/handlers.go"
click node_event_api "https://github.com/sarthak-shubham/mochi/blob/main/internal/api/handlers.go"
click node_response_helpers "https://github.com/sarthak-shubham/mochi/blob/main/internal/api/helpers.go"
click node_endpoint_state "https://github.com/sarthak-shubham/mochi/blob/main/internal/store/endpoints.go"
click node_event_state "https://github.com/sarthak-shubham/mochi/blob/main/internal/store/events.go"
click node_store_core "https://github.com/sarthak-shubham/mochi/blob/main/internal/store/store.go"
click node_queue "https://github.com/sarthak-shubham/mochi/blob/main/internal/store/events.go"
click node_worker "https://github.com/sarthak-shubham/mochi/blob/main/internal/worker/worker.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_config,node_process toneBlue
class node_api_server,node_endpoint_api,node_event_api,node_response_helpers,node_redis toneAmber
class node_endpoint_state,node_event_state,node_store_core,node_webhook toneMint
class node_queue,node_worker toneRose
class node_operator,node_publisher,node_subscriber toneIndigo
```

## Components

### Runtime

- [Configuration](https://github.com/sarthak-shubham/mochi/blob/main/internal/config/config.go): `internal/config/config.go`
- [Service startup](https://github.com/sarthak-shubham/mochi/blob/main/cmd/mochi/main.go): `cmd/mochi/main.go`

### HTTP API

- [HTTP server](https://github.com/sarthak-shubham/mochi/blob/main/internal/api/server.go): `internal/api/server.go`
- [Endpoint subscriptions](https://github.com/sarthak-shubham/mochi/blob/main/internal/api/handlers.go): `internal/api/handlers.go`
- [Event publish and lookup](https://github.com/sarthak-shubham/mochi/blob/main/internal/api/handlers.go): `internal/api/handlers.go`
- [HTTP helpers](https://github.com/sarthak-shubham/mochi/blob/main/internal/api/helpers.go): `internal/api/helpers.go`

### State and routing

- [Endpoint and subscriptions](https://github.com/sarthak-shubham/mochi/blob/main/internal/store/endpoints.go): `internal/store/endpoints.go`
- [Events and deliveries](https://github.com/sarthak-shubham/mochi/blob/main/internal/store/events.go): `internal/store/events.go`
- [Store and keys](https://github.com/sarthak-shubham/mochi/blob/main/internal/store/store.go): `internal/store/store.go`

### Delivery

- [Delivery stream](https://github.com/sarthak-shubham/mochi/blob/main/internal/store/events.go): `internal/store/events.go`
- [Delivery workers](https://github.com/sarthak-shubham/mochi/blob/main/internal/worker/worker.go): `internal/worker/worker.go`

### Other components

- **Operator**
- **Event publisher**
- **Subscriber endpoint**
- **Redis**
- **Webhook receiver**

## Connections

- Operator → HTTP server: manages endpoints (evidence: `internal/api/server.go`)
- Event publisher → HTTP server: publishes events (evidence: `internal/api/server.go`)
- HTTP server → Endpoint subscriptions: routes endpoint requests (evidence: `internal/api/server.go`)
- HTTP server → Event publish and lookup: routes event requests (evidence: `internal/api/server.go`)
- Endpoint subscriptions → HTTP helpers: writes responses (evidence: `internal/api/handlers.go`)
- Event publish and lookup → HTTP helpers: writes responses (evidence: `internal/api/handlers.go`)
- Endpoint subscriptions → Endpoint and subscriptions: manages subscriptions (evidence: `internal/api/handlers.go`)
- Event publish and lookup → Events and deliveries: saves and reads events (evidence: `internal/api/handlers.go`)
- Event publish and lookup → Endpoint and subscriptions: finds subscribers (evidence: `internal/api/handlers.go`)
- Event publish and lookup → Delivery stream: schedules deliveries (evidence: `internal/api/handlers.go`)
- Service startup → Configuration: loads settings (evidence: `cmd/mochi/main.go`)
- Service startup → Store and keys: creates store (evidence: `cmd/mochi/main.go`)
- Service startup → Delivery workers: starts workers (evidence: `cmd/mochi/main.go`)
- Service startup → HTTP server: starts server (evidence: `cmd/mochi/main.go`)
- Store and keys → Redis: uses client (evidence: `internal/store/store.go`)
- Endpoint and subscriptions → Redis: reads and writes (evidence: `internal/store/endpoints.go`)
- Events and deliveries → Redis: reads and writes (evidence: `internal/store/events.go`)
- Events and deliveries → Delivery stream: enqueues messages (evidence: `internal/store/events.go`)
- Delivery workers → Delivery stream: reads and acknowledges (evidence: `internal/worker/worker.go`)
- Delivery workers → Events and deliveries: loads and records delivery (evidence: `internal/worker/worker.go`)
- Delivery workers → Endpoint and subscriptions: loads endpoint (evidence: `internal/worker/worker.go`)
- Delivery workers → Webhook receiver: posts event (evidence: `internal/worker/worker.go`)
- Webhook receiver → Delivery workers: returns HTTP result (evidence: `internal/worker/worker.go`)
- Subscriber endpoint → Webhook receiver: receives delivery
