Skip to content

Folders and files

NameName
Last commit message
Last commit date

Latest commit

Β 

History

4 Commits
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 

Repository files navigation

🧭 ArchFlow

Real-Time Collaborative System Design Workspace, Powered by AI

nextdotjs typescript tailwindcss clerk liveblocks prisma trigger.dev gemini vercel

ArchFlow is a full-stack, real-time collaborative workspace for system design β€” describe a system in plain English, let an AI agent draft it as a live architecture diagram, refine it together with your team, and export the final graph as a technical specification.


πŸ“‹ Table of Contents

  1. Overview
  2. Tech Stack
  3. Key Features
  4. How the AI Pipeline Works
  5. Architecture Highlights
  6. Project Structure
  7. Getting Started
  8. Environment Variables
  9. Future Improvements

πŸ€– Overview

ArchFlow turns a blank canvas into a shared architecture whiteboard with an AI co-designer sitting inside it. Instead of dragging boxes and arrows one by one, a user can describe a system β€” "an event-driven order pipeline with a queue and three consumers" β€” and the AI agent writes real nodes and edges directly into a shared, live canvas that every collaborator sees update in real time.

Two AI-driven capabilities sit at the core of the app:

  • Design Generation β€” turn a natural-language prompt (plus the current canvas state) into structured architecture nodes and edges, written live into the shared room
  • Spec Generation β€” turn the finished canvas graph into a persisted Markdown technical specification, ready to review or download

Everything else β€” auth, project ownership, collaborator access, a curated starter-template library, and live multiplayer presence β€” exists to support that core loop: describe it, watch it get drawn, refine it together, export it.

Built with Next.js (App Router) and backed by Clerk (auth), Prisma + PostgreSQL (metadata), Liveblocks + React Flow (real-time canvas), Trigger.dev (durable AI background jobs), Vercel Blob (generated artifacts), and Google Gemini through the Vercel AI SDK for all generation.


βš™οΈ Tech Stack

Layer Technology Purpose
Framework Next.js 16 (App Router) SSR, routing, API route handlers
Language TypeScript End-to-end type safety
Auth Clerk User identity, sign-in/sign-up, route protection
Database Prisma + PostgreSQL Project metadata, collaborators, spec records, task runs
Real-Time Canvas Liveblocks + React Flow (@xyflow/react) Shared canvas state, live cursors, presence, node/edge sync
Background Jobs Trigger.dev Durable, long-running AI generation tasks
Artifact Storage Vercel Blob Canvas snapshots and generated Markdown specs
AI Google Gemini (via Vercel AI SDK) Architecture generation and spec generation
Styling Tailwind CSS + shadcn/ui + Base UI Utility-first styles + accessible component primitives
Deployment Vercel Hosting for the app and API routes

πŸ”‹ Key Features

πŸ—‚οΈ Projects & Collaboration

  • Clerk Authentication β€” Full sign-in/sign-up flow with protected routes
  • Project Ownership β€” Every project belongs to a single owner, with additional collaborators invited by email
  • Access-Controlled Rooms β€” Liveblocks room tokens are only issued after verifying project membership; non-members hit an access-denied state
  • Project Sidebar & Share Dialog β€” Manage collaborators and project settings without leaving the workspace

πŸ–ΌοΈ Real-Time Collaborative Canvas

  • Shared Canvas β€” Built on Liveblocks + React Flow; every node, edge, and edit syncs live across all connected collaborators
  • Live Presence β€” Real-time cursors and collaborator avatars show who's editing and where
  • Rich Node Editing β€” Shape panel, color toolbar, inline label editing, and configurable node/edge behavior
  • Canvas Autosave β€” Canvas state is snapshotted and persisted automatically as it changes
  • Starter Template Library β€” Prebuilt system-design templates (monolith, microservices, event-driven, CI/CD pipeline, serverless, and more) that can be imported into the canvas at any point, following the same node/edge schema as user-created content

πŸ€– AI-Powered Architecture Generation

  • Prompt-to-Diagram β€” Describe a system in plain English; the AI agent generates structured nodes and edges and writes them directly into the shared room
  • Context-Aware β€” Generation takes the current canvas state and project context into account, so the AI extends existing designs rather than overwriting them
  • AI Sidebar β€” A dedicated chat-style panel for prompting the design agent and reviewing its running feed of actions
  • Durable Execution β€” Generation runs as a background task via Trigger.dev, so it survives page navigation and doesn't block API requests

