# yeusepe/yucp-creator-assistant architecture

> Architecture diagram of the GitHub repository yeusepe/yucp-creator-assistant, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2026-08-03). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/yeusepe/yucp-creator-assistant
- Repository: https://github.com/yeusepe/yucp-creator-assistant

## Overview

#### Purpose and runtime entry points
YUCP Creator Assistant is a multi-tenant entitlement platform: creators connect storefronts and Discord guilds; buyers prove identity or purchases; verified entitlements drive Discord roles, gated downloads, and package access.

Primary runtime entries:
- Discord bot: `apps/bot/src/index.ts`
- Bun HTTP API: `apps/api/src/index.ts`, `apps/api/src/createServer.ts`
- Cloudflare Worker/Vite web dashboard: `apps/web/src/router.tsx`, `apps/web/src/routes/__root.tsx`
- Convex backend functions and schema: `convex/schema.ts`, `convex/http.ts`

#### Interaction surfaces: bot, web, and API
The bot exposes creator and administrator workflows, processes Discord interactions, and runs role synchronization and gated-download delivery. It calls backend capabilities through internal RPC rather than directly owning persistence.
- Command registry and handlers: `apps/bot/src/commands/index.ts`, `apps/bot/src/handlers/interactions.ts`
- Role and download services: `apps/bot/src/services/roleSync.ts`, `apps/bot/src/services/lienedDownloads.ts`
- API route composition and server boundaries: `apps/api/src/routes/index.ts`, `apps/api/src/internalRpc/router.ts`

The web app is the browser-facing dashboard, account area, OAuth/verification UI, and API/auth proxy. Authenticated dashboard routing is separated from public routes.
- Router and authenticated shell: `apps/web/src/router.tsx`, `apps/web/src/routes/_authenticated.tsx`
- Server-side API/auth proxy: `apps/web/src/lib/server/api-proxy.ts`, `apps/web/src/routes/api/$.ts`

#### Identity, authorization, and tenant boundary
Better Auth is hosted with Convex; the API and web frontend broker sessions, OAuth flows, origin enforcement, and scoped identities. Guild/workspace ownership and collaborators establish the tenant context for creator operations.

- API auth/session layer: `apps/api/src/auth/index.ts`, `apps/api/src/auth/session.ts`
- Convex auth integration: `convex/betterAuth/auth.ts`, `convex/auth.ts`
- Tenant/workspace authorization: `convex/creatorWorkspacePermissions.ts`, `convex/workspaceResolution.realtest.ts`
- Public API authorization surfaces: `apps/api/src/routes/publicV2/auth.ts`, `apps/api/src/routes/publicV2/bindings.ts`

#### Providers, webhooks, and verification
Provider adapters normalize OAuth, API-key, webhook, buyer-link, and license-verification behaviors across Discord, Gumroad, itch.io, Jinxxy, Lemon Squeezy, Patreon, Payhip, VRChat, and manual licenses. The API receives provider callbacks/webhooks; Convex persists connections and processes durable domain state; verification sessions resolve buyer identity and product access.

- Shared provider registry/contracts: `packages/providers/src/index.ts`, `packages/providers/src/descriptors/index.ts`
- API provider adapters and webhook ingress: `apps/api/src/providers/index.ts`, `apps/api/src/routes/webhooks.ts`
- Verification orchestration: `apps/api/src/verification/sessionManager.ts`, `apps/api/src/verification/completeLicense.ts`
- Durable webhook processing: `convex/webhookIngestion.ts`, `convex/webhookProcessing.ts`

#### Entitlements, policies, and role synchronization
Convex is the system of record for products, provider connections, buyer subjects, entitlements, guild links, role rules, and audit/event data. The policy package produces allow/deny decisions and remediation guidance. Completion or webhook changes enqueue role-sync work, which the bot executes against Discord.

