How sankalp210/project-idx-clone works
Project Type and Purpose
• This is a full-stack, real-time web application.
• Purpose: Provide a browser-based code playground with live file tree, editor, and an interactive shell terminal powered by WebSockets and Docker.
High-Level Structure
• FRONTEND/
• React + Vite SPA that handles UI: file tree, code editor, terminal UI, routing, state management (Zustand), API & socket hooks.
• External service: Supabase (used for authentication/storage).
• BACKEND/
• Node.js/Express HTTP server exposing REST v1 API (ping, project management).
• WebSocket endpoint for editor events (editorHandler.js) and terminal I/O (terminalApp.js).
• Dockerfile to build a “sandbox” container for secure shell sessions.
• Core layers: config, controllers, services, socket handlers, route definitions.
• Dockerized Terminal Service (optional runtime)
• Standalone container providing a shell sandbox.
• Communicates via WebSocket to the browser terminal component.
Main Components
a. Browser (React/Vite)
• Pages/Components: Project list page, playground, file tree, editor, terminal UI.
• Interacts with both REST API and WebSocket streams.
b. API & Socket Server (Node.js/Express)
• REST API (HTTP)
• Routes: /v1/ping, /v1/projects
• Controllers → Services → File/project management on disk
• WebSocket Server
• Editor channel: bi-directional code edits and file operations
• Terminal channel: forwards keystrokes & receives shell output
c. Sandbox Container (Docker)
• Hosts the actual shell process (bash/sh) in an isolated environment
• Built from BACKEND/Dockerfile
d. External Service
• Supabase (auth, project persistence, optional file storage)
Component Relationships & Data Flows
• Browser ⟷ REST API (HTTP): fetch project list, create projects, ping.
• Browser ⟷ WebSocket Server:
• Editor Socket: real-time code & file tree synchronization
• Terminal Socket: interactive shell I/O
• WebSocket Server ↔ Sandbox Container: spawn container, attach stdio streams to WebSocket
• REST API ↔ File System: read/write project files under src/projects/{projectId}
• Browser ↔ Supabase: authentication tokens, maybe project metadata
Architectural Patterns & Principles
• Separation of Concerns:
• REST vs. WebSocket endpoints
• Controller → Service → Utility layers
• Frontend: atoms → molecules → organisms → pages (atomic design)
• Micro-sandboxing: Docker container per terminal session, isolated from host
• Event-driven I/O: WebSockets for low-latency real-time updates
• Stateful sockets, stateless REST
Essential Elements
• Frontend modules (routers, components, API clients)
• REST routes vs. WS handlers
• File system root path for projects
• Docker build & run flow
• Supabase integration