# ravirraj/z0 architecture

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

- Interactive diagram: https://gitdiagram.com/ravirraj/z0
- Repository: https://github.com/ravirraj/z0

## Overview

Z0 is a self-hosted AI React-component generator. The main workflow takes a developer’s prompt and optional images through the chat UI, sends it to the v0 service, streams or returns generated chat content, and presents the result in a live preview. Users can authenticate, save and manage conversations, configure a personal v0 API key, and browse generated projects. Several links are documented or visible in the source index rather than in excerpts; those evidence limits are reflected in the graph.

Main entry points: [`lib/db/queries.ts`](https://github.com/ravirraj/z0/blob/main/lib/db/queries.ts) (Database Queries), [`lib/v0-client.ts`](https://github.com/ravirraj/z0/blob/main/lib/v0-client.ts) (v0 Client), [`components/home/home-client.tsx`](https://github.com/ravirraj/z0/blob/main/components/home/home-client.tsx) (Prompt Workspace), [`app/api/chat/route.ts`](https://github.com/ravirraj/z0/blob/main/app/api/chat/route.ts) (Generation API)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_identity["Identity &amp; Keys"]
  node_auth_pages["Login &amp; Register<br/>[page.tsx]"]
  node_auth_form["Auth Form<br/>[auth-form.tsx]"]
  node_auth_client["Auth Client<br/>[auth-client.ts]"]
  node_auth_session["Session Helper<br/>[auth.ts]"]
  node_auth_backend["Auth Backend<br/>[auth.ts]"]
  node_key_routes["v0 Key API<br/>[route.ts]"]
end

subgraph group_generation["Generation &amp; Preview"]
  node_home["Prompt Workspace<br/>[home-client.tsx]"]
  node_chat_input["Chat Input<br/>[chat-input.tsx]"]
  node_chat_api["Generation API<br/>[route.ts]"]
  node_v0_client["v0 Client<br/>[v0-client.ts]"]
  node_chat_messages["Message Renderer<br/>[chat-messages.tsx]"]
  node_preview_panel["Live Preview<br/>[preview-panel.tsx]"]
  node_web_preview["Preview Frame<br/>[web-preview.tsx]"]
  node_qr_dialog["QR Sharing<br/>[qr-code-dialog.tsx]"]
end

subgraph group_history["Chat &amp; Projects"]
  node_chat_api_routes["Chat Management APIs"]
  node_chats_api["Chat List &amp; Detail APIs"]
  node_chat_pages["Chat Pages"]
  node_chat_detail["Chat Detail UI"]
  node_projects_page["Projects Dashboard<br/>[projects-page.tsx]"]
  node_projects_data["Project Queries<br/>[projects.ts]"]
end

subgraph group_persistence["Persistence"]
  node_database[("PostgreSQL Data<br/>[schema.ts]")]
  node_db_queries["Database Queries<br/>[queries.ts]"]
end

node_developer(("Developer"))
node_v0_service["v0 API"]

node_developer -->|"signs in"| node_auth_pages
node_auth_pages -->|"renders"| node_auth_form
node_auth_form -->|"authenticates with"| node_auth_client
node_auth_client -.->|"uses session service"| node_auth_backend
node_auth_backend -->|"reads auth data"| node_database
node_developer -->|"describes component"| node_home
node_home -->|"renders"| node_chat_input
node_home -.->|"submits prompt"| node_chat_api
node_chat_api -->|"checks session"| node_auth_session
node_chat_api -->|"checks limit; records owner"| node_db_queries
node_chat_api -->|"requests generation"| node_v0_client
node_v0_client -->|"loads user key"| node_db_queries
node_v0_client -->|"calls SDK"| node_v0_service
node_chat_api -.->|"streams responses"| node_chat_messages
node_home -->|"renders"| node_chat_messages
node_home -->|"renders"| node_preview_panel
node_preview_panel -->|"embeds preview"| node_web_preview
node_preview_panel -->|"opens sharing"| node_qr_dialog
node_chat_pages -.->|"renders"| node_chat_detail
node_chat_detail -->|"uses input"| node_chat_input
node_chat_detail -->|"renders messages"| node_chat_messages
node_chat_detail -->|"shows preview"| node_preview_panel
node_chat_api_routes -->|"checks session"| node_auth_session
node_chat_api_routes -->|"manages ownership"| node_db_queries
node_chat_api_routes -->|"manages v0 chats"| node_v0_client
node_chats_api -->|"loads chat records"| node_db_queries
node_chats_api -->|"accesses v0 chats"| node_v0_client
node_key_routes -->|"stores key"| node_db_queries
node_key_routes -->|"validates key"| node_v0_client
node_projects_page -->|"loads projects"| node_projects_data
node_projects_data -.->|"reads chat data"| node_db_queries
node_db_queries -->|"reads and writes"| node_database

click node_auth_pages "https://github.com/ravirraj/z0/blob/main/app/(auth)/login/page.tsx"
click node_auth_form "https://github.com/ravirraj/z0/blob/main/components/auth-form.tsx"
click node_auth_client "https://github.com/ravirraj/z0/blob/main/lib/auth-client.ts"
click node_auth_session "https://github.com/ravirraj/z0/blob/main/app/(auth)/auth.ts"
click node_auth_backend "https://github.com/ravirraj/z0/blob/main/lib/auth.ts"
click node_key_routes "https://github.com/ravirraj/z0/blob/main/app/api/user/v0-key/route.ts"
click node_home "https://github.com/ravirraj/z0/blob/main/components/home/home-client.tsx"
click node_chat_input "https://github.com/ravirraj/z0/blob/main/components/chat/chat-input.tsx"
click node_chat_api "https://github.com/ravirraj/z0/blob/main/app/api/chat/route.ts"
click node_v0_client "https://github.com/ravirraj/z0/blob/main/lib/v0-client.ts"
click node_chat_messages "https://github.com/ravirraj/z0/blob/main/components/chat/chat-messages.tsx"
click node_preview_panel "https://github.com/ravirraj/z0/blob/main/components/chat/preview-panel.tsx"
click node_web_preview "https://github.com/ravirraj/z0/blob/main/components/ai-elements/web-preview.tsx"
click node_qr_dialog "https://github.com/ravirraj/z0/blob/main/components/dialogs/qr-code-dialog.tsx"
click node_chat_api_routes "https://github.com/ravirraj/z0/tree/main/app/api/chat"
click node_chats_api "https://github.com/ravirraj/z0/tree/main/app/api/chats"
click node_chat_pages "https://github.com/ravirraj/z0/tree/main/app/chats"
click node_chat_detail "https://github.com/ravirraj/z0/blob/main/components/chats/chat-detail-client.tsx"
click node_projects_page "https://github.com/ravirraj/z0/blob/main/components/projects/projects-page.tsx"
click node_projects_data "https://github.com/ravirraj/z0/blob/main/lib/projects.ts"
click node_database "https://github.com/ravirraj/z0/blob/main/lib/db/schema.ts"
click node_db_queries "https://github.com/ravirraj/z0/blob/main/lib/db/queries.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_auth_pages,node_auth_form,node_auth_client,node_auth_session,node_auth_backend,node_key_routes toneBlue
class node_home,node_chat_input,node_chat_api,node_v0_client,node_chat_messages,node_preview_panel,node_web_preview,node_qr_dialog toneAmber
class node_chat_api_routes,node_chats_api,node_chat_pages,node_chat_detail,node_projects_page,node_projects_data,node_v0_service toneMint
class node_database,node_db_queries toneRose
class node_developer toneIndigo
```

## Components

### Identity & Keys

- [Login & Register](https://github.com/ravirraj/z0/blob/main/app/(auth)/login/page.tsx): `app/(auth)/login/page.tsx`
- [Auth Form](https://github.com/ravirraj/z0/blob/main/components/auth-form.tsx): `components/auth-form.tsx`
- [Auth Client](https://github.com/ravirraj/z0/blob/main/lib/auth-client.ts): `lib/auth-client.ts`
- [Session Helper](https://github.com/ravirraj/z0/blob/main/app/(auth)/auth.ts): `app/(auth)/auth.ts`
- [Auth Backend](https://github.com/ravirraj/z0/blob/main/lib/auth.ts): `lib/auth.ts`
- [v0 Key API](https://github.com/ravirraj/z0/blob/main/app/api/user/v0-key/route.ts): `app/api/user/v0-key/route.ts`

### Generation & Preview

- [Prompt Workspace](https://github.com/ravirraj/z0/blob/main/components/home/home-client.tsx): `components/home/home-client.tsx`
- [Chat Input](https://github.com/ravirraj/z0/blob/main/components/chat/chat-input.tsx): `components/chat/chat-input.tsx`
- [Generation API](https://github.com/ravirraj/z0/blob/main/app/api/chat/route.ts): `app/api/chat/route.ts`
- [v0 Client](https://github.com/ravirraj/z0/blob/main/lib/v0-client.ts): `lib/v0-client.ts`
- [Message Renderer](https://github.com/ravirraj/z0/blob/main/components/chat/chat-messages.tsx): `components/chat/chat-messages.tsx`
- [Live Preview](https://github.com/ravirraj/z0/blob/main/components/chat/preview-panel.tsx): `components/chat/preview-panel.tsx`
- [Preview Frame](https://github.com/ravirraj/z0/blob/main/components/ai-elements/web-preview.tsx): `components/ai-elements/web-preview.tsx`
- [QR Sharing](https://github.com/ravirraj/z0/blob/main/components/dialogs/qr-code-dialog.tsx): `components/dialogs/qr-code-dialog.tsx`

### Chat & Projects

- [Chat Management APIs](https://github.com/ravirraj/z0/tree/main/app/api/chat): `app/api/chat`
- [Chat List & Detail APIs](https://github.com/ravirraj/z0/tree/main/app/api/chats): `app/api/chats`
- [Chat Pages](https://github.com/ravirraj/z0/tree/main/app/chats): `app/chats`
- [Chat Detail UI](https://github.com/ravirraj/z0/blob/main/components/chats/chat-detail-client.tsx): `components/chats/chat-detail-client.tsx`
- [Projects Dashboard](https://github.com/ravirraj/z0/blob/main/components/projects/projects-page.tsx): `components/projects/projects-page.tsx`
- [Project Queries](https://github.com/ravirraj/z0/blob/main/lib/projects.ts): `lib/projects.ts`

### Persistence

- [PostgreSQL Data](https://github.com/ravirraj/z0/blob/main/lib/db/schema.ts): `lib/db/schema.ts`
- [Database Queries](https://github.com/ravirraj/z0/blob/main/lib/db/queries.ts): `lib/db/queries.ts`

### Other components

- **Developer**
- **v0 API**

## Connections

- Developer → Login & Register: signs in (evidence: `README.md`)
- Login & Register → Auth Form: renders (evidence: `app/(auth)/login/page.tsx`)
- Auth Form → Auth Client: authenticates with (evidence: `components/auth-form.tsx`)
- Auth Client → Auth Backend: uses session service
- Auth Backend → PostgreSQL Data: reads auth data (evidence: `lib/auth.ts`)
- Developer → Prompt Workspace: describes component (evidence: `README.md`)
- Prompt Workspace → Chat Input: renders (evidence: `components/home/home-client.tsx`)
- Prompt Workspace → Generation API: submits prompt
- Generation API → Session Helper: checks session (evidence: `app/api/chat/route.ts`)
- Generation API → Database Queries: checks limit; records owner (evidence: `app/api/chat/route.ts`)
- Generation API → v0 Client: requests generation (evidence: `app/api/chat/route.ts`)
- v0 Client → Database Queries: loads user key (evidence: `lib/v0-client.ts`)
- v0 Client → v0 API: calls SDK (evidence: `lib/v0-client.ts`)
- Generation API → Message Renderer: streams responses
- Prompt Workspace → Message Renderer: renders (evidence: `components/home/home-client.tsx`)
- Prompt Workspace → Live Preview: renders (evidence: `components/home/home-client.tsx`)
- Live Preview → Preview Frame: embeds preview (evidence: `components/chat/preview-panel.tsx`)
- Live Preview → QR Sharing: opens sharing (evidence: `components/chat/preview-panel.tsx`)
- Chat Pages → Chat Detail UI: renders
- Chat Detail UI → Chat Input: uses input (evidence: `components/chats/chat-detail-client.tsx`)
- Chat Detail UI → Message Renderer: renders messages (evidence: `components/chats/chat-detail-client.tsx`)
- Chat Detail UI → Live Preview: shows preview (evidence: `components/chats/chat-detail-client.tsx`)
- Chat Management APIs → Session Helper: checks session (evidence: `app/api/chat/delete/route.ts`)
- Chat Management APIs → Database Queries: manages ownership (evidence: `app/api/chat/ownership/route.ts`)
- Chat Management APIs → v0 Client: manages v0 chats (evidence: `app/api/chat/fork/route.ts`)
- Chat List & Detail APIs → Database Queries: loads chat records (evidence: `app/api/chats/route.ts`)
- Chat List & Detail APIs → v0 Client: accesses v0 chats (evidence: `app/api/chats/route.ts`)
- v0 Key API → Database Queries: stores key (evidence: `app/api/user/v0-key/route.ts`)
- v0 Key API → v0 Client: validates key (evidence: `app/api/user/v0-key/route.ts`)
- Projects Dashboard → Project Queries: loads projects (evidence: `app/projects/page.tsx`)
- Project Queries → Database Queries: reads chat data
- Database Queries → PostgreSQL Data: reads and writes (evidence: `lib/db/queries.ts`)