πŸ“„ Spec Generation & Export

  • Graph-to-Markdown β€” Converts the current canvas graph and chat history into a structured Markdown technical specification
  • Persisted Artifacts β€” Specs are saved to Vercel Blob and linked to the project via a database record, with full history per project
  • Review & Download β€” Users can view generated specs in-app or download them directly

🧠 How the AI Pipeline Works

User enters a prompt in the AI sidebar
      β”‚
      β–Ό
POST /api/ai/design β†’ ownership/auth check β†’ Trigger.dev task queued
      β”‚
      β–Ό
design-agent.ts (Trigger.dev background task)
      β”‚
      β”œβ”€ Reads current canvas state (nodes, edges) + project context
      β”œβ”€ Calls Google Gemini via the Vercel AI SDK
      └─ Produces structured node/edge updates
      β”‚
      β–Ό
Updates written directly into the shared Liveblocks room
      β”‚
      β–Ό
All connected collaborators see the diagram update live β€” no refresh
─────────────────────────────────────────────
User triggers "Generate Spec"
      β”‚
      β–Ό
POST /api/projects/[projectId]/specs β†’ Trigger.dev task queued
      β”‚
      β–Ό
generate-spec.ts (Trigger.dev background task)
      β”‚
      β”œβ”€ Builds context from canvas nodes, edges, and AI chat history
      β”œβ”€ Calls Google Gemini to draft a Markdown technical spec
      └─ Uploads the result to Vercel Blob (specs/{projectId}/{specId}.md)
      β”‚
      β–Ό
ProjectSpec record saved to PostgreSQL, linked to the project
      β”‚
      β–Ό
User views or downloads the spec from the workspace

All AI generation runs as Trigger.dev background tasks, not inline in request handlers β€” API routes only validate, authorize, and queue work, keeping long-running model calls off the request/response cycle.


