# haydenbleasel/tersa architecture

> Architecture diagram of the GitHub repository haydenbleasel/tersa, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2025-05-16). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/haydenbleasel/tersa
- Repository: https://github.com/haydenbleasel/tersa

## Overview

##### Project type and purpose
- This is a full-stack web application (“Tersa”) for visually building and running AI workflows.
- Frontend: Next.js App Router with React, Tailwind CSS, ReactFlow canvas, TipTap editor, shadcn/Kibo UI components.
- Backend: Next.js server actions and API routes, Drizzle ORM, Supabase (Auth, Storage, Postgres, RLS), Stripe, Posthog, Vercel AI SDK integrations.

##### File structure
- app/
- app/(unauthenticated) → public landing, home, pricing, A-U pages, header/footer
- app/(authenticated) → workspace pages, project listing, per-project canvas
- app/api/ → serverless routes for chat, checkout, code, portal, webhooks
- app/actions/ → Next.js Server Actions for project CRUD, media processing (image/speech/video), feedback, credits
- app/auth/ → authentication pages and routes (login, sign-up, forgot/update password, OAuth)
- components/ → client UI elements (canvas, nodes, edges, toolbar, general UI primitives)
- lib/ → shared utilities (auth, env, error handling, database setup, Supabase client/middleware/server, Drizzle config, AI model helpers)
- providers/ → React Context providers (theme, analytics, subscription, project state, Posthog)
- emails/ → email templates for sign-in, sign-up, password reset
- supabase/ + drizzle.config.ts + schema.ts → DB schema and local Supabase setup
- next.config.ts, middleware.ts → Next.js configuration, route middleware
- public/ → static assets (demo media, opengraph image)

##### README insights
- Emphasizes drag-and-drop canvas, automatic saving to Supabase, multi-modal AI model integrations via Vercel AI SDK, ReactFlow for visual graph.
- Lists primary technologies and integration points: Next.js 15, React 19, Supabase, Drizzle ORM, Stripe, Posthog, Tailwind, shadcn/Kibo/Radix UI.

## Diagram (Mermaid)

```mermaid
graph TD
  %% Frontend Layer
  subgraph "Frontend (Browser)"
    direction TB
    PublicUI["Public UI (Marketing & Landing Pages)"]:::frontend
    AuthWorkspace["Authenticated Workspace & Canvas"]:::frontend
    ReactFlowCanvas["ReactFlow Canvas & Node Components"]:::frontend
    UIPrimitives["UI Primitives & Component Library"]:::frontend
    ContextProviders["React Context Providers"]:::frontend
  end

  %% Server & Business Logic
  subgraph "Server Layer (Next.js on Vercel)"
    direction TB
    MiddlewareGlobal["Global Routing Middleware"]:::server
    MiddlewareSupabase["Supabase Auth Middleware"]:::server
    ServerActions["Server Actions (app/actions)"]:::server
    APIRoutes["API Routes (app/api)"]:::server
  end

  %% Database Layer
  subgraph "Database Layer"
    direction TB
    Postgres["Supabase Postgres DB (with RLS)"]:::db
    Drizzle["Drizzle ORM (schema & config)"]:::db
  end

  %% External Services
  subgraph "External Services"
    direction TB
    SupabaseAuth["Supabase Auth & Storage"]:::external
    VercelAI["Vercel AI SDK"]:::external
    StripeSvc["Stripe (Checkout & Webhooks)"]:::external
    PosthogSvc["Posthog Analytics"]:::external
    EmailSvc["Email Provider (Resend)"]:::external
  end

  %% Connections
  PublicUI -->|"navigates pages"| MiddlewareGlobal
  AuthWorkspace -->|"/projects"| MiddlewareGlobal
  MiddlewareGlobal --> MiddlewareSupabase
  MiddlewareSupabase --> ServerActions
  MiddlewareSupabase --> APIRoutes

  ReactFlowCanvas -->|uses actions| ServerActions
  ContextProviders --> PublicUI
  ContextProviders --> AuthWorkspace
  ContextProviders --> ReactFlowCanvas

  ServerActions -->|CRUD & AI nodes| Drizzle
  ServerActions -->|DB queries| Postgres
  ServerActions -->|calls| VercelAI
  ServerActions -->|stores media| SupabaseAuth

  APIRoutes -->|chat & code| VercelAI
  APIRoutes -->|checkout| StripeSvc
  APIRoutes -->|webhooks| StripeSvc
  APIRoutes -->|resend webhooks| EmailSvc
  APIRoutes -->|portal| StripeSvc

  Drizzle -->|maps to| Postgres

  SupabaseAuth --> Postgres
  VercelAI -->|model endpoints| VercelAI
  StripeSvc -->|billing events| Postgres
  EmailSvc -->|send emails| Postgres
  PosthogSvc -->|analytics| ContextProviders

  %% Click events
  click PublicUI "https://github.com/haydenbleasel/tersa/tree/main/app/(unauthenticated)"
  click AuthWorkspace "https://github.com/haydenbleasel/tersa/blob/main/app/(authenticated)/projects/[projectId]/page.tsx"
  click ServerActions "https://github.com/haydenbleasel/tersa/tree/main/app/actions"
  click APIRoutes "https://github.com/haydenbleasel/tersa/tree/main/app/api"
  click MiddlewareGlobal "https://github.com/haydenbleasel/tersa/blob/main/middleware.ts"
  click MiddlewareSupabase "https://github.com/haydenbleasel/tersa/blob/main/lib/supabase/middleware.ts"
  click Drizzle "https://github.com/haydenbleasel/tersa/blob/main/drizzle.config.ts"
  click Drizzle "https://github.com/haydenbleasel/tersa/blob/main/schema.ts"
  click SupabaseAuth "https://github.com/haydenbleasel/tersa/blob/main/supabase/config.toml"
  click UIPrimitives "https://github.com/haydenbleasel/tersa/tree/main/components/ui"
  click ReactFlowCanvas "https://github.com/haydenbleasel/tersa/blob/main/components/canvas/index.tsx"
  click ContextProviders "https://github.com/haydenbleasel/tersa/blob/main/providers/theme.tsx"
  click ContextProviders "https://github.com/haydenbleasel/tersa/blob/main/providers/subscription.tsx"
  click ContextProviders "https://github.com/haydenbleasel/tersa/blob/main/providers/project.tsx"

  %% Styles
  classDef frontend fill:#cce5ff,stroke:#3399ff,color:#000
  classDef server fill:#d4edda,stroke:#28a745,color:#000
  classDef db fill:#fff3cd,stroke:#ffc107,color:#000
  classDef external fill:#e2e3e5,stroke:#6f42c1,color:#000
```
