How suhailult777/ai-coder-main works
Project type and purpose
• This is a full-stack web application: a browser-based AI-powered code editor with secure authentication and an autonomous “agent mode.”
• Purpose: let authenticated users generate code via AI models, toggle into agent mode for autonomous tasks (file creation, VSCode integration, command execution), and view real-time streaming results.
File structure
• Top-level directories:
• frontend/ – static UI: index.html, script.js, styles.css
• backend/
– server/ – Express.js server setup, auth, database drivers, storage abstraction
– api/ – REST endpoints (auth, agent, health, database, SSE stream)
– agent/ – agent logic, status JSON
– scripts/ – DB migration (JSON→Postgres)
• config/ – environment and Firebase config
• test/ – unit, integration, SSE and agent debug tools
• package.json, .env.example – Node.js setup
README for additional insights
• Tech stack: HTML/CSS/JS front end, Express/Node.js back end, PostgreSQL or JSON file storage, Firebase for Google Auth, OpenRouter and Gemini 2.0 for AI, SSE for real-time streaming, child process spawning for agent mode.
• Highlights: session-based auth, SSE streams for AI responses, agent’s START→THINK→ACTION→OBSERVE→OUTPUT workflow.
Main components and their interactions
a. Frontend UI
– Code editor, model dropdown, auth forms, agent mode toggle, SSE event listener
– Communicates with backend over HTTP(S) and SSE
b. Backend API layer (Express.js)
– /api/auth → login, registration, session management
– /api/agent → spawn agent process (child_process), open VSCode
– /api/agent-stream SSE → stream AI/agent progress to UI
– /api/database → optional DB calls
– /api/health → system and DB status
c. Storage layer
– JSON files (fallback) or PostgreSQL (production)
– Session store: connect-pg-simple or JSON
d. AI services (external)
– OpenRouter API (multiple models)
– Google Gemini 2.0 (primary for agent mode)
e. Firebase Authentication (external)
– Google sign-in integration
f. Agent runtime
– Node.js child processes running agent scripts
– VSCode CLI integration (“code” command)
– Filesystem operations for project scaffolding
g. User’s browser
– Hosts frontend assets, SSE connection, HTTP requests
Architectural patterns and design principles
• Layered architecture: Presentation (frontend), API/controllers, business logic (agent, AI integration), data access/storage.
• Separation of concerns: distinct modules for auth, agent, health, database, streaming.
• Event-driven streaming via SSE for real-time feedback.
• Pluggable storage: JSON vs Postgres with migration scripts.
• Externalized configuration for API keys and services.