How trolleroof/cafecode works
Project type and purpose
• This is a full-stack AI-powered coding tutor platform called “Cafécode.”
• Frontend: Next.js 13+ with TypeScript, Tailwind, shadcn/ui, Monaco editor, and WebContainer.
• Backend: Node.js/Express microservices in Docker, deployed on Fly.io.
• Database: Supabase (Postgres + row-level security + real-time auth).
• External services: Gemini AI API for code assistance, Stripe for payments.
File structure
• Top-level folders:
• frontend – Next.js app, UI components, client-side services, WebContainer integration.
• backend – Express routes, services modules, workspace files, Docker and deployment scripts.
• supabase – SQL migrations and local config for the Postgres database.
• .kiro/specs – spec-driven design documents (design.md, requirements.md, tasks.md).
• Notice subdirectories:
• frontend/app + frontend/components: screens and reusable UI.
• frontend/services + frontend/hooks: client-side orchestration layers.
• backend/routes + backend/services: modular API handlers and business logic.
• backend/workspaces: per-user ephemeral file systems.
• docker-compose.yml, backend/Dockerfile, backend/fly.toml: deployment config.
• Configuration and build scripts:
• next.config.js, tsconfig.json, tailwind.config.ts, postcss.config.js for frontend.
• .dockerignore, Dockerfile, deploy.sh for backend.
• supabase/.temp and supabase/migrations for DB provisioning.
README for additional insights
• Reinforces microservices architecture separating AI orchestration, workspace management, payment, file sync.
• Highlights real-time syncing via WebSockets and/or WebContainerSyncService.
• Describes migration from server-side node-pty pty streams to in-browser WebContainer runtime.
Main components and their relationships
A. Frontend
• Next.js SSR/SSG UI with pages under frontend/app.
• Monaco editor, file explorer, terminal rendered via WebContainer in the browser.
• Client-side services (BuildService, PreviewService, SynchronizationService) talk to backend over REST or WebSockets.
• Auth workflows using Supabase client library and JWT.
B. WebContainer sandbox
• Browser-native Node.js runtime that executes code, file I/O, and terminal sessions.
• Synchronized state via WebContainerSyncService and backend sync endpoints.
C. Backend (Express)
• HTTP API endpoints (routes folder) for account, guided projects, code analysis, file management, payments, search, translation.
• Services layer handles business logic: UserWorkspaceManager, FileSystemIndexer, StepDecisionEngine, StripeService, Gemini integration, etc.
• Real-time channels (WebSockets) for editor/terminal syncing.
• Middleware stack: Helmet, CORS, rate limiter, JWT verification against Supabase Auth.
• Workspace persistence and ephemeral storage under backend/workspaces.
D. Database (Supabase/Postgres)
• User profiles, project metadata, payment records.
• Row-level security ensures each user only sees their workspace.
• Triggers or migrations to enforce schema constraints.
E. External services
• Gemini AI API for code suggestions and decision engine.
• Stripe API for payment processing.
• Supabase Auth & realtime.
F. Deployment
• Frontend: Vercel or custom server via next config.
• Backend: Docker on Fly.io with fly.toml, deploy.sh.
• Supabase project provisioned via CLI and migrations.
Elements to include for clarity
• Clear labels on every component and service.
• Layer separation (presentation, application, data, external).
• Annotations for important design principles (microservices, spec-driven, real-time sync).