# dhrumilshah-216/ai_code_editor architecture

> Architecture diagram of the GitHub repository dhrumilshah-216/ai_code_editor, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2026-04-14). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/dhrumilshah-216/ai_code_editor
- Repository: https://github.com/dhrumilshah-216/ai_code_editor

## Overview

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: [`static/js/script.js`](https://github.com/dhrumilshah-216/ai_code_editor/blob/main/static/js/script.js) (Editor UI), [`app.py`](https://github.com/dhrumilshah-216/ai_code_editor/blob/main/app.py) (Flask app), [`fastapi_app.py`](https://github.com/dhrumilshah-216/ai_code_editor/blob/main/fastapi_app.py) (FastAPI app), [`static/css/style.css`](https://github.com/dhrumilshah-216/ai_code_editor/blob/main/static/css/style.css) (Stylesheet)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_presentation["Presentation & Auth"]
  node_app["Flask app<br/>flask entrypoint<br/>[app.py]"]
  node_pages["Main pages<br/>jinja templates"]
  node_editor_ui["Editor UI<br/>monaco frontend<br/>[script.js]"]
  node_styles["Stylesheet<br/>css assets<br/>[style.css]"]
  node_images["Images<br/>static assets"]
  node_auth{{"Demo auth<br/>session auth"}}
end

subgraph group_analysis["Analysis Engine"]
  node_fastapi["FastAPI app<br/>api entrypoint<br/>[fastapi_app.py]"]
  node_analysis_api["Analysis API<br/>request handler"]
  node_lang_router{{"Language router<br/>multi-language dispatch"}}
  node_gemini_path(("Gemini path<br/>ai analysis"))
  node_local_path(("Local fallback<br/>offline analyzer"))
end

subgraph group_external["External AI"]
  node_gemini_api(("Gemini API<br/>external service"))
end

node_browser(("Browser<br/>client"))

node_browser -->|"page requests"| node_app
node_app -->|"renders"| node_pages
node_app -->|"login/session"| node_auth
node_pages -->|"includes"| node_editor_ui
node_editor_ui -->|"loads"| node_styles
node_editor_ui -->|"loads"| node_images
node_browser -->|"edits code"| node_editor_ui
node_editor_ui -->|"analysis request"| node_fastapi
node_fastapi -->|"exposes"| node_analysis_api
node_analysis_api -->|"routes by language"| node_lang_router
node_lang_router -->|"primary"| node_gemini_path
node_lang_router -->|"fallback"| node_local_path
node_gemini_path -->|"calls"| node_gemini_api
node_local_path -->|"returns feedback"| node_editor_ui
node_gemini_path -->|"returns feedback"| node_editor_ui
node_auth -->|"gates access"| node_browser

click node_app "https://github.com/dhrumilshah-216/ai_code_editor/blob/main/app.py"
click node_editor_ui "https://github.com/dhrumilshah-216/ai_code_editor/blob/main/static/js/script.js"
click node_styles "https://github.com/dhrumilshah-216/ai_code_editor/blob/main/static/css/style.css"
click node_images "https://github.com/dhrumilshah-216/ai_code_editor/tree/main/static/images"
click node_fastapi "https://github.com/dhrumilshah-216/ai_code_editor/blob/main/fastapi_app.py"

classDef toneNeutral fill:#f8fafc,stroke:#334155,stroke-width:1.5px,color:#0f172a
classDef toneBlue fill:#dbeafe,stroke:#2563eb,stroke-width:1.5px,color:#172554
classDef toneAmber fill:#fef3c7,stroke:#d97706,stroke-width:1.5px,color:#78350f
classDef toneMint fill:#dcfce7,stroke:#16a34a,stroke-width:1.5px,color:#14532d
classDef toneRose fill:#ffe4e6,stroke:#e11d48,stroke-width:1.5px,color:#881337
classDef toneIndigo fill:#e0e7ff,stroke:#4f46e5,stroke-width:1.5px,color:#312e81
classDef toneTeal fill:#ccfbf1,stroke:#0f766e,stroke-width:1.5px,color:#134e4a
class node_app,node_pages,node_editor_ui,node_styles,node_images,node_auth toneBlue
class node_fastapi,node_analysis_api,node_lang_router,node_gemini_path,node_local_path toneAmber
class node_gemini_api toneMint
class node_browser toneNeutral
```

## Components

### Presentation & Auth

Flask-served browser app, session login, and UI assets

- [Flask app](https://github.com/dhrumilshah-216/ai_code_editor/blob/main/app.py): flask entrypoint · Serves pages and handles session-based auth · `app.py`
- **Main pages**: jinja templates · Server-rendered browser pages for landing, login, and editor
- [Editor UI](https://github.com/dhrumilshah-216/ai_code_editor/blob/main/static/js/script.js): monaco frontend · Interactive coding surface and analysis trigger logic · `static/js/script.js`
- [Stylesheet](https://github.com/dhrumilshah-216/ai_code_editor/blob/main/static/css/style.css): css assets · Local styling for the browser experience · `static/css/style.css`
- [Images](https://github.com/dhrumilshah-216/ai_code_editor/tree/main/static/images): static assets · Local image assets bundled with the UI · `static/images`
- **Demo auth**: session auth · Hardcoded credentials and in-memory sessions for login flow

### Analysis Engine

FastAPI service and its code-analysis paths

- [FastAPI app](https://github.com/dhrumilshah-216/ai_code_editor/blob/main/fastapi_app.py): api entrypoint · Separate service boundary for code analysis · `fastapi_app.py`
- **Analysis API**: request handler · Accepts code and language context from the browser
- **Language router**: multi-language dispatch · Selects analysis behavior for Python, JavaScript, or C
- **Gemini path**: ai analysis · Uses Google Gemini when the API key and service are available
- **Local fallback**: offline analyzer · Fallback analysis path when Gemini is unavailable

### External AI

Optional third-party model dependency

- **Gemini API**: external service · Optional third-party AI dependency driven by GEMINI_API_KEY

### Other components

- **Browser**: client · User interacts with the UI and sends analysis requests

## Connections

- 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
