# hirotomasato/tempik architecture

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

- Interactive diagram: https://gitdiagram.com/hirotomasato/tempik
- Repository: https://github.com/hirotomasato/tempik

## Overview

Tempik is a Cloudflare Workers disposable-email service. A browser obtains a session, creates or claims an inbox, and fetches its messages through the HTTP API; inbound mail is separately parsed and stored for later display. The principal workflow and database interactions are visible in the excerpts. README documents static UI hosting and Cloudflare Email Worker/D1 deployment; schema details are documented but schema.sql was not sampled, so its edges are limited to those explicit statements.

Main entry points: [`src/web/app.js`](https://github.com/hirotomasato/tempik/blob/main/src/web/app.js) (Browser App Logic), [`src/api/routes.ts`](https://github.com/hirotomasato/tempik/blob/main/src/api/routes.ts) (API Routes), [`src/db/queries.ts`](https://github.com/hirotomasato/tempik/blob/main/src/db/queries.ts) (Database Queries), [`src/index.ts`](https://github.com/hirotomasato/tempik/blob/main/src/index.ts) (Worker Handlers)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_edge_runtime["Worker Runtime"]
  node_worker_entry["Worker Handlers<br/>[index.ts]"]
end

subgraph group_mail_ingestion["Mail Ingestion"]
  node_email_processor["Email Processor<br/>[email-handler.ts]"]
end

subgraph group_inbox_api["Inbox API"]
  node_http_router["HTTP Router<br/>[index.ts]"]
  node_api_routes["API Routes<br/>[routes.ts]"]
  node_address_generator["Address Generator<br/>[random-address.ts]"]
end

subgraph group_persistence["Persistence"]
  node_query_layer["Database Queries<br/>[queries.ts]"]
  node_d1_store[("D1 Database<br/>[schema.sql]")]
end

subgraph group_web_client["Web Client"]
  node_web_ui["Web Interface<br/>[index.html]"]
  node_web_logic["Browser App Logic<br/>[app.js]"]
  node_web_styles["UI Styles<br/>[styles.css]"]
end

node_browser(("Browser User"))
node_email_sender(("Email Sender"))
node_email_worker{{"Email Worker Service"}}
node_postal_mime["PostalMime Parser"]
node_cloudflare_assets{{"Workers Assets"}}

node_browser -.->|"opens"| node_web_ui
node_browser -->|"uses"| node_web_logic
node_web_ui -.->|"loads"| node_web_logic
node_web_logic -->|"requests API"| node_http_router
node_worker_entry -->|"routes API"| node_http_router
node_http_router -->|"dispatches"| node_api_routes
node_api_routes -->|"reads and writes"| node_query_layer
node_api_routes -->|"generates addresses"| node_address_generator
node_address_generator -->|"checks availability"| node_query_layer
node_query_layer -->|"queries"| node_d1_store
node_email_sender -.->|"sends mail"| node_email_worker
node_email_worker -.->|"invokes email handler"| node_worker_entry
node_worker_entry -->|"dispatches email"| node_email_processor
node_email_processor -->|"parses message"| node_postal_mime
node_email_processor -->|"stores message"| node_query_layer
node_cloudflare_assets -.->|"serves static UI"| node_web_ui
node_api_routes -.->|"returns API data"| node_web_logic
node_web_logic -.->|"uses styles"| node_web_styles

click node_worker_entry "https://github.com/hirotomasato/tempik/blob/main/src/index.ts"
click node_email_processor "https://github.com/hirotomasato/tempik/blob/main/src/email-handler.ts"
click node_http_router "https://github.com/hirotomasato/tempik/blob/main/src/index.ts"
click node_api_routes "https://github.com/hirotomasato/tempik/blob/main/src/api/routes.ts"
click node_address_generator "https://github.com/hirotomasato/tempik/blob/main/src/utils/random-address.ts"
click node_query_layer "https://github.com/hirotomasato/tempik/blob/main/src/db/queries.ts"
click node_d1_store "https://github.com/hirotomasato/tempik/blob/main/src/db/schema.sql"
click node_web_ui "https://github.com/hirotomasato/tempik/blob/main/src/web/index.html"
click node_web_logic "https://github.com/hirotomasato/tempik/blob/main/src/web/app.js"
click node_web_styles "https://github.com/hirotomasato/tempik/blob/main/src/web/styles.css"

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_worker_entry,node_browser toneBlue
class node_email_processor toneAmber
class node_http_router,node_api_routes,node_address_generator toneMint
class node_query_layer,node_d1_store,node_email_worker,node_cloudflare_assets toneRose
class node_web_ui,node_web_logic,node_web_styles,node_email_sender,node_postal_mime toneIndigo
```

## Components

### Worker Runtime

- [Worker Handlers](https://github.com/hirotomasato/tempik/blob/main/src/index.ts): `src/index.ts`

### Mail Ingestion

- [Email Processor](https://github.com/hirotomasato/tempik/blob/main/src/email-handler.ts): `src/email-handler.ts`

### Inbox API

- [HTTP Router](https://github.com/hirotomasato/tempik/blob/main/src/index.ts): `src/index.ts`
- [API Routes](https://github.com/hirotomasato/tempik/blob/main/src/api/routes.ts): `src/api/routes.ts`
- [Address Generator](https://github.com/hirotomasato/tempik/blob/main/src/utils/random-address.ts): `src/utils/random-address.ts`

### Persistence

- [Database Queries](https://github.com/hirotomasato/tempik/blob/main/src/db/queries.ts): `src/db/queries.ts`
- [D1 Database](https://github.com/hirotomasato/tempik/blob/main/src/db/schema.sql): `src/db/schema.sql`

### Web Client

- [Web Interface](https://github.com/hirotomasato/tempik/blob/main/src/web/index.html): `src/web/index.html`
- [Browser App Logic](https://github.com/hirotomasato/tempik/blob/main/src/web/app.js): `src/web/app.js`
- [UI Styles](https://github.com/hirotomasato/tempik/blob/main/src/web/styles.css): `src/web/styles.css`

### Other components

- **Browser User**
- **Email Sender**
- **Email Worker Service**
- **PostalMime Parser**
- **Workers Assets**

## Connections

- Browser User → Web Interface: opens (evidence: `README.md`)
- Browser User → Browser App Logic: uses (evidence: `src/web/app.js`)
- Web Interface → Browser App Logic: loads (evidence: `README.md`)
- Browser App Logic → HTTP Router: requests API (evidence: `src/web/app.js`)
- Worker Handlers → HTTP Router: routes API (evidence: `src/index.ts`)
- HTTP Router → API Routes: dispatches (evidence: `src/index.ts`)
- API Routes → Database Queries: reads and writes (evidence: `src/api/routes.ts`)
- API Routes → Address Generator: generates addresses (evidence: `src/api/routes.ts`)
- Address Generator → Database Queries: checks availability (evidence: `src/api/routes.ts`)
- Database Queries → D1 Database: queries (evidence: `src/db/queries.ts`)
- Email Sender → Email Worker Service: sends mail (evidence: `README.md`)
- Email Worker Service → Worker Handlers: invokes email handler (evidence: `README.md`)
- Worker Handlers → Email Processor: dispatches email (evidence: `src/index.ts`)
- Email Processor → PostalMime Parser: parses message (evidence: `src/email-handler.ts`)
- Email Processor → Database Queries: stores message (evidence: `src/email-handler.ts`)
- Workers Assets → Web Interface: serves static UI (evidence: `README.md`)
- API Routes → Browser App Logic: returns API data (evidence: `README.md`)
- Browser App Logic → UI Styles: uses styles (evidence: `README.md`)
