# prathamthatte52701/sage-hackathon architecture

> Architecture diagram of the GitHub repository prathamthatte52701/sage-hackathon, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2026-08-22). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/prathamthatte52701/sage-hackathon
- Repository: https://github.com/prathamthatte52701/sage-hackathon

## Overview

#### Purpose and Entry Points
CODE MASTER AI is a code-intelligence workspace for reviewing pasted snippets and imported ZIP/GitHub projects, producing evidence-backed findings, guidance, chat responses, and validated fixes. The root development command starts React and FastAPI. Backend registration begins at `server/main.py`; browser bootstrapping flows through `client/src/main.jsx` into `client/src/App.jsx`.

#### Frontend Workspace
The Vite/React client is the user-facing orchestration layer for paste review, project analysis, finding exploration, chat, and preview-first fixes. `client/src/api/client.js` is the API boundary; it should remain the central transport contract. Major stateful views include `client/src/components/CodeEditor.jsx`, `client/src/components/ProjectOverview.jsx`, and `client/src/components/FixValidationModal.jsx`. Authentication state is isolated in `client/src/context/AuthContext.jsx`.

#### HTTP/API Domains
FastAPI separates product capabilities by router: authentication in `server/routers/auth.py`, snippet review and paste fixes in `server/routers/review.py`, and project import, analysis, fixes, downloads, and chat in `server/routers/projects.py`. Explanation-oriented interactions are handled by `server/routers/explain.py`. Request/response contracts are defined in `server/models/schemas.py`, forming the main frontend/backend compatibility boundary.

#### Evidence-First Analysis Pipeline
Snippet and project review first derive deterministic evidence, then optionally augment it with LLM quality review. Project structure and metadata extraction begin in `server/services/analyzer.py`; language-specific detection is in `server/services/analyzers/python_analyzer.py` and `server/services/analyzers/javascript_analyzer.py`, with rule definitions in `server/services/analyzers/rules.py`. Python taint tracking (`server/services/analyzers/python_taint.py`) and AST structure analysis (`server/services/structural/python_ast.py`) deepen evidence where applicable. Findings are deduplicated, grounded, and scored through `server/services/grounding.py` and `server/services/scoring.py`.

#### Knowledge and Retrieval Boundaries
Curated engineering guidance is deliberately separate from uploaded project code. Knowledge records, validation, ingestion, and hybrid retrieval reside in `server/knowledge/schema.py`, `server/knowledge/ingest.py`, and `server/knowledge/retrieval.py`. Finding-scoped retrieval uses exact rule/category evidence before semantic matches. Repository chat and project-context retrieval are separate service concerns in `server/services/retrieval.py` and `server/services/context_expansion.py`; retrieved guidance informs recommendations but is not proof of a finding.

#### AI Reasoning and External Services
LLM calls are constrained to explanations, quality review, chat, reasoning, and patch proposals—not authoritative detection. Prompt construction and reasoning orchestration are in `server/services/prompt_builder.py` and `server/services/reasoning_engine.py`; Groq integration is isolated behind `server/services/groq_client.py`. MongoDB Atlas stores application/project data and the curated `sage_knowledge` vector collection; embeddings are generated via `server/services/embeddings.py` and knowledge embeddings via `server/knowledge/embeddings.py`. The default embedding model is local `all-MiniLM-L6-v2` (384 dimensions), with vector-search fallback when unavailable.

#### Safe Fix and Reanalysis Loop
Fix generation is preview-only until explicit application. `server/services/patching.py` validates exact targets, uniqueness, source freshness, overlap, and patch structure before modifying working source or a target project file. Review/project routers then invoke reanalysis against the changed working artifact, while project download exports a sanitized fixed ZIP. This boundary preserves original source, prevents unsafe broad edits, and keeps LLM output subordinate to deterministic patch validation.