- Entitlements and product resolution: `convex/entitlements.ts`, `convex/productResolution.ts`
- Role-rule and sync pipeline: `convex/role_rules.ts`, `convex/roleSyncEnqueue.ts`, `convex/roleSyncWorkpool.ts`
- Policy engine: `packages/policy/src/engine.ts`
- Bot-side Discord mutation: `apps/bot/src/services/roleSync.ts`

#### Package storage and protected delivery
A separate package lifecycle supports creator uploads, VPM repositories, installer/TUF metadata, and buyer-authorized delivery. Uploads enter quarantine, are ingested/materialized into object storage, registered in a PostgreSQL catalog, and served by Cloudflare Workers with signed/DPoP-bound access controls.

- API package endpoints: `apps/api/src/routes/creatorUploads.ts`, `apps/api/src/routes/vpmRepository.ts`
- Catalog control plane: `ops/catalog/catalog.ts`, `ops/catalog/database.ts`
- Ingestion/materialization: `ops/ingest-pipeline/ingestPipeline.ts`, `ops/materialization/materializationBroker.ts`
- Edge delivery: `services/delivery-worker/src/index.ts`, `services/rendition-worker/src/index.ts`

#### Infrastructure and external dependencies
Core runtimes are TypeScript on Node (bot), Bun (API), Convex (database/functions), and Cloudflare Workers (web and delivery). Production secrets are sourced from Infisical. External boundaries include Discord APIs/OAuth, provider storefront APIs and webhooks, S3-compatible/R2-style object storage, PostgreSQL for the catalog, and HyperDX/OpenTelemetry observability.

Shared contracts and cross-runtime utilities reside in `packages/private-rpc/src/index.ts`, `packages/application/src/composition/createApplicationServices.ts`, and `packages/shared/src/index.ts`.

