|
| 1 | +# 📖 The DevInterview.io Bible: AI-Driven Full-Stack Development |
| 2 | + |
| 3 | +Welcome! This document is a comprehensive guide to the **DevInterview.io** project. It serves as both a technical manual and a learning resource for college students interested in modern web development and AI-assisted engineering. |
| 4 | + |
| 5 | +--- |
| 6 | + |
| 7 | +## 🚀 Project Overview |
| 8 | + |
| 9 | +**DevInterview.io** is a real-time technical interview platform. It allows interviewers to create sessions, share them with candidates, and collaborate on code and a whiteboard in real-time. |
| 10 | + |
| 11 | +### Key Features: |
| 12 | +- **Real-time Sync**: Code, whiteboard, and timer stay in sync across all participants. |
| 13 | +- **Client-Side Execution**: Python and JavaScript code run safely in the browser using WebAssembly (WASM). |
| 14 | +- **Syntax Highlighting**: Rich code editing experience for multiple languages. |
| 15 | +- **Containerized Architecture**: Fully packaged using Docker and Nginx. |
| 16 | +- **Automated CI/CD**: Tests and deployments are handled automatically via GitHub Actions. |
| 17 | + |
| 18 | +--- |
| 19 | + |
| 20 | +## 🛠 The Tech Stack |
| 21 | + |
| 22 | +### Frontend: React & TypeScript |
| 23 | +- **Why?** React is the industry standard for building dynamic user interfaces. TypeScript adds "type safety," which prevents common bugs by ensuring variables are used correctly. |
| 24 | +- **Key Libraries**: |
| 25 | + - `tldraw`: For the collaborative whiteboard. |
| 26 | + - `monaco-editor`: The same engine that powers VS Code. |
| 27 | + - `socket.io-client`: For real-time communication. |
| 28 | + |
| 29 | +### Backend: FastAPI (Python) |
| 30 | +- **Why?** FastAPI is incredibly fast and uses Python's `async/await` for high performance. It also automatically generates API documentation. |
| 31 | +- **Key Libraries**: |
| 32 | + - `python-socketio`: Handles real-time events. |
| 33 | + - `SQLAlchemy`: An ORM (Object Relational Mapper) that lets us talk to the database using Python objects instead of raw SQL. |
| 34 | + |
| 35 | +### Database: PostgreSQL |
| 36 | +- **Why?** A robust, production-ready relational database. We started with SQLite for simplicity and moved to PostgreSQL for the cloud. |
| 37 | + |
| 38 | +### DevOps: Docker, Nginx, & GitHub Actions |
| 39 | +- **Docker**: Packages the app into "containers" so it runs the same way on every machine. |
| 40 | +- **Nginx**: Acts as a "Reverse Proxy," serving the frontend and routing API requests to the backend. |
| 41 | +- **GitHub Actions**: Our CI/CD pipeline that runs tests on every push. |
| 42 | + |
| 43 | +--- |
| 44 | + |
| 45 | +## 🤖 AI-Assisted Development: How We Built This |
| 46 | + |
| 47 | +Building this project wasn't just about writing code; it was about **collaborating with an AI Agent**. Here is the flow we followed and the prompts that drove it. |
| 48 | + |
| 49 | +### Phase 1: The Foundation (Frontend & Specs) |
| 50 | +We started with a frontend built in **Lovable**. |
| 51 | +- **AI Strategy**: We extracted the OpenAPI specifications from the frontend code to understand what endpoints the backend needed to provide. |
| 52 | +- **Prompt Example**: *"Analyze the frontend services and generate a FastAPI backend structure that matches these API calls."* |
| 53 | + |
| 54 | +### Phase 2: Implementing the Backend |
| 55 | +We built the FastAPI server to handle authentication, session management, and real-time sync. |
| 56 | +- **Challenge**: Real-time sync is hard. |
| 57 | +- **Solution**: We used Socket.IO "rooms" to isolate session data. |
| 58 | +- **Prompt Example**: *"Implement a Socket.IO handler that joins users to a room based on their `session_id` and broadcasts code changes only to that room."* |
| 59 | + |
| 60 | +### Phase 3: Advanced Features (WASM & Highlighting) |
| 61 | +To make the app secure, we moved code execution from the server to the client. |
| 62 | +- **Tech used**: `Pyodide` (Python in WASM). |
| 63 | +- **Prompt Example**: *"I want to remove the server-side `/execute` endpoint. Instead, use Pyodide in the React frontend to run Python code locally in the browser."* |
| 64 | + |
| 65 | +### Phase 4: Fixing Bugs & Refinement |
| 66 | +During our session, we noticed the "Duration" column was empty. |
| 67 | +- **The Fix**: We modified the `terminate_session` endpoint to calculate the difference between `start_time` and the current time. |
| 68 | +- **Prompt Example**: *"The duration column in the dashboard is empty. Update the backend to calculate the session duration in minutes when a session is terminated and save it to the database."* |
| 69 | + |
| 70 | +### Phase 5: Containerization (The "Docker" Phase) |
| 71 | +We needed to package the app for the cloud. |
| 72 | +- **The Challenge**: Nginx, FastAPI, and React all need to work together on one port. |
| 73 | +- **The Solution**: A multi-stage `Dockerfile` and an `nginx.conf` proxy. |
| 74 | +- **Prompt Example**: *"Create a Dockerfile that builds the React frontend, installs the FastAPI backend, and uses Nginx to serve both on port 8080. Also, create a docker-compose.yml with a PostgreSQL database."* |
| 75 | + |
| 76 | +### Phase 6: Cloud Deployment & CI/CD |
| 77 | +Finally, we deployed to Render and set up GitHub Actions. |
| 78 | +- **The Fix**: We encountered a `psycopg2` error on Render. |
| 79 | +- **Prompt Example**: *"Render is failing with 'ModuleNotFoundError: No module named psycopg2'. I am using asyncpg. Update the database connection logic to handle Render's postgres:// URL and convert it to the async-compatible postgresql+asyncpg:// format."* |
| 80 | + |
| 81 | +--- |
| 82 | + |
| 83 | +## 🎓 Learning for Students: Tips for Success |
| 84 | + |
| 85 | +1. **Don't Fear the Error**: Errors are just the AI's way of telling you what's missing. When you see a `ModuleNotFoundError`, it usually means a dependency isn't in your `pyproject.toml` or `package.json`. |
| 86 | +2. **Think in Components**: In React, break everything down. The Whiteboard is a component, the Editor is a component. This makes the code easier to manage. |
| 87 | +3. **State is Everything**: In a real-time app, the "Single Source of Truth" is the database. Use WebSockets to tell other users when that truth changes. |
| 88 | +4. **AI is a Pair Programmer**: Treat the AI as a senior dev. Ask it "Why did you choose this approach?" or "Can you explain this line of code?" |
| 89 | + |
| 90 | +--- |
| 91 | + |
| 92 | +## 🛠 How to Use This Project |
| 93 | + |
| 94 | +1. **Local Dev**: `npm run dev` (runs both client and server). |
| 95 | +2. **Docker**: `docker-compose up --build`. |
| 96 | +3. **Tests**: `cd server && uv run pytest` or `cd client && npm run test`. |
| 97 | + |
| 98 | +**Happy Coding!** 🚀 |
0 commit comments