How dhrumilshah-216/ai_code_editor works
1. This repository is split into two runtime services plus a browser UI:
- Flask app in app.py on port 5000
- FastAPI app in fastapi_app.py on port 8000
- Static frontend assets and Jinja templates for the browser experience
2. The Flask service is the entrypoint for users. It serves the main pages (templates/index.html, templates/login.html, templates/editor.html) and handles session-based authentication. The README notes this is demo-style auth with hardcoded credentials and in-memory sessions, so there is no database boundary.
3. The browser UI is built from server-rendered HTML plus client-side JavaScript in static/js/script.js and styles in static/css/style.css. The editor experience is described as Monaco-based, so the frontend is responsible for the interactive coding surface and for initiating analysis requests.
4. The FastAPI service is the analysis engine boundary. It exposes code-analysis functionality separately from the UI/auth stack, which keeps analysis concerns isolated from page rendering and login flow.
5. Code flows from the editor in the browser to the analysis API. The user writes or edits code, selects a language, and triggers analysis; the frontend then sends the code payload to the FastAPI layer, which returns feedback for display in the UI.
6. The analysis layer supports multiple languages: Python, JavaScript, and C. That language choice is part of the request context passed from the frontend into the analyzer, so the backend can tailor feedback to the selected language.
7. There is an AI-backed analysis path plus a fallback path. The README indicates Google Gemini is used when available, but if the API key is missing or the service is unavailable, the system switches to a local analyzer so the core workflow still works offline.
8. GEMINI_API_KEY in a .env file is the main external-service dependency. This means AI quality depends on an optional cloud API, but the app is architected to degrade gracefully rather than fail closed.
9. The frontend assets are entirely local and bundled in the repo: images, CSS, and JavaScript live under static/. That makes the UI self-contained and lets Flask serve the whole browser experience without requiring a separate static-hosting layer.
10. The main architectural boundary is therefore:
- presentation/auth in Flask
- analysis in FastAPI
- optional third-party AI via Gemini
- fallback local analysis when AI is unavailable
This separation is the key thing to capture in an architecture diagram.
11. Operationally, the project is meant to be run as two processes in parallel. The Flask process provides the user-facing site, while the FastAPI process provides the analysis API, and the browser bridges the two through client-side requests.
12. There is no persistent storage layer in this repo. No database, queue, or file-backed state is part of the core architecture, so the diagram should focus on request/response interactions rather than data persistence.
Main entry points: script.js Editor UI · app.py Flask app · fastapi_app.py FastAPI app · style.css Stylesheet
Components 13
Presentation & Auth
Flask-served browser app, session login, and UI assets
- Flask app · Serves pages and handles session-based auth
app.py - Main pages · Server-rendered browser pages for landing, login, and editor
- Editor UI · Interactive coding surface and analysis trigger logic
static/js/script.js - Stylesheet · Local styling for the browser experience
static/css/style.css - Images · Local image assets bundled with the UI
static/images - Demo auth · Hardcoded credentials and in-memory sessions for login flow
Analysis Engine
FastAPI service and its code-analysis paths
- FastAPI app · Separate service boundary for code analysis
fastapi_app.py - Analysis API · Accepts code and language context from the browser
- Language router · Selects analysis behavior for Python, JavaScript, or C
- Gemini path · Uses Google Gemini when the API key and service are available
- Local fallback · Fallback analysis path when Gemini is unavailable
External AI
Optional third-party model dependency
- Gemini API · Optional third-party AI dependency driven by GEMINI_API_KEY
Other components
- Browser · User interacts with the UI and sends analysis requests
Connections 16
- Browser → Flask app: page requests · Loads the server-rendered site
- Flask app → Main pages: renders · Serves index, login, and editor templates
- Flask app → Demo auth: login/session · Validates demo credentials and manages session state
- Main pages → Editor UI: includes · HTML templates load the client-side editor experience
- Editor UI → Stylesheet: loads · Applies local CSS styling
- Editor UI → Images: loads · Uses bundled image assets
- Browser → Editor UI: edits code · User writes code in the browser editor
- Editor UI → FastAPI app: analysis request · Sends code and selected language to the analysis service
- FastAPI app → Analysis API: exposes · FastAPI entrypoint serves the analysis endpoint
- Analysis API → Language router: routes by language · Branches on Python, JavaScript, or C context
- Language router → Gemini path: primary · Prefers AI-backed analysis when available
- Language router → Local fallback: fallback · Uses local analysis if Gemini is unavailable
- Gemini path → Gemini API: calls · Optional external model request
- Local fallback → Editor UI: returns feedback · Sends analysis results back to the browser UI
- Gemini path → Editor UI: returns feedback · Sends AI-generated feedback back to the browser UI
- Demo auth → Browser: gates access · Controls access to the editor experience through login