Skip to content
MuqeetullahPublic

About

Ghost AI is a real-time collaborative system design workspace. Users can describe a software architecture in plain English, have AI generate an initial canvas of nodes and connections, then collaborate with others to refine the design. The final architecture can be converted into a persistent Markdown technical specification.

Topics

Resources

Stars

2 stars

Watchers

0 watching

Forks

Latest commit

 

History

33 Commits

Folders and files

NameName
Last commit message
Last commit date
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Ghost AI

AI-assisted system design workspace for collaborative architecture planning and technical specification generation.

Next.js React TypeScript Prisma Trigger.dev

Ghost AI turns natural-language architecture prompts into editable system design diagrams, keeps collaborators synchronized in real time, and generates polished Markdown technical specifications from the final canvas. It is built as a full-stack Next.js workspace with authenticated project management, Liveblocks-powered multiplayer state, durable Trigger.dev AI workflows, Prisma/PostgreSQL metadata, and Vercel Blob artifact storage.

Product Value

Ghost AI is designed for engineers, founders, and product teams who need to move quickly from a rough system idea to a concrete architecture artifact. Instead of keeping diagrams, AI chat, collaboration, and specs in separate tools, Ghost AI brings them into one shared workspace:

Capability Value
AI architecture generation Converts a prompt into structured React Flow nodes and edges on the canvas.
Multiplayer editing Lets teammates refine the same architecture with live cursors and presence.
Starter templates Speeds up common designs such as monoliths, microservices, serverless, event-driven systems, and CI/CD flows.
Spec generation Produces persistent Markdown technical specs from the current graph and project context.
Durable background work Keeps long-running AI tasks out of request handlers and observable through Trigger.dev runs.

Tech Stack

Layer Technology Purpose
Framework Next.js 16, React 19, TypeScript Full-stack application with Server Component-first routing.
Styling Tailwind CSS 4, shadcn/ui, Radix primitives, Lucide React Dark technical workspace UI with composable primitives.
Authentication Clerk Sign-in, route protection, user identity, and account UI.
Database Prisma 7, PostgreSQL, Prisma Accelerate/PG adapter Project metadata, collaborators, task runs, and generated spec records.
Realtime canvas Liveblocks, React Flow, @liveblocks/react-flow Shared canvas state, presence, cursors, and collaborative graph editing.
Background jobs Trigger.dev v4 Durable AI design generation, spec generation, run metadata, and local worker tooling.
AI AI SDK, Gemini 3.5 Flash-Lite Shared model for canvas tool calls and Markdown spec generation, configured in lib/ai-model.ts.
Artifact storage Vercel Blob Private canvas snapshots and generated Markdown specs.

Architecture Overview

flowchart LR
  User["Authenticated user"] --> Next["Next.js app router"]
  Next --> Clerk["Clerk auth"]
  Next --> API["Route handlers"]
  API --> Prisma["Prisma + PostgreSQL"]
  API --> Liveblocks["Liveblocks rooms"]
  API --> Trigger["Trigger.dev tasks"]
  Trigger --> Gemini["Google Gemini via AI SDK"]
  Trigger --> Liveblocks
  Trigger --> Blob["Vercel Blob"]
  Blob --> Prisma
  Liveblocks --> Canvas["React Flow collaborative canvas"]
  Prisma --> Next
Loading

The application keeps responsibilities intentionally separated:

Boundary Responsibility
app/ Next.js routes, authenticated pages, route handlers, and API entry points.
components/editor/ Workspace chrome, canvas UI, AI sidebar, project sidebar, modals, and editor controls.
components/ui/ shadcn/ui foundation primitives.
hooks/ Client-side interaction hooks such as autosave, keyboard shortcuts, and project actions.
lib/ Server infrastructure for Prisma, Liveblocks, project access, generated specs, feeds, and validation helpers.
trigger/ Durable Trigger.dev tasks for AI design generation, spec generation, and health checks.
types/ Shared contracts for canvas nodes, AI status events, projects, and task payloads.
prisma/ Prisma schema, model files, and migrations.
context/ Product, architecture, UI, standards, workflow, and progress documentation.

Features

Authenticated Project Workspace

  • Consistent dark sign-in and sign-up pages with a custom Ghost AI mark and local generated artwork.
  • Clerk-backed authentication and protected editor routes.
  • Profile access in the navbar, visible above the AI workspace.
  • Owned and shared project lists.
  • Project creation, rename, delete, and collaborator management.
  • Access checks enforced before every project mutation.

