# anil-matcha/open-ai-ugc architecture

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

- Interactive diagram: https://gitdiagram.com/anil-matcha/open-ai-ugc
- Repository: https://github.com/anil-matcha/open-ai-ugc

## Overview

Open AI UGC is a web studio for creating AI UGC video ads. The main workflow is sign in, upload optional reference images, submit a model-configured generation, then view its persisted status and result in the creations gallery. Credits and Stripe purchasing, custom MuAPI keys, and asynchronous webhook/polling updates are distinct supporting capabilities. Arrows reflect the sampled route calls and README-documented UI/API workflow; unsampled pages and webhook wiring are kept at directory scope where needed.

Main entry points: [`prisma/schema.prisma`](https://github.com/anil-matcha/open-ai-ugc/blob/main/prisma/schema.prisma) (PostgreSQL Data), [`src/app/page.js`](https://github.com/anil-matcha/open-ai-ugc/blob/main/src/app/page.js) (Studio UI), [`src/app/api/generate/route.js`](https://github.com/anil-matcha/open-ai-ugc/blob/main/src/app/api/generate/route.js) (Generate Route), [`src/lib/services/billing.js`](https://github.com/anil-matcha/open-ai-ugc/blob/main/src/lib/services/billing.js) (Billing Service)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_studio["UGC Studio"]
  node_studio_ui["Studio UI<br/>[page.js]"]
  node_gallery["Creations Gallery<br/>[page.js]"]
  node_login["Sign-in Page<br/>[page.js]"]
end

subgraph group_generation["Generation Pipeline"]
  node_upload_route["Image Upload<br/>[route.js]"]
  node_generate_route["Generate Route<br/>[route.js]"]
  node_muapi_hook["Completion Webhook<br/>[route.js]"]
  node_creation_api["Creations API<br/>[route.js]"]
  node_creation_detail["Creation Status<br/>[route.js]"]
end

subgraph group_identity["Identity &amp; Credits"]
  node_auth_ui["Session Provider<br/>[providers.js]"]
  node_auth["Authentication<br/>[auth.js]"]
  node_auth_route["Auth Endpoint<br/>[route.js]"]
  node_apikey_api["Custom API Key<br/>[route.js]"]
  node_user_service["User Credits<br/>[user.js]"]
  node_db[("PostgreSQL Data<br/>[schema.prisma]")]
end

subgraph group_billing["Billing"]
  node_pricing["Plans Page<br/>[page.js]"]
  node_checkout_api["Checkout Route<br/>[route.js]"]
  node_stripe_checkout["Stripe Checkout<br/>[route.js]"]
  node_billing_service["Billing Service<br/>[billing.js]"]
  node_stripe_hook["Stripe Webhook<br/>[route.js]"]
end

node_creator(("Creator"))
node_muapi{{"MuAPI"}}
node_stripe{{"Stripe"}}

node_creator -->|"creates ad"| node_studio_ui
node_studio_ui -.->|"uploads references"| node_upload_route
node_upload_route -->|"uploads file"| node_muapi
node_studio_ui -.->|"submits render"| node_generate_route
node_generate_route -->|"requests generation"| node_muapi
node_generate_route -->|"persists job"| node_db
node_muapi -->|"sends completion"| node_muapi_hook
node_muapi_hook -.->|"updates creation"| node_db
node_gallery -.->|"loads creations"| node_creation_api
node_creation_api -->|"reads creations"| node_db
node_gallery -.->|"polls status"| node_creation_detail
node_creation_detail -->|"reads and updates"| node_db
node_creation_detail -->|"polls result"| node_muapi
node_creator -->|"signs in"| node_login
node_login -.->|"authenticates"| node_auth_route
node_auth_route -->|"uses options"| node_auth
node_auth -->|"reads users"| node_db
node_studio_ui -.->|"uses session"| node_auth_ui
node_creator -->|"chooses plan"| node_pricing
node_pricing -.->|"starts checkout"| node_checkout_api
node_checkout_api -->|"creates session"| node_billing_service
node_billing_service -->|"creates checkout"| node_stripe
node_stripe -.->|"notifies payment"| node_stripe_hook
node_stripe_hook -.->|"handles event"| node_billing_service
node_billing_service -->|"adds credits"| node_user_service
node_user_service -->|"updates balance"| node_db
node_creator -.->|"sets own key"| node_apikey_api
node_apikey_api -->|"stores key"| node_db
node_generate_route -.->|"deducts credits"| node_user_service

click node_studio_ui "https://github.com/anil-matcha/open-ai-ugc/blob/main/src/app/page.js"
click node_gallery "https://github.com/anil-matcha/open-ai-ugc/blob/main/src/app/gallery/page.js"
click node_login "https://github.com/anil-matcha/open-ai-ugc/blob/main/src/app/login/page.js"
click node_pricing "https://github.com/anil-matcha/open-ai-ugc/blob/main/src/app/pricing/page.js"
click node_upload_route "https://github.com/anil-matcha/open-ai-ugc/blob/main/src/app/api/upload/route.js"
click node_generate_route "https://github.com/anil-matcha/open-ai-ugc/blob/main/src/app/api/generate/route.js"
click node_muapi_hook "https://github.com/anil-matcha/open-ai-ugc/blob/main/src/app/api/webhook/muapi/route.js"
click node_creation_api "https://github.com/anil-matcha/open-ai-ugc/blob/main/src/app/api/creations/route.js"
click node_creation_detail "https://github.com/anil-matcha/open-ai-ugc/blob/main/src/app/api/creations/%5Bid%5D/route.js"
click node_auth_ui "https://github.com/anil-matcha/open-ai-ugc/blob/main/src/app/providers.js"
click node_auth "https://github.com/anil-matcha/open-ai-ugc/blob/main/src/lib/auth.js"
click node_auth_route "https://github.com/anil-matcha/open-ai-ugc/blob/main/src/app/api/auth/%5B...nextauth%5D/route.js"
click node_apikey_api "https://github.com/anil-matcha/open-ai-ugc/blob/main/src/app/api/user/apikey/route.js"
click node_user_service "https://github.com/anil-matcha/open-ai-ugc/blob/main/src/lib/services/user.js"
click node_db "https://github.com/anil-matcha/open-ai-ugc/blob/main/prisma/schema.prisma"
click node_checkout_api "https://github.com/anil-matcha/open-ai-ugc/blob/main/src/app/api/checkout/route.js"
click node_stripe_checkout "https://github.com/anil-matcha/open-ai-ugc/blob/main/src/app/api/checkout/stripe/route.js"
click node_billing_service "https://github.com/anil-matcha/open-ai-ugc/blob/main/src/lib/services/billing.js"
click node_stripe_hook "https://github.com/anil-matcha/open-ai-ugc/blob/main/src/app/api/webhook/stripe/route.js"

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_studio_ui,node_gallery,node_login toneBlue
class node_upload_route,node_generate_route,node_muapi_hook,node_creation_api,node_creation_detail toneAmber
class node_auth_ui,node_auth,node_auth_route,node_apikey_api,node_user_service,node_db,node_muapi toneMint
class node_pricing,node_checkout_api,node_stripe_checkout,node_billing_service,node_stripe_hook toneRose
class node_creator,node_stripe toneIndigo
```

## Components

### UGC Studio

- [Studio UI](https://github.com/anil-matcha/open-ai-ugc/blob/main/src/app/page.js): `src/app/page.js`
- [Creations Gallery](https://github.com/anil-matcha/open-ai-ugc/blob/main/src/app/gallery/page.js): `src/app/gallery/page.js`
- [Sign-in Page](https://github.com/anil-matcha/open-ai-ugc/blob/main/src/app/login/page.js): `src/app/login/page.js`

### Generation Pipeline

- [Image Upload](https://github.com/anil-matcha/open-ai-ugc/blob/main/src/app/api/upload/route.js): `src/app/api/upload/route.js`
- [Generate Route](https://github.com/anil-matcha/open-ai-ugc/blob/main/src/app/api/generate/route.js): `src/app/api/generate/route.js`
- [Completion Webhook](https://github.com/anil-matcha/open-ai-ugc/blob/main/src/app/api/webhook/muapi/route.js): `src/app/api/webhook/muapi/route.js`
- [Creations API](https://github.com/anil-matcha/open-ai-ugc/blob/main/src/app/api/creations/route.js): `src/app/api/creations/route.js`
- [Creation Status](https://github.com/anil-matcha/open-ai-ugc/blob/main/src/app/api/creations/%5Bid%5D/route.js): `src/app/api/creations/[id]/route.js`

### Identity & Credits

- [Session Provider](https://github.com/anil-matcha/open-ai-ugc/blob/main/src/app/providers.js): `src/app/providers.js`
- [Authentication](https://github.com/anil-matcha/open-ai-ugc/blob/main/src/lib/auth.js): `src/lib/auth.js`
- [Auth Endpoint](https://github.com/anil-matcha/open-ai-ugc/blob/main/src/app/api/auth/%5B...nextauth%5D/route.js): `src/app/api/auth/[...nextauth]/route.js`
- [Custom API Key](https://github.com/anil-matcha/open-ai-ugc/blob/main/src/app/api/user/apikey/route.js): `src/app/api/user/apikey/route.js`
- [User Credits](https://github.com/anil-matcha/open-ai-ugc/blob/main/src/lib/services/user.js): `src/lib/services/user.js`
- [PostgreSQL Data](https://github.com/anil-matcha/open-ai-ugc/blob/main/prisma/schema.prisma): `prisma/schema.prisma`

### Billing

- [Plans Page](https://github.com/anil-matcha/open-ai-ugc/blob/main/src/app/pricing/page.js): `src/app/pricing/page.js`
- [Checkout Route](https://github.com/anil-matcha/open-ai-ugc/blob/main/src/app/api/checkout/route.js): `src/app/api/checkout/route.js`
- [Stripe Checkout](https://github.com/anil-matcha/open-ai-ugc/blob/main/src/app/api/checkout/stripe/route.js): `src/app/api/checkout/stripe/route.js`
- [Billing Service](https://github.com/anil-matcha/open-ai-ugc/blob/main/src/lib/services/billing.js): `src/lib/services/billing.js`
- [Stripe Webhook](https://github.com/anil-matcha/open-ai-ugc/blob/main/src/app/api/webhook/stripe/route.js): `src/app/api/webhook/stripe/route.js`

### Other components

- **Creator**
- **MuAPI**
- **Stripe**

## Connections

- Creator → Studio UI: creates ad (evidence: `README.md`)
- Studio UI → Image Upload: uploads references (evidence: `README.md`)
- Image Upload → MuAPI: uploads file (evidence: `src/app/api/upload/route.js`)
- Studio UI → Generate Route: submits render (evidence: `README.md`)
- Generate Route → MuAPI: requests generation (evidence: `src/app/api/generate/route.js`)
- Generate Route → PostgreSQL Data: persists job (evidence: `src/app/api/generate/route.js`)
- MuAPI → Completion Webhook: sends completion (evidence: `README.md`)
- Completion Webhook → PostgreSQL Data: updates creation (evidence: `README.md`)
- Creations Gallery → Creations API: loads creations (evidence: `README.md`)
- Creations API → PostgreSQL Data: reads creations (evidence: `src/app/api/creations/route.js`)
- Creations Gallery → Creation Status: polls status (evidence: `README.md`)
- Creation Status → PostgreSQL Data: reads and updates (evidence: `src/app/api/creations/[id]/route.js`)
- Creation Status → MuAPI: polls result (evidence: `src/app/api/creations/[id]/route.js`)
- Creator → Sign-in Page: signs in (evidence: `README.md`)
- Sign-in Page → Auth Endpoint: authenticates (evidence: `README.md`)
- Auth Endpoint → Authentication: uses options (evidence: `src/app/api/auth/[...nextauth]/route.js`)
- Authentication → PostgreSQL Data: reads users (evidence: `src/lib/auth.js`)
- Studio UI → Session Provider: uses session (evidence: `src/app/providers.js`)
- Creator → Plans Page: chooses plan (evidence: `README.md`)
- Plans Page → Checkout Route: starts checkout (evidence: `README.md`)
- Checkout Route → Billing Service: creates session (evidence: `src/app/api/checkout/route.js`)
- Billing Service → Stripe: creates checkout (evidence: `src/lib/services/billing.js`)
- Stripe → Stripe Webhook: notifies payment (evidence: `README.md`)
- Stripe Webhook → Billing Service: handles event (evidence: `README.md`)
- Billing Service → User Credits: adds credits (evidence: `src/lib/services/billing.js`)
- User Credits → PostgreSQL Data: updates balance (evidence: `src/lib/services/user.js`)
- Creator → Custom API Key: sets own key (evidence: `README.md`)
- Custom API Key → PostgreSQL Data: stores key (evidence: `src/app/api/user/apikey/route.js`)
- Generate Route → User Credits: deducts credits
