How khanhthanhdev/comai works
Main Components
A. Frontend Layer:
• Next.js Application (App Router)
• Main Application Routes (/app directory)
• Authentication Routes (sign-in, sign-up)
• Sharing Feature (/share/[id])
• Component Preview System (Sandpack integration)
B. Backend Layer:
• API Routes (/app/api)
• Component Generation Endpoints
• OpenGraph Image Generation
• Authentication System
• Database Layer (Prisma + PostgreSQL)
C. External Services:
• Claude AI Integration
• Sandpack Code Sandbox
• Authentication Provider (implied by auth routes)
[Client Layer]
• Next.js Frontend
• UI Components (/components)
• Main App Routes
• Auth Routes
• Share Routes
• ▼
[API Layer]
• Next.js API Routes
• /api/generateCode
• /api/generateNextjsCode
• /api/og
• ▼
[External Services]
• Claude AI
• Sandpack
• Auth Provider
• ▼
[Data Layer]
• Prisma ORM ─► PostgreSQL Database
Important Elements to Highlight
A. Architecture Patterns:
• Next.js App Router structure
• API route handling
• Database access through Prisma
• Component generation flow
B. Key Interactions:
• User input → API → AI generation
• Generated code → Sandpack preview
• Share functionality flow
• Authentication flow
Implementation Details
• Rectangles: Core application components
• Clouds: External services
• Hexagons: API endpoints
• Rounded rectangles: UI components
Annotations for:
• Authentication flow
• Component generation process
• Preview system integration
• Database schema relationships