Real-Time Collaborative Canvas

  • Liveblocks room tokens issued only after project membership verification.
  • React Flow graph synchronized through Liveblocks storage.
  • Live cursors, participant avatars, presence metadata, and AI thinking state.
  • Node creation, resize, inline label editing, color selection, custom shapes, edge labels, undo/redo, zoom controls, and keyboard shortcuts.

Starter Architecture Templates

  • Static graph templates can be imported into any active workspace.
  • Templates share the same node and edge schema as user-created canvas content.
  • Current library covers common architecture patterns and can be extended without database changes.

AI Design Agent

  • POST /api/ai/design validates access, creates an idempotent Trigger.dev run, and persists the run ID.
  • trigger/design-agent.ts reads project context, interprets the prompt, generates canvas actions, and applies them into the Liveblocks room.
  • Your prompts and the agent's responses appear in the AI Architect conversation and survive reloads.
  • New submissions carry request IDs so retrying a prompt does not reuse a canceled or expired run.
  • AI activity is published through room events and status feeds.
  • When browser feed subscriptions time out, a membership-checked HTTP fallback reads the same saved Liveblocks messages. Feed failures do not take down the canvas.
  • Design generation has a 60-second model deadline; spec generation has a 30-second deadline.

AI Spec Generation

  • POST /api/ai/spec combines the current canvas snapshot with the saved conversation on the server before starting the Trigger.dev workflow.
  • trigger/generate-spec.ts generates a Markdown technical specification with Gemini Flash-Lite.
  • Specs are saved to private Vercel Blob storage and linked through Prisma metadata.
  • Successful generation opens the latest preview automatically. Authenticated users can preview and download Markdown specs.
  • Preview text wraps on narrow screens, with wide tables scrolling inside their own containers.

Key Technical Challenges Solved

Challenge Solution
Keeping AI work out of request handlers Long-running generation runs in Trigger.dev tasks, while API routes only validate, authorize, trigger, and persist metadata.
Synchronizing AI and human edits The design agent applies graph mutations directly to the Liveblocks-backed React Flow document, so generated changes appear in the same realtime state model as human edits.
Preventing duplicate AI runs Design generation uses Trigger.dev idempotency keys derived from project, user, room, prompt hash, and submission request ID.
Protecting collaborative rooms Liveblocks tokens are minted only after Clerk identity and project membership checks pass.
Separating metadata from large artifacts PostgreSQL stores ownership and references; Vercel Blob stores canvas snapshots and Markdown specs.
Recovering from feed timeouts An authenticated HTTP fallback reads the existing Liveblocks chat and status feeds while the browser subscription is loading or unavailable.
Reducing slow AI spec runs Spec prompts trim chat history, compress canvas context, use a bounded model output budget, and fail fast with an AI SDK timeout.
Handling database connection modes Runtime Prisma connections normalize direct Prisma Postgres URLs to pooled hosts while CLI workflows can use direct URLs for migrations.

Folder Structure

ghost-ai/
|-- app/
|   |-- api/                         # Authenticated API routes
|   |-- editor/                      # Editor home and project workspace routes
|   |-- sign-in/                     # Clerk sign-in route
|   |-- sign-up/                     # Clerk sign-up route
|   |-- globals.css                  # Dark theme tokens and Tailwind mapping
|   `-- layout.tsx                   # Root app shell and providers
|-- components/
|   |-- auth/                        # Authentication layout composition
|   |-- brand/                       # Shared Ghost AI logo
|   |-- editor/                      # Canvas, sidebar, navbar, dialogs, workspace UI
|   `-- ui/                          # shadcn/ui primitives
|-- context/                         # Product and engineering context docs
|-- generated/prisma/                # Generated Prisma client output
|-- hooks/                           # Client interaction hooks
|-- lib/                             # Server utilities, access control, Prisma, Liveblocks
|-- prisma/
|   |-- migrations/                  # Database migrations
|   |-- models/                      # Prisma model definitions
|   `-- schema.prisma                # Prisma schema entry
|-- public/images/                   # Local authentication artwork
|-- tests/                           # Conversation and canvas regression tests
|-- trigger/                         # Trigger.dev v4 tasks
|-- types/                           # Shared TypeScript contracts
|-- liveblocks.config.ts             # Liveblocks type augmentation
|-- trigger.config.ts                # Trigger.dev deployment configuration
`-- prisma.config.ts                 # Prisma CLI configuration

Getting Started

Prerequisites

  • Node.js 22 or newer
  • npm
  • PostgreSQL or Prisma Postgres
  • Clerk application
  • Liveblocks project
  • Trigger.dev project
  • Google AI API key
  • Vercel Blob token for private artifact storage

