How jay-lchicken/helipopcorp works
Project Type & Purpose
• KLC Code IDE is a full-stack web application built on Next.js, designed as an educational coding platform.
• It provides role-based dashboards (students vs. teachers), an online code editor (Monaco), real-time execution via Judge0, and persists data in PostgreSQL.
File Structure Analysis
• Top-level “src/app” folder holds the Next.js App Router pages and API routes.
• /src/app/page.js, /src/app/layout.js, client layout files: UI shell, routing.
• /src/app/ide, /src/app/dashboard: feature areas.
• /src/app/api/*/route.js: backend endpoints implemented as Next.js API Routes.
• /src/components: reusable UI components (e.g., CodeEditor).
• /src/lib/db.js: database helper for PostgreSQL via pg.
• middleware.js: global middleware (authentication guard, etc.).
• Config files: next.config.mjs, tailwind.config.mjs, postcss.config.mjs.
Key Architectural Insights from README
• Authentication via Clerk (OAuth/webhooks).
• Code execution offloaded to Judge0 API.
• Terminal UI powered by Xterm.js.
• DB schema: users and assignments tables in PostgreSQL.
Main Components & Their Responsibilities
A. Frontend (Next.js App Router)
• Pages & layouts in src/app for Home, Dashboard, IDE, etc.
• React components (Monaco Editor, Xterm terminal).
• Calls internal API routes to fetch data or trigger actions.
B. Backend API Routes (Next.js serverless functions)
• /api/usersync: sync Clerk users to Postgres
• /api/GetAssignments, /api/NewAssignment, /api/DeleteAssignment, /api/EditAssignment
• /api/SubmitCode/RunCode: forward code & language ID to Judge0, return execution results
• /api/clerk-webhook: listens for Clerk user creation events
C. Database (PostgreSQL)
• Stores user profiles, roles, assignments metadata
• Accessed via /src/lib/db.js
D. External Services
• Clerk: authentication, session management, webhooks
• Judge0 API: code compilation & execution
Relationships & Data Flows
• User’s browser ↔️ Next.js frontend (UI & React hooks)
• Frontend → Next.js API routes (HTTP calls)
• API routes → PostgreSQL via db.js (CRUD operations)
• API routes → Judge0 API (code execution)
• Clerk webhooks → /api/clerk-webhook → DB
• Middleware ensures only authorized roles access teacher-only endpoints
Architectural Patterns & Principles
• Separation of concerns: UI, business logic (API routes), data access layer
• Serverless functions: each /api/*/route.js is isolated, stateless
• Role-based access control enforced at middleware/API layer
• Feature folders under src/app follow Next.js App Router conventions