# jasonpraful/hono-workflows-do architecture

> Architecture diagram of the GitHub repository jasonpraful/hono-workflows-do, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2025-04-21). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/jasonpraful/hono-workflows-do
- Repository: https://github.com/jasonpraful/hono-workflows-do

## Overview

##### Project type and purpose
- This is a serverless microservices project built on Cloudflare Workers.
- It consists of two worker scripts:
– A “core” Hono‑based HTTP API + Web UI (JSX) that exposes OpenAPI/Swagger, triggers workflows, and displays their status.
– A “workflows” worker that executes asynchronous processes (timer, AI image generation) and pushes results to R2.
- Durable Objects store workflow state; R2 stores generated images; external AI API generates images.

##### File structure
- Top‑level:
– README.md, bun.lock, package.json, tsconfig.json, .prettierrc
- functions/core:
– src/routes: HTTP handlers for /ai, /image, /state, /timer
– src/ui: Hono‑JSX components (CreatePost, Post, Layout) for the browser UI
– src/middleware: Durable Objects binding, cross‑script calls
– workflows.ts: cross‑script client to call the workflows worker
– wrangler.jsonc + package.json: binding definitions, dev scripts
- functions/workflows:
– src/index.ts: entry point; routes to ai.ts (calls external AI, writes R2), timer.ts (timer logic)
– wrangler.jsonc + package.json: separate worker config

##### README for additional insights
- The core service exposes OpenAPI + Swagger UI.
- Workflows include Timer and AI flows, triggered via HTTP from core.
- Cross‑script calls and Durable Object usage are key gaps in Cloudflare docs this demo fills.

##### Elements
– API/workers in another (e.g., green)
– Storage/state in another (e.g., orange)
– External services in gray

## Diagram (Mermaid)

```mermaid
flowchart TD
    %% Browser UI
    Browser["User Browser"]:::frontend
    Browser -->|"GET /, POST actions"| CoreUI

    subgraph "Core Worker" 
        direction TB
        CoreUI["Hono JSX UI (CreatePost, Post, Layout)"]:::frontend
        CoreAPI["Hono HTTP API (OpenAPI)"]:::backend
        Middleware["Durable Objects & Middleware"]:::backend
        CrossClient["Cross-script Client"]:::backend
        CoreUI -->|renders UI| CoreAPI
        CoreAPI -->|uses| Middleware
        CoreAPI -->|calls| CrossClient
    end

    subgraph "Workflows Worker"
        direction TB
        WFIndex["Entry Point index.ts"]:::backend
        TimerWF["Timer Workflow (timer.ts)"]:::backend
        AIWF["AI Workflow (ai.ts)"]:::backend
        WFIndex -->|routes to| TimerWF
        WFIndex -->|routes to| AIWF
        TimerWF -->|update state after delay| DO
        AIWF -->|call AI API| ExternalAI
        AIWF -->|store image| R2
        AIWF -->|update state| DO
    end

    CoreAPI -->|"Start Workflow"| WFIndex
    CoreAPI -->|"GET /state"| DO
    CoreAPI -->|"POST /timer"| WFIndex
    CoreAPI -->|"POST /ai"| WFIndex
    CoreAPI -->|"GET /image"| R2
    CoreAPI -->|"GET /state"| DO

    DO["Durable Object Namespace"]:::storage
    R2["Cloudflare R2 (Image Store)"]:::storage
    ExternalAI["External AI Service"]:::external

    Browser -->|poll /state|getState[/"GET /state"/]:::backend
    getState --> DO

    classDef frontend fill:#cce5ff,stroke:#66b0ff,color:#004085;
    classDef backend fill:#d4edda,stroke:#8fd19e,color:#155724;
    classDef storage fill:#fff3cd,stroke:#ffe69a,color:#856404;
    classDef external fill:#e2e3e5,stroke:#d6d8db,color:#383d41;

    %% Click Events for Core Worker
    click Browser "https://github.com/jasonpraful/hono-workflows-do/blob/main/functions/core/src/ui/Layout.tsx"
    click CoreUI "https://github.com/jasonpraful/hono-workflows-do/blob/main/functions/core/src/ui/CreatePost.tsx"
    click CoreUI "https://github.com/jasonpraful/hono-workflows-do/blob/main/functions/core/src/ui/Post.tsx"
    click Middleware "https://github.com/jasonpraful/hono-workflows-do/blob/main/functions/core/src/middleware/durable-objects.ts"
    click CrossClient "https://github.com/jasonpraful/hono-workflows-do/blob/main/functions/core/src/do/workflows.ts"
    click CoreAPI "https://github.com/jasonpraful/hono-workflows-do/blob/main/functions/core/src/index.tsx"
    click AIGet "https://github.com/jasonpraful/hono-workflows-do/blob/main//functions/core/src/routes/ai/get.ts" "functions/core/src/routes/ai/get.ts"
    click AIPost "https://github.com/jasonpraful/hono-workflows-do/blob/main//functions/core/src/routes/ai/post.ts" "functions/core/src/routes/ai/post.ts"
    click ImageGet "https://github.com/jasonpraful/hono-workflows-do/blob/main//functions/core/src/routes/image/get.ts" "functions/core/src/routes/image/get.ts"
    click StateGet "https://github.com/jasonpraful/hono-workflows-do/blob/main//functions/core/src/routes/state/get.ts" "functions/core/src/routes/state/get.ts"
    click StateReset "https://github.com/jasonpraful/hono-workflows-do/blob/main//functions/core/src/routes/state/reset.ts" "functions/core/src/routes/state/reset.ts"
    click TimerGet "https://github.com/jasonpraful/hono-workflows-do/blob/main//functions/core/src/routes/timer/get.ts" "functions/core/src/routes/timer/get.ts"
    click TimerPost "https://github.com/jasonpraful/hono-workflows-do/blob/main//functions/core/src/routes/timer/post.ts" "functions/core/src/routes/timer/post.ts"
    click WranglerCore "https://github.com/jasonpraful/hono-workflows-do/blob/main/functions/core/wrangler.jsonc"
    click TSConfigCore "https://github.com/jasonpraful/hono-workflows-do/blob/main/functions/core/tsconfig.json"

    %% Click Events for Workflows Worker
    click WFIndex "https://github.com/jasonpraful/hono-workflows-do/blob/main/functions/workflows/src/index.ts"
    click TimerWF "https://github.com/jasonpraful/hono-workflows-do/blob/main/functions/workflows/src/timer.ts"
    click AIWF "https://github.com/jasonpraful/hono-workflows-do/blob/main/functions/workflows/src/ai.ts"
    click WranglerWF "https://github.com/jasonpraful/hono-workflows-do/blob/main/functions/workflows/wrangler.jsonc"
    click TSConfigWF "https://github.com/jasonpraful/hono-workflows-do/blob/main/functions/workflows/tsconfig.json"

    %% Click Events for Project-Wide Config
    click PackageRoot "https://github.com/jasonpraful/hono-workflows-do/blob/main/package.json"
    click TSConfigRoot "https://github.com/jasonpraful/hono-workflows-do/blob/main/tsconfig.json"
    click Prettier "https://github.com/jasonpraful/hono-workflows-do/blob/main/.prettierrc"
    click Bun "https://github.com/jasonpraful/hono-workflows-do/blob/main/bun.lock"
    click Readme "https://github.com/jasonpraful/hono-workflows-do/blob/main/README.md"
    click Gitignore "https://github.com/jasonpraful/hono-workflows-do/blob/main/.gitignore"
```
