# code-with-antonio/ai-teammates architecture

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

- Interactive diagram: https://gitdiagram.com/code-with-antonio/ai-teammates
- Repository: https://github.com/code-with-antonio/ai-teammates

## Overview

This is a bot-chat application: users create bots, converse with them individually or in groups, and can inspect a bot’s live sandbox desktop and metered usage. The main path runs from the dashboard through chat UI and server actions into Trigger.dev streaming, where model turns can use sandbox tools and hand off among bots. Bot configuration, group membership, billing gates, usage accounting, and desktop access are distinct supporting capabilities. Relationships below are limited to README or indexed source references and shown excerpts; several UI and action implementations were not sampled.

Main entry points: [`db/index.ts`](https://github.com/code-with-antonio/ai-teammates/blob/main/db/index.ts) (Postgres database), [`trigger/chat.ts`](https://github.com/code-with-antonio/ai-teammates/blob/main/trigger/chat.ts) (Chat orchestration), [`lib/usage.ts`](https://github.com/code-with-antonio/ai-teammates/blob/main/lib/usage.ts) (Usage ledger logic), [`components/chat.tsx`](https://github.com/code-with-antonio/ai-teammates/blob/main/components/chat.tsx) (Chat interface)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_product["User experience"]
  node_dashboard["Dashboard<br/>[page.tsx]"]
  node_chatpage["Chat page<br/>[page.tsx]"]
  node_chatui["Chat interface<br/>[chat.tsx]"]
  node_chatparts["Message components<br/>[message.tsx]"]
  node_prompt["Prompt input<br/>[prompt-input.tsx]"]
  node_desktop["Desktop panel<br/>[desktop-panel.tsx]"]
end

subgraph group_runtime["Chat runtime"]
  node_chatactions["Chat actions<br/>[chat.ts]"]
  node_triggerchat["Chat orchestration<br/>[chat.ts]"]
  node_handoff["Bot handoff<br/>[handoff-tool.ts]"]
  node_model["Chat model<br/>[model.ts]"]
end

subgraph group_bots["Bots and sandboxes"]
  node_botdialog["Bot editor<br/>[bot-dialog.tsx]"]
  node_botactions["Bot actions<br/>[bot.ts]"]
  node_sandboxtools["Sandbox tools<br/>[sandbox-tools.ts]"]
  node_daytona["Sandbox service<br/>[daytona.ts]"]
end

subgraph group_account["Billing and usage"]
  node_usagepage["Usage page<br/>[page.tsx]"]
  node_paywall["Paywall hook<br/>[use-paywall.ts]"]
  node_usageactions["Usage actions<br/>[usage.ts]"]
  node_usage["Usage ledger logic<br/>[usage.ts]"]
  node_billing["Billing rules<br/>[billing.ts]"]
  node_pricing["Pricing page<br/>[page.tsx]"]
end

subgraph group_data["Persistence"]
  node_chatqueries["Chat queries<br/>[chats.ts]"]
  node_botqueries["Bot queries<br/>[bots.ts]"]
  node_schema["Application schema<br/>[schema.ts]"]
  node_database[("Postgres database<br/>[index.ts]")]
end

node_user(("User"))

node_user -->|"opens"| node_dashboard
node_user -->|"opens"| node_chatpage
node_chatpage -->|"renders"| node_chatui
node_chatui -->|"renders"| node_prompt
node_chatui -->|"renders"| node_chatparts
node_chatui -->|"starts sessions"| node_chatactions
node_chatui -->|"loads transcript"| node_triggerchat
node_dashboard -->|"opens editor"| node_botdialog
node_botdialog -->|"submits bot"| node_botactions
node_chatactions -->|"loads chat"| node_chatqueries
node_chatactions -->|"starts session"| node_triggerchat
node_triggerchat -->|"provides tools"| node_sandboxtools
node_triggerchat -->|"streams model"| node_model
node_triggerchat -->|"checks and records"| node_usage
node_sandboxtools -->|"gets sandbox"| node_daytona
node_sandboxtools -->|"uses handoff types"| node_handoff
node_chatactions -->|"opens desktop"| node_daytona
node_chatpage -->|"renders"| node_desktop
node_botactions -->|"manages sandbox"| node_daytona
node_botactions -->|"checks usage"| node_usage
node_botactions -->|"persists bot"| node_database
node_chatactions -->|"updates chats"| node_database
node_chatqueries -->|"reads chats"| node_database
node_botqueries -->|"reads bots"| node_database
node_database -->|"uses schema"| node_schema
node_usagepage -->|"gets usage"| node_usage
node_paywall -->|"checks allowance"| node_usageactions
node_usageactions -.->|"checks usage"| node_usage
node_usage -->|"reads and writes ledger"| node_database
node_usage -->|"checks subscription"| node_billing
node_paywall -->|"checks plan"| node_billing
node_user -->|"views plans"| node_pricing
node_triggerchat -->|"loads chat data"| node_database

click node_dashboard "https://github.com/code-with-antonio/ai-teammates/blob/main/app/(dashboard)/page.tsx"
click node_chatpage "https://github.com/code-with-antonio/ai-teammates/blob/main/app/(dashboard)/chats/%5BchatId%5D/page.tsx"
click node_chatui "https://github.com/code-with-antonio/ai-teammates/blob/main/components/chat.tsx"
click node_chatparts "https://github.com/code-with-antonio/ai-teammates/blob/main/components/ai-elements/message.tsx"
click node_prompt "https://github.com/code-with-antonio/ai-teammates/blob/main/components/ai-elements/prompt-input.tsx"
click node_botdialog "https://github.com/code-with-antonio/ai-teammates/blob/main/components/bot-dialog.tsx"
click node_botactions "https://github.com/code-with-antonio/ai-teammates/blob/main/actions/bot.ts"
click node_chatactions "https://github.com/code-with-antonio/ai-teammates/blob/main/actions/chat.ts"
click node_chatqueries "https://github.com/code-with-antonio/ai-teammates/blob/main/queries/chats.ts"
click node_botqueries "https://github.com/code-with-antonio/ai-teammates/blob/main/queries/bots.ts"
click node_triggerchat "https://github.com/code-with-antonio/ai-teammates/blob/main/trigger/chat.ts"
click node_sandboxtools "https://github.com/code-with-antonio/ai-teammates/blob/main/lib/sandbox-tools.ts"
click node_daytona "https://github.com/code-with-antonio/ai-teammates/blob/main/lib/daytona.ts"
click node_handoff "https://github.com/code-with-antonio/ai-teammates/blob/main/lib/handoff-tool.ts"
click node_model "https://github.com/code-with-antonio/ai-teammates/blob/main/lib/model.ts"
click node_usagepage "https://github.com/code-with-antonio/ai-teammates/blob/main/app/(dashboard)/usage/page.tsx"
click node_paywall "https://github.com/code-with-antonio/ai-teammates/blob/main/hooks/use-paywall.ts"
click node_usageactions "https://github.com/code-with-antonio/ai-teammates/blob/main/actions/usage.ts"
click node_usage "https://github.com/code-with-antonio/ai-teammates/blob/main/lib/usage.ts"
click node_billing "https://github.com/code-with-antonio/ai-teammates/blob/main/lib/billing.ts"
click node_schema "https://github.com/code-with-antonio/ai-teammates/blob/main/db/schema.ts"
click node_database "https://github.com/code-with-antonio/ai-teammates/blob/main/db/index.ts"
click node_desktop "https://github.com/code-with-antonio/ai-teammates/blob/main/components/desktop-panel.tsx"
click node_pricing "https://github.com/code-with-antonio/ai-teammates/blob/main/app/(dashboard)/pricing/page.tsx"

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_dashboard,node_chatpage,node_chatui,node_chatparts,node_prompt,node_desktop,node_user toneBlue
class node_chatactions,node_triggerchat,node_handoff,node_model toneAmber
class node_botdialog,node_botactions,node_sandboxtools,node_daytona toneMint
class node_usagepage,node_paywall,node_usageactions,node_usage,node_billing,node_pricing toneRose
class node_chatqueries,node_botqueries,node_schema,node_database toneIndigo
```

## Components

### User experience

- [Dashboard](https://github.com/code-with-antonio/ai-teammates/blob/main/app/(dashboard)/page.tsx): `app/(dashboard)/page.tsx`
- [Chat page](https://github.com/code-with-antonio/ai-teammates/blob/main/app/(dashboard)/chats/%5BchatId%5D/page.tsx): `app/(dashboard)/chats/[chatId]/page.tsx`
- [Chat interface](https://github.com/code-with-antonio/ai-teammates/blob/main/components/chat.tsx): `components/chat.tsx`
- [Message components](https://github.com/code-with-antonio/ai-teammates/blob/main/components/ai-elements/message.tsx): `components/ai-elements/message.tsx`
- [Prompt input](https://github.com/code-with-antonio/ai-teammates/blob/main/components/ai-elements/prompt-input.tsx): `components/ai-elements/prompt-input.tsx`
- [Desktop panel](https://github.com/code-with-antonio/ai-teammates/blob/main/components/desktop-panel.tsx): `components/desktop-panel.tsx`

### Chat runtime

- [Chat actions](https://github.com/code-with-antonio/ai-teammates/blob/main/actions/chat.ts): `actions/chat.ts`
- [Chat orchestration](https://github.com/code-with-antonio/ai-teammates/blob/main/trigger/chat.ts): `trigger/chat.ts`
- [Bot handoff](https://github.com/code-with-antonio/ai-teammates/blob/main/lib/handoff-tool.ts): `lib/handoff-tool.ts`
- [Chat model](https://github.com/code-with-antonio/ai-teammates/blob/main/lib/model.ts): `lib/model.ts`

### Bots and sandboxes

- [Bot editor](https://github.com/code-with-antonio/ai-teammates/blob/main/components/bot-dialog.tsx): `components/bot-dialog.tsx`
- [Bot actions](https://github.com/code-with-antonio/ai-teammates/blob/main/actions/bot.ts): `actions/bot.ts`
- [Sandbox tools](https://github.com/code-with-antonio/ai-teammates/blob/main/lib/sandbox-tools.ts): `lib/sandbox-tools.ts`
- [Sandbox service](https://github.com/code-with-antonio/ai-teammates/blob/main/lib/daytona.ts): `lib/daytona.ts`

### Billing and usage

- [Usage page](https://github.com/code-with-antonio/ai-teammates/blob/main/app/(dashboard)/usage/page.tsx): `app/(dashboard)/usage/page.tsx`
- [Paywall hook](https://github.com/code-with-antonio/ai-teammates/blob/main/hooks/use-paywall.ts): `hooks/use-paywall.ts`
- [Usage actions](https://github.com/code-with-antonio/ai-teammates/blob/main/actions/usage.ts): `actions/usage.ts`
- [Usage ledger logic](https://github.com/code-with-antonio/ai-teammates/blob/main/lib/usage.ts): `lib/usage.ts`
- [Billing rules](https://github.com/code-with-antonio/ai-teammates/blob/main/lib/billing.ts): `lib/billing.ts`
- [Pricing page](https://github.com/code-with-antonio/ai-teammates/blob/main/app/(dashboard)/pricing/page.tsx): `app/(dashboard)/pricing/page.tsx`

### Persistence

- [Chat queries](https://github.com/code-with-antonio/ai-teammates/blob/main/queries/chats.ts): `queries/chats.ts`
- [Bot queries](https://github.com/code-with-antonio/ai-teammates/blob/main/queries/bots.ts): `queries/bots.ts`
- [Application schema](https://github.com/code-with-antonio/ai-teammates/blob/main/db/schema.ts): `db/schema.ts`
- [Postgres database](https://github.com/code-with-antonio/ai-teammates/blob/main/db/index.ts): `db/index.ts`

### Other components

- **User**

## Connections

- User → Dashboard: opens (evidence: `app/(dashboard)/page.tsx`)
- User → Chat page: opens (evidence: `app/(dashboard)/chats/[chatId]/page.tsx`)
- Chat page → Chat interface: renders (evidence: `app/(dashboard)/chats/[chatId]/page.tsx`)
- Chat interface → Prompt input: renders (evidence: `components/chat.tsx`)
- Chat interface → Message components: renders (evidence: `components/chat.tsx`)
- Chat interface → Chat actions: starts sessions (evidence: `components/chat.tsx`)
- Chat interface → Chat orchestration: loads transcript (evidence: `components/chat.tsx`)
- Dashboard → Bot editor: opens editor (evidence: `app/(dashboard)/page.tsx`)
- Bot editor → Bot actions: submits bot (evidence: `components/bot-dialog.tsx`)
- Chat actions → Chat queries: loads chat (evidence: `actions/chat.ts`)
- Chat actions → Chat orchestration: starts session (evidence: `actions/chat.ts`)
- Chat orchestration → Sandbox tools: provides tools (evidence: `trigger/chat.ts`)
- Chat orchestration → Chat model: streams model (evidence: `trigger/chat.ts`)
- Chat orchestration → Usage ledger logic: checks and records (evidence: `trigger/chat.ts`)
- Sandbox tools → Sandbox service: gets sandbox (evidence: `lib/sandbox-tools.ts`)
- Sandbox tools → Bot handoff: uses handoff types (evidence: `lib/sandbox-tools.ts`)
- Chat actions → Sandbox service: opens desktop (evidence: `actions/chat.ts`)
- Chat page → Desktop panel: renders (evidence: `app/(dashboard)/chats/[chatId]/page.tsx`)
- Bot actions → Sandbox service: manages sandbox (evidence: `actions/bot.ts`)
- Bot actions → Usage ledger logic: checks usage (evidence: `actions/bot.ts`)
- Bot actions → Postgres database: persists bot (evidence: `actions/bot.ts`)
- Chat actions → Postgres database: updates chats (evidence: `actions/chat.ts`)
- Chat queries → Postgres database: reads chats (evidence: `queries/chats.ts`)
- Bot queries → Postgres database: reads bots (evidence: `queries/bots.ts`)
- Postgres database → Application schema: uses schema (evidence: `db/index.ts`)
- Usage page → Usage ledger logic: gets usage (evidence: `app/(dashboard)/usage/page.tsx`)
- Paywall hook → Usage actions: checks allowance (evidence: `hooks/use-paywall.ts`)
- Usage actions → Usage ledger logic: checks usage
- Usage ledger logic → Postgres database: reads and writes ledger (evidence: `lib/usage.ts`)
- Usage ledger logic → Billing rules: checks subscription (evidence: `lib/usage.ts`)
- Paywall hook → Billing rules: checks plan (evidence: `hooks/use-paywall.ts`)
- User → Pricing page: views plans
- Chat orchestration → Postgres database: loads chat data (evidence: `trigger/chat.ts`)