πŸ—οΈ Architecture Highlights

  • Request Handlers vs. Background Tasks β€” app/api handles auth, validation, and task triggering only; all long-running AI work lives in trigger/, kept off the request/response cycle
  • Two-Layer Storage Model β€” Relational metadata (projects, collaborators, spec records, task runs) lives in PostgreSQL via Prisma; large generated artifacts (canvas snapshots, Markdown specs) live in Vercel Blob, referenced from the database by URL
  • Ownership Enforced at Every Mutation β€” Every project has a single owner, with collaborator access checked before any Liveblocks room token is issued or any resource is mutated
  • Schema-Consistent Templates β€” Starter system-design templates are static canvas snapshots that follow the exact same node/edge schema as user-created content, so they can be imported without a separate database record
  • Protected Foundation Components β€” components/ui/* (shadcn/ui primitives) remain untouched defaults; feature and layout logic lives in app-level components instead

πŸ“ Project Structure

ArchFlow/
β”‚
β”œβ”€β”€ app/
β”‚   β”œβ”€β”€ api/
β”‚   β”‚   β”œβ”€β”€ ai/
β”‚   β”‚   β”‚   β”œβ”€β”€ design/route.ts + token/route.ts    # Trigger AI design generation
β”‚   β”‚   β”‚   └── spec/route.ts + token/route.ts      # Trigger AI spec generation
β”‚   β”‚   β”œβ”€β”€ projects/
β”‚   β”‚   β”‚   β”œβ”€β”€ route.ts                            # Project list/create
β”‚   β”‚   β”‚   └── [projectId]/
β”‚   β”‚   β”‚       β”œβ”€β”€ route.ts                        # Project detail/update/delete
β”‚   β”‚   β”‚       β”œβ”€β”€ canvas/route.ts                 # Canvas snapshot persistence
β”‚   β”‚   β”‚       β”œβ”€β”€ collaborators/route.ts          # Collaborator management
β”‚   β”‚   β”‚       └── specs/                          # Spec list, detail, download
β”‚   β”‚   └── liveblocks-auth/route.ts                 # Room token issuance
β”‚   β”‚
β”‚   β”œβ”€β”€ editor/
β”‚   β”‚   β”œβ”€β”€ page.tsx                                 # Project home
β”‚   β”‚   └── [roomId]/page.tsx                        # Collaborative canvas workspace
β”‚   β”‚
β”‚   β”œβ”€β”€ sign-in/[[...sign-in]]/page.tsx
β”‚   β”œβ”€β”€ sign-up/[[...sign-up]]/page.tsx
β”‚   β”œβ”€β”€ globals.css
β”‚   └── layout.tsx
β”‚
β”œβ”€β”€ components/
β”‚   β”œβ”€β”€ editor/
β”‚   β”‚   β”œβ”€β”€ canvas/
β”‚   β”‚   β”‚   β”œβ”€β”€ canvas-editor.tsx        # Canvas root
β”‚   β”‚   β”‚   β”œβ”€β”€ canvas-room.tsx          # Liveblocks room provider
β”‚   β”‚   β”‚   β”œβ”€β”€ canvas-node.tsx / canvas-edge.tsx
β”‚   β”‚   β”‚   β”œβ”€β”€ canvas-controls.tsx / shape-panel.tsx
β”‚   β”‚   β”‚   β”œβ”€β”€ presence-cursors.tsx / collaborator-avatars.tsx
β”‚   β”‚   β”œβ”€β”€ ai-sidebar.tsx               # AI prompt + chat feed
β”‚   β”‚   β”œβ”€β”€ editor-workspace-client.tsx / editor-navbar.tsx
β”‚   β”‚   β”œβ”€β”€ editor-home-client.tsx / project-sidebar.tsx
β”‚   β”‚   β”œβ”€β”€ project-dialogs.tsx / project-share-dialog.tsx
β”‚   β”‚   β”œβ”€β”€ starter-templates.ts / starter-templates-modal.tsx
β”‚   β”‚   └── access-denied.tsx
β”‚   └── ui/                              # shadcn/ui primitives
β”‚
β”œβ”€β”€ trigger/
β”‚   β”œβ”€β”€ design-agent.ts                  # AI architecture generation task
β”‚   └── generate-spec.ts                 # AI Markdown spec generation task
β”‚
β”œβ”€β”€ lib/
β”‚   β”œβ”€β”€ prisma.ts                        # Prisma client
β”‚   β”œβ”€β”€ liveblocks.ts                    # Liveblocks server client
β”‚   β”œβ”€β”€ projects.ts / project-access.ts / project-collaborators.ts
β”‚   └── utils.ts
β”‚
β”œβ”€β”€ prisma/
β”‚   β”œβ”€β”€ schema.prisma
β”‚   β”œβ”€β”€ models/project.prisma            # Project, ProjectSpec, ProjectCollaborator, TaskRun
β”‚   └── migrations/
β”‚
β”œβ”€β”€ hooks/
β”‚   β”œβ”€β”€ use-canvas-autosave.ts
β”‚   β”œβ”€β”€ use-project-actions.ts / use-project-dialogs.ts / use-project-share.ts
β”‚   └── useKeyboardShortcuts.ts
β”‚
β”œβ”€β”€ types/
β”‚   β”œβ”€β”€ canvas.ts
β”‚   └── tasks.ts
β”‚
β”œβ”€β”€ liveblocks.config.ts
β”œβ”€β”€ trigger.config.ts
└── prisma.config.ts

πŸš€ Getting Started

Prerequisites

1. Clone

git clone https://github.com/<your-username>/ArchFlow.git
cd ArchFlow

2. Install

npm install

postinstall runs prisma generate automatically.

3. Environment Variables

Create .env in the project root (see Environment Variables below).

4. Set Up the Database

npx prisma migrate deploy

5. Run

npm run dev

Open http://localhost:3000.

To run AI background tasks locally, also start the Trigger.dev dev server:

npx trigger.dev@latest dev

πŸ” Environment Variables

Variable Description
DATABASE_URL PostgreSQL connection string
NEXT_PUBLIC_CLERK_PUBLISHABLE_KEY Clerk publishable key
CLERK_SECRET_KEY Clerk secret key
LIVEBLOCKS_SECRET_KEY Liveblocks server secret key
TRIGGER_SECRET_KEY Trigger.dev project secret key
BLOB_READ_WRITE_TOKEN Vercel Blob read/write token
GOOGLE_GENERATIVE_AI_API_KEY Gemini API key for AI generation

Exact variable names may differ slightly by provider version β€” check lib/prisma.ts, lib/liveblocks.ts, and the trigger/ tasks for the values actually read at runtime if you're wiring up a fresh environment.


πŸ”­ Future Improvements

  • Versioned spec history with diffing between generations
  • Role-based collaborator permissions (view-only vs. edit)
  • Richer AI-sidebar chat feed with inline diff previews before writing to canvas
  • Migrating starter templates to database-backed, user-editable template library
  • Export formats beyond Markdown (PDF, diagrams-as-code)

Built with Next.js Β· Clerk Β· Liveblocks Β· Prisma Β· Trigger.dev Β· Gemini Β· Tailwind CSS

About

Real-time collaborative system-design canvas with AI-generated architecture diagrams and specs. Built with Next.js, Liveblocks & React Flow.

Topics

Resources

Stars

Watchers

Forks

Releases

Packages

Contributors

Languages