Installation

git clone https://github.com/Muqeetullah/ghost-ai.git
cd ghost-ai
npm install

Create a local environment file:

touch .env.local

Populate .env.local using the environment variable table below. Never commit API keys or database credentials.

Generate the Prisma client and apply migrations. The Prisma CLI uses dotenv/config, so point it at the same local environment file:

DOTENV_CONFIG_PATH=.env.local npx prisma generate
DOTENV_CONFIG_PATH=.env.local npx prisma migrate deploy

Start the Next.js app:

npm run dev

Start the Trigger.dev worker in a second terminal:

npm run trigger:dev

Open http://localhost:3000. Both processes must stay running for local AI generation. A running Next.js server alone can queue tasks, but it cannot execute the AI worker.

To use port 3100 instead:

npm run dev -- --port 3100

The Gemini model is pinned in lib/ai-model.ts. A model with a free tier still requires a Google API project on the Free tier to avoid inference charges, and quotas apply. The app does not enable billing or automatically switch to a paid model.

Environment Variables

Variable Required Purpose
DATABASE_URL Yes Runtime database connection. Use a pooled Prisma Postgres URL when possible.
DIRECT_URL Recommended Direct database connection for Prisma migrations and admin operations.
DIRECT_DATABASE_URL Optional Alternate direct database URL used by prisma.config.ts when DIRECT_URL is absent.
NEXT_PUBLIC_CLERK_PUBLISHABLE_KEY Yes Clerk public browser key.
CLERK_SECRET_KEY Yes Clerk server secret key.
NEXT_PUBLIC_CLERK_SIGN_IN_URL Recommended Local sign-in route, usually /sign-in.
NEXT_PUBLIC_CLERK_SIGN_UP_URL Recommended Local sign-up route, usually /sign-up.
NEXT_PUBLIC_CLERK_SIGN_IN_FALLBACK_REDIRECT_URL Recommended Post-auth redirect, usually /editor.
NEXT_PUBLIC_CLERK_SIGN_UP_FALLBACK_REDIRECT_URL Recommended Post-sign-up redirect, usually /editor.
LIVEBLOCKS_SECRET_KEY Yes Server key for room creation, auth token issuance, presence, and room mutation.
TRIGGER_PROJECT_REF Yes Trigger.dev project reference used by trigger.config.ts.
TRIGGER_SECRET_KEY Yes Trigger.dev secret key for local and deployed workers.
GOOGLE_AI_API_KEY Yes Google AI API key for Gemini 3.5 Flash-Lite design and spec generation. Use a Free tier API project to avoid inference charges; free quotas apply.
BLOB_READ_WRITE_TOKEN Yes Vercel Blob read/write token for private canvas and spec artifacts.

Example database configuration for Prisma Postgres:

DATABASE_URL="postgres://USER:PASSWORD@pooled.db.prisma.io:5432/postgres?sslmode=require"
DIRECT_URL="postgres://USER:PASSWORD@db.prisma.io:5432/postgres?sslmode=require"

Scripts

Command Description
npm run dev Start the Next.js development server.
npm run build Create a production build.
npm run start Run the production server after a build.
npm run lint Run ESLint.
npm test Run conversation, spec-context, and canvas feed-failure regression tests without network access.
npm run trigger:dev Start the Trigger.dev local worker with .env.local.
npm run trigger:deploy Deploy Trigger.dev tasks.
npx prisma generate Generate the Prisma client in generated/prisma.
npx prisma migrate deploy Apply committed migrations to the configured database.

API Integration

Route Method Responsibility
/api/projects GET List owned and shared projects for the authenticated user.
/api/projects POST Create a new project.
/api/projects/[projectId] PATCH Rename or update a project owned by the user.
/api/projects/[projectId] DELETE Delete an owned project.
/api/projects/[projectId]/collaborators GET List project collaborators.
/api/projects/[projectId]/collaborators POST Invite a collaborator by email.
/api/projects/[projectId]/collaborators/[collaboratorId] DELETE Remove a collaborator.
/api/liveblocks-auth POST Verify project access and issue a Liveblocks room token.
/api/projects/[projectId]/ai-feed GET Read an allowed AI chat or status feed after checking project membership.
/api/projects/[projectId]/canvas GET Load the saved canvas snapshot from Vercel Blob.
/api/projects/[projectId]/canvas PUT Persist the latest canvas snapshot to Vercel Blob.
/api/ai/design POST Trigger the durable AI design-agent workflow.
/api/ai/design/token POST Issue a Trigger.dev public token scoped to a stored design run.
/api/ai/spec POST Trigger Markdown spec generation from the current canvas.
/api/ai/spec/token POST Issue a Trigger.dev public token scoped to a stored spec run.
/api/projects/[projectId]/specs GET List generated project specs.
/api/projects/[projectId]/specs/[specId] GET Preview a generated Markdown spec.
/api/projects/[projectId]/specs/[specId]/download GET Download a generated Markdown spec.