Main entry points: [`apps/api/src/index.ts`](https://github.com/yeusepe/yucp-creator-assistant/blob/main/apps/api/src/index.ts) (Bun API), [`apps/bot/src/index.ts`](https://github.com/yeusepe/yucp-creator-assistant/blob/main/apps/bot/src/index.ts) (Discord bot), [`convex/entitlements.ts`](https://github.com/yeusepe/yucp-creator-assistant/blob/main/convex/entitlements.ts) (Entitlement resolution), [`ops/ingest-pipeline/ingestPipeline.ts`](https://github.com/yeusepe/yucp-creator-assistant/blob/main/ops/ingest-pipeline/ingestPipeline.ts) (Ingest and materialize)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_surfaces["Runtime surfaces"]
  node_bot["Discord bot<br/>Node runtime<br/>[index.ts]"]
  node_bot_interactions["Interaction handlers<br/>bot handlers<br/>[interactions.ts]"]
  node_api["Bun API<br/>HTTP runtime<br/>[index.ts]"]
  node_api_rpc["Internal RPC router<br/>API boundary<br/>[router.ts]"]
  node_web["Web dashboard<br/>Cloudflare Worker/Vite<br/>[router.tsx]"]
  node_web_proxy["API/auth proxy<br/>server proxy<br/>[api-proxy.ts]"]
end

subgraph group_control["Identity and tenant control"]
  node_auth["Better Auth<br/>identity integration<br/>[auth.ts]"]
  node_tenant_auth["Workspace authorization<br/>tenant boundary"]
end

subgraph group_entitlements["Entitlements and automation"]
  node_convex[("Convex domain backend<br/>system of record<br/>[schema.ts]")]
  node_entitlements["Entitlement resolution<br/>domain functions<br/>[entitlements.ts]"]
  node_policy["Policy engine<br/>shared package<br/>[engine.ts]"]
  node_role_queue["Role-sync workpool<br/>durable queue"]
end

subgraph group_providers["Provider verification"]
  node_provider_registry["Provider contracts<br/>shared registry<br/>[index.ts]"]
  node_webhooks["Webhook processing<br/>durable ingestion"]
  node_verification["Verification orchestration<br/>API service<br/>[sessionManager.ts]"]
end

subgraph group_packages["Package lifecycle"]
  node_uploads["Creator package endpoints<br/>API routes<br/>[creatorUploads.ts]"]
  node_ingestion["Ingest and materialize<br/>pipeline<br/>[ingestPipeline.ts]"]
  node_catalog[("Package catalog<br/>PostgreSQL control plane<br/>[catalog.ts]")]
  node_storage[("Object storage<br/>S3/R2 storage")]
  node_delivery["Protected delivery worker<br/>Cloudflare Worker<br/>[index.ts]"]
end

node_discord{{"Discord platform<br/>external API"}}
node_storefronts{{"Storefront providers<br/>external APIs"}}

node_discord -->|"interactions and OAuth"| node_bot
node_bot -->|"dispatches"| node_bot_interactions
node_bot_interactions -->|"internal RPC"| node_api_rpc
node_api_rpc -->|"domain operations"| node_convex
node_web -->|"authenticated requests"| node_web_proxy
node_web_proxy -->|"proxies API/auth"| node_api
node_api -->|"brokers sessions and OAuth"| node_auth
node_auth -->|"identity state"| node_convex
node_tenant_auth -->|"tenant-scoped access"| node_convex
node_api -->|"authorizes creator operations"| node_tenant_auth
node_api -->|"uses adapters"| node_provider_registry
node_storefronts -->|"OAuth callbacks and webhooks"| node_api
node_api -->|"starts verification"| node_verification
node_verification -->|"proves buyer access"| node_entitlements
node_api -->|"persists webhook events"| node_webhooks
node_webhooks -->|"updates access"| node_entitlements
node_entitlements -->|"evaluates rules"| node_policy
node_policy -->|"approved role changes"| node_role_queue
node_role_queue -->|"sync work"| node_bot
node_bot -->|"mutates guild roles"| node_discord
node_api -->|"package requests"| node_uploads
node_uploads -->|"quarantined objects"| node_storage
node_storage -->|"ingests uploads"| node_ingestion
node_ingestion -->|"registers artifacts"| node_catalog
node_ingestion -->|"materializes objects"| node_storage
node_delivery -->|"resolves package metadata"| node_catalog
node_delivery -->|"serves authorized artifacts"| node_storage
node_entitlements -->|"authorizes buyer delivery"| node_delivery

click node_bot "https://github.com/yeusepe/yucp-creator-assistant/blob/main/apps/bot/src/index.ts"
click node_bot_interactions "https://github.com/yeusepe/yucp-creator-assistant/blob/main/apps/bot/src/handlers/interactions.ts"
click node_api "https://github.com/yeusepe/yucp-creator-assistant/blob/main/apps/api/src/index.ts"
click node_api_rpc "https://github.com/yeusepe/yucp-creator-assistant/blob/main/apps/api/src/internalRpc/router.ts"
click node_web "https://github.com/yeusepe/yucp-creator-assistant/blob/main/apps/web/src/router.tsx"
click node_web_proxy "https://github.com/yeusepe/yucp-creator-assistant/blob/main/apps/web/src/lib/server/api-proxy.ts"
click node_auth "https://github.com/yeusepe/yucp-creator-assistant/blob/main/convex/betterAuth/auth.ts"
click node_tenant_auth "https://github.com/yeusepe/yucp-creator-assistant/blob/main/convex/creatorWorkspacePermissions.ts"
click node_convex "https://github.com/yeusepe/yucp-creator-assistant/blob/main/convex/schema.ts"
click node_entitlements "https://github.com/yeusepe/yucp-creator-assistant/blob/main/convex/entitlements.ts"
click node_policy "https://github.com/yeusepe/yucp-creator-assistant/blob/main/packages/policy/src/engine.ts"
click node_role_queue "https://github.com/yeusepe/yucp-creator-assistant/blob/main/convex/roleSyncWorkpool.ts"
click node_provider_registry "https://github.com/yeusepe/yucp-creator-assistant/blob/main/packages/providers/src/index.ts"
click node_webhooks "https://github.com/yeusepe/yucp-creator-assistant/blob/main/convex/webhookProcessing.ts"
click node_verification "https://github.com/yeusepe/yucp-creator-assistant/blob/main/apps/api/src/verification/sessionManager.ts"
click node_uploads "https://github.com/yeusepe/yucp-creator-assistant/blob/main/apps/api/src/routes/creatorUploads.ts"
click node_ingestion "https://github.com/yeusepe/yucp-creator-assistant/blob/main/ops/ingest-pipeline/ingestPipeline.ts"
click node_catalog "https://github.com/yeusepe/yucp-creator-assistant/blob/main/ops/catalog/catalog.ts"
click node_delivery "https://github.com/yeusepe/yucp-creator-assistant/blob/main/services/delivery-worker/src/index.ts"

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_bot,node_bot_interactions,node_api,node_api_rpc,node_web,node_web_proxy toneBlue
class node_auth,node_tenant_auth toneAmber
class node_convex,node_entitlements,node_policy,node_role_queue toneMint
class node_provider_registry,node_webhooks,node_verification toneRose
class node_uploads,node_ingestion,node_catalog,node_storage,node_delivery toneIndigo
class node_discord,node_storefronts toneNeutral
```

## Components

### Runtime surfaces

- [Discord bot](https://github.com/yeusepe/yucp-creator-assistant/blob/main/apps/bot/src/index.ts): Node runtime · Runs creator workflows, interactions, role sync, and downloads. · `apps/bot/src/index.ts`
- [Interaction handlers](https://github.com/yeusepe/yucp-creator-assistant/blob/main/apps/bot/src/handlers/interactions.ts): bot handlers · `apps/bot/src/handlers/interactions.ts`
- [Bun API](https://github.com/yeusepe/yucp-creator-assistant/blob/main/apps/api/src/index.ts): HTTP runtime · Composes public, internal, provider, and package routes. · `apps/api/src/index.ts`
- [Internal RPC router](https://github.com/yeusepe/yucp-creator-assistant/blob/main/apps/api/src/internalRpc/router.ts): API boundary · Backend capability boundary used by the bot. · `apps/api/src/internalRpc/router.ts`
- [Web dashboard](https://github.com/yeusepe/yucp-creator-assistant/blob/main/apps/web/src/router.tsx): Cloudflare Worker/Vite · Creator dashboard, account, OAuth, and verification UI. · `apps/web/src/router.tsx`
- [API/auth proxy](https://github.com/yeusepe/yucp-creator-assistant/blob/main/apps/web/src/lib/server/api-proxy.ts): server proxy · `apps/web/src/lib/server/api-proxy.ts`

### Identity and tenant control

- [Better Auth](https://github.com/yeusepe/yucp-creator-assistant/blob/main/convex/betterAuth/auth.ts): identity integration · Sessions, OAuth, origins, and scoped identities. · `convex/betterAuth/auth.ts`
- [Workspace authorization](https://github.com/yeusepe/yucp-creator-assistant/blob/main/convex/creatorWorkspacePermissions.ts): tenant boundary · Guild ownership and collaborator access establish tenant context. · `convex/creatorWorkspacePermissions.ts`

### Entitlements and automation

- [Convex domain backend](https://github.com/yeusepe/yucp-creator-assistant/blob/main/convex/schema.ts): system of record · Persists products, connections, buyers, entitlements, rules, and events. · `convex/schema.ts`
- [Entitlement resolution](https://github.com/yeusepe/yucp-creator-assistant/blob/main/convex/entitlements.ts): domain functions · Resolves products and buyer access. · `convex/entitlements.ts`
- [Policy engine](https://github.com/yeusepe/yucp-creator-assistant/blob/main/packages/policy/src/engine.ts): shared package · Produces allow/deny decisions and remediation guidance. · `packages/policy/src/engine.ts`
- [Role-sync workpool](https://github.com/yeusepe/yucp-creator-assistant/blob/main/convex/roleSyncWorkpool.ts): durable queue · Queues role changes after entitlement updates. · `convex/roleSyncWorkpool.ts`

### Provider verification

- [Provider contracts](https://github.com/yeusepe/yucp-creator-assistant/blob/main/packages/providers/src/index.ts): shared registry · Normalizes provider OAuth, API key, webhook, and license behavior. · `packages/providers/src/index.ts`
- [Webhook processing](https://github.com/yeusepe/yucp-creator-assistant/blob/main/convex/webhookProcessing.ts): durable ingestion · Ingests and processes provider events. · `convex/webhookProcessing.ts`
- [Verification orchestration](https://github.com/yeusepe/yucp-creator-assistant/blob/main/apps/api/src/verification/sessionManager.ts): API service · Resolves buyer identity, licenses, and product access. · `apps/api/src/verification/sessionManager.ts`

### Package lifecycle

- [Creator package endpoints](https://github.com/yeusepe/yucp-creator-assistant/blob/main/apps/api/src/routes/creatorUploads.ts): API routes · Accepts uploads and serves VPM repository operations. · `apps/api/src/routes/creatorUploads.ts`
- [Ingest and materialize](https://github.com/yeusepe/yucp-creator-assistant/blob/main/ops/ingest-pipeline/ingestPipeline.ts): pipeline · Moves quarantined uploads into distributable package artifacts. · `ops/ingest-pipeline/ingestPipeline.ts`
- [Package catalog](https://github.com/yeusepe/yucp-creator-assistant/blob/main/ops/catalog/catalog.ts): PostgreSQL control plane · Registers package and repository metadata. · `ops/catalog/catalog.ts`
- **Object storage**: S3/R2 storage · Stores quarantined and materialized package objects.
- [Protected delivery worker](https://github.com/yeusepe/yucp-creator-assistant/blob/main/services/delivery-worker/src/index.ts): Cloudflare Worker · Serves signed and DPoP-bound package access. · `services/delivery-worker/src/index.ts`

### Other components

- **Discord platform**: external API · OAuth, interactions, guild roles, and DMs.
- **Storefront providers**: external APIs · Commerce APIs and webhook sources.

## Connections

- Discord platform → Discord bot: interactions and OAuth
- Discord bot → Interaction handlers: dispatches
- Interaction handlers → Internal RPC router: internal RPC
- Internal RPC router → Convex domain backend: domain operations
- Web dashboard → API/auth proxy: authenticated requests
- API/auth proxy → Bun API: proxies API/auth
- Bun API → Better Auth: brokers sessions and OAuth
- Better Auth → Convex domain backend: identity state
- Workspace authorization → Convex domain backend: tenant-scoped access
- Bun API → Workspace authorization: authorizes creator operations
- Bun API → Provider contracts: uses adapters
- Storefront providers → Bun API: OAuth callbacks and webhooks
- Bun API → Verification orchestration: starts verification
- Verification orchestration → Entitlement resolution: proves buyer access
- Bun API → Webhook processing: persists webhook events
- Webhook processing → Entitlement resolution: updates access
- Entitlement resolution → Policy engine: evaluates rules
- Policy engine → Role-sync workpool: approved role changes
- Role-sync workpool → Discord bot: sync work
- Discord bot → Discord platform: mutates guild roles
- Bun API → Creator package endpoints: package requests
- Creator package endpoints → Object storage: quarantined objects
- Object storage → Ingest and materialize: ingests uploads
- Ingest and materialize → Package catalog: registers artifacts
- Ingest and materialize → Object storage: materializes objects
- Protected delivery worker → Package catalog: resolves package metadata
- Protected delivery worker → Object storage: serves authorized artifacts
- Entitlement resolution → Protected delivery worker: authorizes buyer delivery