Main entry points: [`server/routers/projects.py`](https://github.com/prathamthatte52701/sage-hackathon/blob/main/server/routers/projects.py) (Product Routers), [`server/services/analyzer.py`](https://github.com/prathamthatte52701/sage-hackathon/blob/main/server/services/analyzer.py) (Project Analyzer), [`server/services/reasoning_engine.py`](https://github.com/prathamthatte52701/sage-hackathon/blob/main/server/services/reasoning_engine.py) (AI Reasoning), [`client/src/App.jsx`](https://github.com/prathamthatte52701/sage-hackathon/blob/main/client/src/App.jsx) (Workspace App)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_client["React Client"]
  node_client_boot["Client Bootstrap<br/>Vite entry<br/>[main.jsx]"]
  node_app["Workspace App<br/>React shell<br/>[App.jsx]"]
  node_api_client["API Client<br/>transport contract<br/>[client.js]"]
  node_workspace_views["Review &amp; Fix Views<br/>stateful views<br/>[CodeEditor.jsx]"]
  node_auth_context["Auth State<br/>React context<br/>[AuthContext.jsx]"]
end

subgraph group_api["FastAPI API"]
  node_server_main["Backend Registration<br/>FastAPI entry<br/>[main.py]"]
  node_api_contracts["API Schemas<br/>request/response contracts<br/>[schemas.py]"]
  node_api_routers["Product Routers<br/>FastAPI routers<br/>[projects.py]"]
end

subgraph group_analysis["Evidence Pipeline"]
  node_analyzer["Project Analyzer<br/>analysis orchestration<br/>[analyzer.py]"]
  node_language_rules["Language Evidence<br/>detectors and rules<br/>[python_analyzer.py]"]
  node_deep_analysis["Python Deep Analysis<br/>taint and AST analysis<br/>[python_taint.py]"]
  node_finding_quality["Grounding &amp; Scoring<br/>finding processing<br/>[grounding.py]"]
  node_patching["Patch Validation<br/>safe fix service<br/>[patching.py]"]
end

subgraph group_knowledge["Knowledge &amp; AI"]
  node_knowledge_retrieval["Curated Knowledge Retrieval<br/>hybrid retrieval<br/>[retrieval.py]"]
  node_project_retrieval["Project Context Retrieval<br/>repository retrieval<br/>[retrieval.py]"]
  node_reasoning["AI Reasoning<br/>prompt orchestration"]
end

subgraph group_storage["Data &amp; External Services"]
  node_mongodb[("MongoDB Atlas<br/>application and vector store")]
  node_groq{{"Groq<br/>LLM provider<br/>[groq_client.py]"}}
  node_embeddings["Embedding Services<br/>local vector embeddings<br/>[embeddings.py]"]
end

node_client_boot -->|"mounts"| node_app
node_app -->|"renders"| node_workspace_views
node_app -->|"uses"| node_auth_context
node_workspace_views -->|"calls"| node_api_client
node_api_client -->|"exchanges"| node_api_contracts
node_api_client -->|"HTTP"| node_server_main
node_server_main -->|"registers"| node_api_routers
node_api_routers -->|"validates with"| node_api_contracts
node_api_routers -->|"starts analysis"| node_analyzer
node_analyzer -->|"derives evidence"| node_language_rules
node_language_rules -->|"deepens Python evidence"| node_deep_analysis
node_analyzer -->|"submits findings"| node_finding_quality
node_deep_analysis -->|"adds evidence"| node_finding_quality
node_finding_quality -.->|"retrieves guidance"| node_knowledge_retrieval
node_api_routers -->|"retrieves project context"| node_project_retrieval
node_knowledge_retrieval -.->|"supplies guidance"| node_reasoning
node_project_retrieval -.->|"supplies context"| node_reasoning
node_reasoning -->|"LLM calls"| node_groq
node_reasoning -.->|"proposes patches"| node_patching
node_api_routers -->|"requests preview/apply"| node_patching
node_patching -->|"reanalysis after apply"| node_analyzer
node_knowledge_retrieval -->|"semantic search"| node_embeddings
node_embeddings -->|"vectors"| node_mongodb
node_api_routers -->|"projects and application data"| node_mongodb

click node_client_boot "https://github.com/prathamthatte52701/sage-hackathon/blob/main/client/src/main.jsx"
click node_app "https://github.com/prathamthatte52701/sage-hackathon/blob/main/client/src/App.jsx"
click node_api_client "https://github.com/prathamthatte52701/sage-hackathon/blob/main/client/src/api/client.js"
click node_workspace_views "https://github.com/prathamthatte52701/sage-hackathon/blob/main/client/src/components/CodeEditor.jsx"
click node_auth_context "https://github.com/prathamthatte52701/sage-hackathon/blob/main/client/src/context/AuthContext.jsx"
click node_server_main "https://github.com/prathamthatte52701/sage-hackathon/blob/main/server/main.py"
click node_api_contracts "https://github.com/prathamthatte52701/sage-hackathon/blob/main/server/models/schemas.py"
click node_api_routers "https://github.com/prathamthatte52701/sage-hackathon/blob/main/server/routers/projects.py"
click node_analyzer "https://github.com/prathamthatte52701/sage-hackathon/blob/main/server/services/analyzer.py"
click node_language_rules "https://github.com/prathamthatte52701/sage-hackathon/blob/main/server/services/analyzers/python_analyzer.py"
click node_deep_analysis "https://github.com/prathamthatte52701/sage-hackathon/blob/main/server/services/analyzers/python_taint.py"
click node_finding_quality "https://github.com/prathamthatte52701/sage-hackathon/blob/main/server/services/grounding.py"
click node_knowledge_retrieval "https://github.com/prathamthatte52701/sage-hackathon/blob/main/server/knowledge/retrieval.py"
click node_project_retrieval "https://github.com/prathamthatte52701/sage-hackathon/blob/main/server/services/retrieval.py"
click node_reasoning "https://github.com/prathamthatte52701/sage-hackathon/blob/main/server/services/reasoning_engine.py"
click node_patching "https://github.com/prathamthatte52701/sage-hackathon/blob/main/server/services/patching.py"
click node_groq "https://github.com/prathamthatte52701/sage-hackathon/blob/main/server/services/groq_client.py"
click node_embeddings "https://github.com/prathamthatte52701/sage-hackathon/blob/main/server/services/embeddings.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_client_boot,node_app,node_api_client,node_workspace_views,node_auth_context toneBlue
class node_server_main,node_api_contracts,node_api_routers toneAmber
class node_analyzer,node_language_rules,node_deep_analysis,node_finding_quality,node_patching toneMint
class node_knowledge_retrieval,node_project_retrieval,node_reasoning toneRose
class node_mongodb,node_groq,node_embeddings toneIndigo
```

## Components

### React Client

- [Client Bootstrap](https://github.com/prathamthatte52701/sage-hackathon/blob/main/client/src/main.jsx): Vite entry · `client/src/main.jsx`
- [Workspace App](https://github.com/prathamthatte52701/sage-hackathon/blob/main/client/src/App.jsx): React shell · Orchestrates review, projects, chat, and fixes. · `client/src/App.jsx`
- [API Client](https://github.com/prathamthatte52701/sage-hackathon/blob/main/client/src/api/client.js): transport contract · Central browser transport boundary. · `client/src/api/client.js`
- [Review & Fix Views](https://github.com/prathamthatte52701/sage-hackathon/blob/main/client/src/components/CodeEditor.jsx): stateful views · Code editor, project overview, and fix validation UI. · `client/src/components/CodeEditor.jsx`
- [Auth State](https://github.com/prathamthatte52701/sage-hackathon/blob/main/client/src/context/AuthContext.jsx): React context · `client/src/context/AuthContext.jsx`

### FastAPI API

- [Backend Registration](https://github.com/prathamthatte52701/sage-hackathon/blob/main/server/main.py): FastAPI entry · `server/main.py`
- [API Schemas](https://github.com/prathamthatte52701/sage-hackathon/blob/main/server/models/schemas.py): request/response contracts · Frontend/backend compatibility boundary. · `server/models/schemas.py`
- [Product Routers](https://github.com/prathamthatte52701/sage-hackathon/blob/main/server/routers/projects.py): FastAPI routers · Auth, review, projects, and explanation endpoints. · `server/routers/projects.py`

### Evidence Pipeline

- [Project Analyzer](https://github.com/prathamthatte52701/sage-hackathon/blob/main/server/services/analyzer.py): analysis orchestration · Extracts project structure and metadata. · `server/services/analyzer.py`
- [Language Evidence](https://github.com/prathamthatte52701/sage-hackathon/blob/main/server/services/analyzers/python_analyzer.py): detectors and rules · Python and JavaScript detection with rule definitions. · `server/services/analyzers/python_analyzer.py`
- [Python Deep Analysis](https://github.com/prathamthatte52701/sage-hackathon/blob/main/server/services/analyzers/python_taint.py): taint and AST analysis · Adds taint tracking and structural evidence where applicable. · `server/services/analyzers/python_taint.py`
- [Grounding & Scoring](https://github.com/prathamthatte52701/sage-hackathon/blob/main/server/services/grounding.py): finding processing · Deduplicates, grounds, and scores findings. · `server/services/grounding.py`
- [Patch Validation](https://github.com/prathamthatte52701/sage-hackathon/blob/main/server/services/patching.py): safe fix service · Validates precise preview patches before application. · `server/services/patching.py`

### Knowledge & AI

- [Curated Knowledge Retrieval](https://github.com/prathamthatte52701/sage-hackathon/blob/main/server/knowledge/retrieval.py): hybrid retrieval · Uses rule/category evidence before semantic matches. · `server/knowledge/retrieval.py`
- [Project Context Retrieval](https://github.com/prathamthatte52701/sage-hackathon/blob/main/server/services/retrieval.py): repository retrieval · Separate project-context and chat retrieval concern. · `server/services/retrieval.py`
- [AI Reasoning](https://github.com/prathamthatte52701/sage-hackathon/blob/main/server/services/reasoning_engine.py): prompt orchestration · Produces explanations, quality review, chat, and patch proposals. · `server/services/reasoning_engine.py`

### Data & External Services

- **MongoDB Atlas**: application and vector store · Stores project data and sage_knowledge vectors.
- [Groq](https://github.com/prathamthatte52701/sage-hackathon/blob/main/server/services/groq_client.py): LLM provider · Isolated LLM integration for non-authoritative reasoning. · `server/services/groq_client.py`
- [Embedding Services](https://github.com/prathamthatte52701/sage-hackathon/blob/main/server/services/embeddings.py): local vector embeddings · Generates 384-dimensional embeddings with fallback behavior. · `server/services/embeddings.py`

## Connections

- Client Bootstrap → Workspace App: mounts
- Workspace App → Review & Fix Views: renders
- Workspace App → Auth State: uses
- Review & Fix Views → API Client: calls
- API Client → API Schemas: exchanges
- API Client → Backend Registration: HTTP
- Backend Registration → Product Routers: registers
- Product Routers → API Schemas: validates with
- Product Routers → Project Analyzer: starts analysis
- Project Analyzer → Language Evidence: derives evidence
- Language Evidence → Python Deep Analysis: deepens Python evidence
- Project Analyzer → Grounding & Scoring: submits findings
- Python Deep Analysis → Grounding & Scoring: adds evidence
- Grounding & Scoring → Curated Knowledge Retrieval: retrieves guidance · Guidance informs recommendations, not finding proof.
- Product Routers → Project Context Retrieval: retrieves project context
- Curated Knowledge Retrieval → AI Reasoning: supplies guidance
- Project Context Retrieval → AI Reasoning: supplies context
- AI Reasoning → Groq: LLM calls
- AI Reasoning → Patch Validation: proposes patches
- Product Routers → Patch Validation: requests preview/apply
- Patch Validation → Project Analyzer: reanalysis after apply
- Curated Knowledge Retrieval → Embedding Services: semantic search
- Embedding Services → MongoDB Atlas: vectors
- Product Routers → MongoDB Atlas: projects and application data