Data Model

The core relational model is intentionally small:

Model Description
Project Owned architecture workspace with optional canvas snapshot reference.
ProjectCollaborator Email-based collaborator access for a project.
TaskRun Stored Trigger.dev run IDs tied to project and user ownership.
ProjectSpec Metadata reference to a generated Markdown spec stored in Vercel Blob.

Canvas nodes, edges, and generated Markdown content are not stored directly in relational rows. Large artifacts live in Vercel Blob and are referenced by URL from Prisma records.

Performance Optimizations

  • Server Component-first routing keeps client JavaScript scoped to interactive editor surfaces.
  • Debounced canvas autosave limits artifact writes while preserving explicit manual save controls.
  • Liveblocks synchronizes collaborative graph state and presence in real time. AI feed reads fall back to polling every three seconds only while the browser subscription is loading or has failed.
  • Trigger.dev moves AI generation out of request-response latency paths.
  • Spec generation trims chat history, filters repetitive assistant status messages, limits prompt size, and caps model output.
  • Prisma client is cached in development to avoid connection churn during hot reloads.
  • Runtime database URLs are normalized toward pooled Prisma Postgres hosts for application traffic.
  • Generated specs and canvas snapshots are stored as Blob artifacts instead of inflating relational tables.

Deployment

Vercel App

  1. Create a Vercel project connected to this repository.
  2. Configure all required environment variables.
  3. Apply database migrations:
npx prisma migrate deploy
  1. Build and deploy the app:
npm run build

Trigger.dev Workers

Deploy durable tasks after environment variables are configured:

npm run trigger:deploy

Trigger.dev production and staging schedules/runs execute against the latest deployed worker version.

Production Checklist

  • Clerk production instance and allowed redirect URLs are configured.
  • Liveblocks production project secret is set.
  • Trigger.dev project reference and secret key are set.
  • Google AI key is scoped and rotated according to team policy.
  • Vercel Blob token is available in the deployment environment.
  • Database migrations are deployed before routing production traffic.

Troubleshooting

Symptom What to check
AI request stays queued or expires Keep npm run trigger:dev running alongside Next.js. Confirm the worker reports ready and uses the same Trigger.dev project and environment as the app.
AI generation times out or hits quota Check the run error in Trigger.dev and the Gemini project's quota. Ensure GOOGLE_AI_API_KEY is available to the worker.
Conversation or AI status is unavailable The HTTP fallback reads saved messages automatically. If it also fails, check LIVEBLOCKS_SECRET_KEY, project membership, and the /ai-feed response.
Generated spec cannot be previewed or downloaded Check the Trigger.dev run, database connectivity, and BLOB_READ_WRITE_TOKEN in both the app and worker environments.

Future Improvements

  • Role-based permissions beyond owner and collaborator.
  • Versioned spec history with review and approval workflows.
  • First-class diagram export to PNG, SVG, and PDF.
  • Template marketplace or organization-scoped starter libraries.
  • Observability dashboard for Trigger.dev task latency, AI usage, and failure rates.
  • Automated end-to-end tests for authenticated canvas and spec generation flows.
  • Fine-grained project activity audit log.
  • Object lifecycle policies for archived canvas snapshots and specs.

Contributing

Contributions should preserve the system boundaries documented in context/architecture-context.md and the implementation rules in context/code-standards.md.

  1. Create a focused branch.
  2. Read the relevant files in context/ before changing behavior.
  3. Keep route handlers thin and move long-running work to Trigger.dev tasks.
  4. Validate external input at API and task boundaries.
  5. Run verification before opening a pull request:
npm run lint
npm test
npx tsc --noEmit
npm run build

For UI work, follow the dark-only token system in app/globals.css and reuse components/ui/ primitives rather than modifying generated foundation components.

License

License information has not been added yet. Add a LICENSE file before publishing this repository publicly.

About

Ghost AI is a real-time collaborative system design workspace. Users can describe a software architecture in plain English, have AI generate an initial canvas of nodes and connections, then collaborate with others to refine the design. The final architecture can be converted into a persistent Markdown technical specification.

Topics

Resources

Stars

2 stars

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages