# sai-subhash-9/devinsight architecture

> Architecture diagram of the GitHub repository sai-subhash-9/devinsight, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2026-05-28). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/sai-subhash-9/devinsight
- Repository: https://github.com/sai-subhash-9/devinsight

## Overview

1. **Overall shape**
   - DevInsight is a two-tier MERN application: a React/Vite frontend in `client/` and an Express/Mongoose backend in `server/`.
   - The backend is the system of record for users, projects, snippets, and reviews; the frontend is a thin UI layer that consumes REST APIs.

2. **Frontend boundary**
   - The client is a single-page app built with React 18, React Router, Axios, Tailwind CSS, and Monaco Editor.
   - Core pages are `Login`, `Register`, `Dashboard`, and `Workspace`, with reusable UI pieces like `Navbar`, `Sidebar`, `CodeEditor`, `ReviewPanel`, and `ProtectedRoute`.

3. **Authentication flow**
   - Authentication is JWT-based and state is managed through `AuthContext`.
   - Users register or log in through the API, receive a token, and the frontend uses that token to access protected routes and authenticated backend endpoints.

4. **Frontend data access**
   - `client/src/services/api.js` is the main network boundary for the UI.
   - It centralizes calls to the backend’s `/api/...` routes, so pages/components do not talk to the server directly.

5. **Workspace and editor experience**
   - `Workspace` appears to be the main product surface: users select a project, edit code snippets in the editor, and view analysis output in the review panel.
   - `Sidebar` likely manages project/snippet navigation, while `CodeEditor` and `ReviewPanel` form the core create-review loop.

6. **Backend application structure**
   - The server is organized by responsibility: `routes` define HTTP surfaces, `controllers` implement request handling, `middleware` enforces auth, `models` define MongoDB schemas, and `services` encapsulate analysis logic.
   - `server.js` is the composition point that wires Express, routes, middleware, and database connection.

7. **Persistence layer**
   - MongoDB Atlas is the persistent store, accessed through Mongoose models for `User`, `Project`, `Snippet`, and `Review`.
   - The domain is hierarchical: users own projects, projects contain snippets, and snippets have generated reviews.

8. **API and authorization boundaries**
   - Public endpoints are limited to `register` and `login`.
   - All project, snippet, and review endpoints are protected by JWT middleware in `server/middleware/auth.js`, so the backend enforces ownership and access control.

9. **AI review subsystem**
   - `server/services/aiService.js` is the analysis engine behind review generation.
   - The README indicates it prefers Groq API / LLaMA 3.3 70B when configured, but falls back to a built-in rule-based analyzer when no API key is present.

10. **Review generation flow**
   - A user submits a snippet for review from the workspace.
   - The backend controller invokes the AI service, produces structured feedback, persists the review in MongoDB, and returns it to the client for display.

11. **Deployment/runtime boundaries**
   - The frontend is designed to be deployed separately from the backend, with `VITE_API_URL` pointing to the server.
   - The backend runs on Node.js/Express, connects to MongoDB Atlas, and reads secrets such as `JWT_SECRET`, `MONGODB_URI`, and optional `GROQ_API_KEY` from environment variables.

12. **What to draw in an architecture diagram**
   - Show three external dependencies: the browser/client, MongoDB Atlas, and optional Groq AI.
   - Show the main internal flow: React UI → Axios API layer → Express routes/controllers → auth middleware / Mongoose models → MongoDB, with review requests additionally flowing through `aiService` before being stored and returned.

Main entry points: [`client/src/App.jsx`](https://github.com/sai-subhash-9/devinsight/blob/main/client/src/App.jsx) (App Shell), [`client/src/pages/Workspace.jsx`](https://github.com/sai-subhash-9/devinsight/blob/main/client/src/pages/Workspace.jsx) (Workspace), [`server/server.js`](https://github.com/sai-subhash-9/devinsight/blob/main/server/server.js) (Server), [`server/controllers/reviewController.js`](https://github.com/sai-subhash-9/devinsight/blob/main/server/controllers/reviewController.js) (Review Controller)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_frontend["Frontend"]
  node_main_ui["App Shell<br/>react app<br/>[App.jsx]"]
  node_auth_ctx["Auth Context<br/>state<br/>[AuthContext.jsx]"]
  node_api_client["API Client<br/>http layer<br/>[api.js]"]
  node_login["Login<br/>page<br/>[Login.jsx]"]
  node_register["Register<br/>page<br/>[Register.jsx]"]
  node_dashboard["Dashboard<br/>page<br/>[Dashboard.jsx]"]
  node_workspace["Workspace<br/>page<br/>[Workspace.jsx]"]
  node_protected["Protected Route<br/>route guard<br/>[ProtectedRoute.jsx]"]
  node_navbar["Navbar<br/>ui component<br/>[Navbar.jsx]"]
  node_sidebar["Sidebar<br/>workspace nav<br/>[Sidebar.jsx]"]
  node_editor["Code Editor<br/>[CodeEditor.jsx]"]
  node_review_panel["Review Panel<br/>results view<br/>[ReviewPanel.jsx]"]
end

subgraph group_backend["Backend"]
  node_server["Server<br/>express app<br/>[server.js]"]
  node_db_config["DB Config<br/>mongodb conn<br/>[db.js]"]
  node_auth_routes["Auth Routes<br/>route surface<br/>[authRoutes.js]"]
  node_project_routes["Project Routes<br/>route surface<br/>[projectRoutes.js]"]
  node_snippet_routes["Snippet Routes<br/>route surface<br/>[snippetRoutes.js]"]
  node_review_routes["Review Routes<br/>route surface<br/>[reviewRoutes.js]"]
  node_auth_ctrl["Auth Controller<br/>[authController.js]"]
  node_project_ctrl["Project Controller"]
  node_snippet_ctrl["Snippet Controller"]
  node_review_ctrl["Review Controller"]
  node_auth_mw["JWT Middleware<br/>auth guard<br/>[auth.js]"]
  node_user_model["User Model<br/>mongoose model<br/>[User.js]"]
  node_project_model["Project Model<br/>mongoose model<br/>[Project.js]"]
  node_snippet_model["Snippet Model<br/>mongoose model<br/>[Snippet.js]"]
  node_review_model["Review Model<br/>mongoose model<br/>[Review.js]"]
  node_ai_service["AI Service<br/>analysis engine<br/>[aiService.js]"]
end

subgraph group_external["External"]
  node_browser(("Browser<br/>client runtime"))
  node_groq(("Groq AI<br/>optional ai"))
  node_mongo[("MongoDB Atlas<br/>database")]
end

node_browser -->|"loads app"| node_main_ui
node_main_ui -->|"session state"| node_auth_ctx
node_main_ui -->|"guards routes"| node_protected
node_protected -->|"allows access"| node_dashboard
node_protected -->|"allows access"| node_workspace
node_main_ui -->|"renders"| node_login
node_main_ui -->|"renders"| node_register
node_main_ui -->|"renders"| node_dashboard
node_main_ui -->|"renders"| node_workspace
node_workspace -->|"uses"| node_navbar
node_workspace -->|"uses"| node_sidebar
node_workspace -->|"uses"| node_editor
node_workspace -->|"uses"| node_review_panel
node_login -->|"auth request"| node_api_client
node_register -->|"auth request"| node_api_client
node_dashboard -->|"fetches data"| node_api_client
node_workspace -->|"reads/writes"| node_api_client
node_api_client -->|"REST calls"| node_server
node_server -->|"mounts"| node_auth_routes
node_server -->|"mounts"| node_project_routes
node_server -->|"mounts"| node_snippet_routes
node_server -->|"mounts"| node_review_routes
node_auth_routes -->|"handles"| node_auth_ctrl
node_project_routes -->|"protects"| node_auth_mw
node_snippet_routes -->|"protects"| node_auth_mw
node_review_routes -->|"protects"| node_auth_mw
node_project_routes -->|"handles"| node_project_ctrl
node_snippet_routes -->|"handles"| node_snippet_ctrl
node_review_routes -->|"handles"| node_review_ctrl
node_auth_ctrl -->|"stores users"| node_user_model
node_project_ctrl -->|"stores projects"| node_project_model
node_snippet_ctrl -->|"stores snippets"| node_snippet_model
node_review_ctrl -->|"stores reviews"| node_review_model
node_review_ctrl -->|"generates feedback"| node_ai_service
node_ai_service -->|"optional model"| node_groq
node_server -->|"connects"| node_db_config
node_db_config -->|"persists to"| node_mongo
node_user_model -->|"reads/writes"| node_mongo
node_project_model -->|"reads/writes"| node_mongo
node_snippet_model -->|"reads/writes"| node_mongo
node_review_model -->|"reads/writes"| node_mongo
node_review_panel -->|"loads reviews"| node_review_routes
node_snippet_ctrl -->|"creates review"| node_review_ctrl
node_review_ctrl -->|"returns feedback"| node_review_panel

click node_main_ui "https://github.com/sai-subhash-9/devinsight/blob/main/client/src/App.jsx"
click node_auth_ctx "https://github.com/sai-subhash-9/devinsight/blob/main/client/src/context/AuthContext.jsx"
click node_api_client "https://github.com/sai-subhash-9/devinsight/blob/main/client/src/services/api.js"
click node_login "https://github.com/sai-subhash-9/devinsight/blob/main/client/src/pages/Login.jsx"
click node_register "https://github.com/sai-subhash-9/devinsight/blob/main/client/src/pages/Register.jsx"
click node_dashboard "https://github.com/sai-subhash-9/devinsight/blob/main/client/src/pages/Dashboard.jsx"
click node_workspace "https://github.com/sai-subhash-9/devinsight/blob/main/client/src/pages/Workspace.jsx"
click node_protected "https://github.com/sai-subhash-9/devinsight/blob/main/client/src/components/ProtectedRoute.jsx"
click node_navbar "https://github.com/sai-subhash-9/devinsight/blob/main/client/src/components/Navbar.jsx"
click node_sidebar "https://github.com/sai-subhash-9/devinsight/blob/main/client/src/components/Sidebar.jsx"
click node_editor "https://github.com/sai-subhash-9/devinsight/blob/main/client/src/components/CodeEditor.jsx"
click node_review_panel "https://github.com/sai-subhash-9/devinsight/blob/main/client/src/components/ReviewPanel.jsx"
click node_server "https://github.com/sai-subhash-9/devinsight/blob/main/server/server.js"
click node_db_config "https://github.com/sai-subhash-9/devinsight/blob/main/server/config/db.js"
click node_auth_routes "https://github.com/sai-subhash-9/devinsight/blob/main/server/routes/authRoutes.js"
click node_project_routes "https://github.com/sai-subhash-9/devinsight/blob/main/server/routes/projectRoutes.js"
click node_snippet_routes "https://github.com/sai-subhash-9/devinsight/blob/main/server/routes/snippetRoutes.js"
click node_review_routes "https://github.com/sai-subhash-9/devinsight/blob/main/server/routes/reviewRoutes.js"
click node_auth_ctrl "https://github.com/sai-subhash-9/devinsight/blob/main/server/controllers/authController.js"
click node_project_ctrl "https://github.com/sai-subhash-9/devinsight/blob/main/server/controllers/projectController.js"
click node_snippet_ctrl "https://github.com/sai-subhash-9/devinsight/blob/main/server/controllers/snippetController.js"
click node_review_ctrl "https://github.com/sai-subhash-9/devinsight/blob/main/server/controllers/reviewController.js"
click node_auth_mw "https://github.com/sai-subhash-9/devinsight/blob/main/server/middleware/auth.js"
click node_user_model "https://github.com/sai-subhash-9/devinsight/blob/main/server/models/User.js"
click node_project_model "https://github.com/sai-subhash-9/devinsight/blob/main/server/models/Project.js"
click node_snippet_model "https://github.com/sai-subhash-9/devinsight/blob/main/server/models/Snippet.js"
click node_review_model "https://github.com/sai-subhash-9/devinsight/blob/main/server/models/Review.js"
click node_ai_service "https://github.com/sai-subhash-9/devinsight/blob/main/server/services/aiService.js"

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_main_ui,node_auth_ctx,node_api_client,node_login,node_register,node_dashboard,node_workspace,node_protected,node_navbar,node_sidebar,node_editor,node_review_panel toneBlue
class node_server,node_db_config,node_auth_routes,node_project_routes,node_snippet_routes,node_review_routes,node_auth_ctrl,node_project_ctrl,node_snippet_ctrl,node_review_ctrl,node_auth_mw,node_user_model,node_project_model,node_snippet_model,node_review_model,node_ai_service toneAmber
class node_browser,node_groq,node_mongo toneMint
```

## Components

### Frontend

React/Vite client and UI flow

- [App Shell](https://github.com/sai-subhash-9/devinsight/blob/main/client/src/App.jsx): react app · Top-level client composition and routing · `client/src/App.jsx`
- [Auth Context](https://github.com/sai-subhash-9/devinsight/blob/main/client/src/context/AuthContext.jsx): state · JWT auth state and session management · `client/src/context/AuthContext.jsx`
- [API Client](https://github.com/sai-subhash-9/devinsight/blob/main/client/src/services/api.js): http layer · Centralized Axios boundary to backend routes · `client/src/services/api.js`
- [Login](https://github.com/sai-subhash-9/devinsight/blob/main/client/src/pages/Login.jsx): page · Authentication entry page · `client/src/pages/Login.jsx`
- [Register](https://github.com/sai-subhash-9/devinsight/blob/main/client/src/pages/Register.jsx): page · Account creation page · `client/src/pages/Register.jsx`
- [Dashboard](https://github.com/sai-subhash-9/devinsight/blob/main/client/src/pages/Dashboard.jsx): page · Authenticated landing page · `client/src/pages/Dashboard.jsx`
- [Workspace](https://github.com/sai-subhash-9/devinsight/blob/main/client/src/pages/Workspace.jsx): page · Main project and review workspace · `client/src/pages/Workspace.jsx`
- [Protected Route](https://github.com/sai-subhash-9/devinsight/blob/main/client/src/components/ProtectedRoute.jsx): route guard · Blocks unauthenticated access to private screens · `client/src/components/ProtectedRoute.jsx`
- [Navbar](https://github.com/sai-subhash-9/devinsight/blob/main/client/src/components/Navbar.jsx): ui component · Global navigation chrome · `client/src/components/Navbar.jsx`
- [Sidebar](https://github.com/sai-subhash-9/devinsight/blob/main/client/src/components/Sidebar.jsx): workspace nav · Project and snippet navigation · `client/src/components/Sidebar.jsx`
- [Code Editor](https://github.com/sai-subhash-9/devinsight/blob/main/client/src/components/CodeEditor.jsx): editor · Monaco-based code editing surface · `client/src/components/CodeEditor.jsx`
- [Review Panel](https://github.com/sai-subhash-9/devinsight/blob/main/client/src/components/ReviewPanel.jsx): results view · Displays generated feedback and analysis · `client/src/components/ReviewPanel.jsx`

### Backend

Express API, auth, data, and review pipeline

- [Server](https://github.com/sai-subhash-9/devinsight/blob/main/server/server.js): express app · Express composition point and API host · `server/server.js`
- [DB Config](https://github.com/sai-subhash-9/devinsight/blob/main/server/config/db.js): mongodb conn · MongoDB connection setup · `server/config/db.js`
- [Auth Routes](https://github.com/sai-subhash-9/devinsight/blob/main/server/routes/authRoutes.js): route surface · Public login and register endpoints · `server/routes/authRoutes.js`
- [Project Routes](https://github.com/sai-subhash-9/devinsight/blob/main/server/routes/projectRoutes.js): route surface · Protected project API endpoints · `server/routes/projectRoutes.js`
- [Snippet Routes](https://github.com/sai-subhash-9/devinsight/blob/main/server/routes/snippetRoutes.js): route surface · Protected snippet API endpoints · `server/routes/snippetRoutes.js`
- [Review Routes](https://github.com/sai-subhash-9/devinsight/blob/main/server/routes/reviewRoutes.js): route surface · Protected review API endpoints · `server/routes/reviewRoutes.js`
- [Auth Controller](https://github.com/sai-subhash-9/devinsight/blob/main/server/controllers/authController.js): controller · Login and registration handling · `server/controllers/authController.js`
- [Project Controller](https://github.com/sai-subhash-9/devinsight/blob/main/server/controllers/projectController.js): controller · Project CRUD and ownership logic · `server/controllers/projectController.js`
- [Snippet Controller](https://github.com/sai-subhash-9/devinsight/blob/main/server/controllers/snippetController.js): controller · Snippet CRUD and review submission entrypoint · `server/controllers/snippetController.js`
- [Review Controller](https://github.com/sai-subhash-9/devinsight/blob/main/server/controllers/reviewController.js): controller · Review retrieval and persistence · `server/controllers/reviewController.js`
- [JWT Middleware](https://github.com/sai-subhash-9/devinsight/blob/main/server/middleware/auth.js): auth guard · Protects private API routes · `server/middleware/auth.js`
- [User Model](https://github.com/sai-subhash-9/devinsight/blob/main/server/models/User.js): mongoose model · User schema and credentials · `server/models/User.js`
- [Project Model](https://github.com/sai-subhash-9/devinsight/blob/main/server/models/Project.js): mongoose model · Project schema and ownership · `server/models/Project.js`
- [Snippet Model](https://github.com/sai-subhash-9/devinsight/blob/main/server/models/Snippet.js): mongoose model · Snippet schema and code content · `server/models/Snippet.js`
- [Review Model](https://github.com/sai-subhash-9/devinsight/blob/main/server/models/Review.js): mongoose model · Stored AI or rule-based feedback · `server/models/Review.js`
- [AI Service](https://github.com/sai-subhash-9/devinsight/blob/main/server/services/aiService.js): analysis engine · Groq-backed or rule-based review generation · `server/services/aiService.js`

### External

Runtime and third-party services

- **Browser**: client runtime · User-facing SPA runtime
- **Groq AI**: optional ai · Optional LLaMA-powered review backend
- **MongoDB Atlas**: database · Persistent store for users, projects, snippets, and reviews

## Connections

- Browser → App Shell: loads app · Browser hosts the React SPA
- App Shell → Auth Context: session state · App reads and updates auth state
- App Shell → Protected Route: guards routes · Private screens are wrapped by route protection
- Protected Route → Dashboard: allows access · Authenticated users reach dashboard
- Protected Route → Workspace: allows access · Authenticated users reach workspace
- App Shell → Login: renders · Public authentication page
- App Shell → Register: renders · Public authentication page
- App Shell → Dashboard: renders · Authenticated overview
- App Shell → Workspace: renders · Primary product surface
- Workspace → Navbar: uses · Shared navigation chrome
- Workspace → Sidebar: uses · Project/snippet navigation
- Workspace → Code Editor: uses · Code editing surface
- Workspace → Review Panel: uses · Shows analysis output
- Login → API Client: auth request · Login submits via API client
- Register → API Client: auth request · Registration submits via API client
- Dashboard → API Client: fetches data · Dashboard loads protected data
- Workspace → API Client: reads/writes · Workspace loads projects, snippets, and reviews
- API Client → Server: REST calls · Central HTTP boundary to backend
- Server → Auth Routes: mounts · Public auth endpoints
- Server → Project Routes: mounts · Protected project endpoints
- Server → Snippet Routes: mounts · Protected snippet endpoints
- Server → Review Routes: mounts · Protected review endpoints
- Auth Routes → Auth Controller: handles · Login and register requests
- Project Routes → JWT Middleware: protects · JWT required for project access
- Snippet Routes → JWT Middleware: protects · JWT required for snippet access
- Review Routes → JWT Middleware: protects · JWT required for review access
- Project Routes → Project Controller: handles · Project request handling
- Snippet Routes → Snippet Controller: handles · Snippet request handling
- Review Routes → Review Controller: handles · Review request handling
- Auth Controller → User Model: stores users · User records are created and verified
- Project Controller → Project Model: stores projects · Project documents are created and queried
- Snippet Controller → Snippet Model: stores snippets · Snippet documents are created and queried
- Review Controller → Review Model: stores reviews · Review documents are created and queried
- Review Controller → AI Service: generates feedback · Controller invokes analysis before persisting
- AI Service → Groq AI: optional model · Uses Groq when configured
- Server → DB Config: connects · Server initializes MongoDB connection
- DB Config → MongoDB Atlas: persists to · MongoDB Atlas is the data store
- User Model → MongoDB Atlas: reads/writes · Mongoose model persistence
- Project Model → MongoDB Atlas: reads/writes · Mongoose model persistence
- Snippet Model → MongoDB Atlas: reads/writes · Mongoose model persistence
- Review Model → MongoDB Atlas: reads/writes · Mongoose model persistence
- Review Panel → Review Routes: loads reviews · UI consumes generated feedback
- Snippet Controller → Review Controller: creates review · Snippet submission flows into review generation
- Review Controller → Review Panel: returns feedback · Structured review is sent back to the client
