# bhargavi1045/repolens architecture

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

- Interactive diagram: https://gitdiagram.com/bhargavi1045/repolens
- Repository: https://github.com/bhargavi1045/repolens

## Overview

#### Purpose and Entry Points
RepoLens is a full-stack GitHub repository analysis product. Users authenticate, submit repositories, and request RAG-grounded explanations, architecture/workflow outputs, test suggestions, improvements, and static health analysis. Backend startup is `backend/server.ts`, which composes Express from `backend/src/app.ts`; the frontend is a Next.js application rooted at `frontend/app/layout.tsx` and `frontend/app/page.tsx`.

#### Client Application
The Next.js frontend provides landing/authentication and an authenticated analysis workspace. The dashboard combines repository navigation, source viewing, and AI output panels, calling the backend through a centralized client API layer.
- `frontend/app/dashboard/page.tsx`
- `frontend/components/dashboard/FileTree.tsx`
- `frontend/components/dashboard/AiPanel.tsx`
- `frontend/lib/api.ts`

#### HTTP API and Request Boundary
Express routes separate authentication, repository lifecycle, and analysis features. Controllers implement request orchestration; middleware applies JWT protection, ingestion preconditions, validation, rate limiting, and centralized error handling. This is the primary boundary between browser state and backend processing.
- `backend/src/api/routes/index.ts`
- `backend/src/api/controllers/repo.controller.ts`
- `backend/src/api/controllers/analysis.controller.ts`
- `backend/src/api/middleware/auth.middleware.ts`
- `backend/src/api/middleware/ensureIngested.ts`

#### Repository Ingestion Pipeline
Repository ingestion fetches GitHub content, parses files, splits source into retrievable chunks, creates embeddings, and persists indexing state. AST-aware chunking is an architectural differentiator: it preserves function/class boundaries versus fixed-size chunks. Ingestion bridges GitHub’s external API and Pinecone’s vector index.
- `backend/src/services/ingest.service.ts`
- `backend/src/services/github.service.ts`
- `backend/src/services/astChunking.service.ts`
- `backend/src/services/embedding.service.ts`
- `backend/src/services/pinecone.service.ts`

#### RAG and LLM Analysis Engine
Feature requests retrieve semantically similar indexed chunks, build feature-specific prompts, then ask Groq-backed LLM services for structured results. Supported outputs include file explanation, architecture diagrams, workflows, unit tests, and improvement recommendations. Mermaid output is extracted/sanitized before reaching the UI.
- `backend/src/services/rag.service.ts`
- `backend/src/services/askRepo.service.ts`
- `backend/src/services/llm.service.ts`
- `backend/src/prompts/architecture.prompt.ts`
- `backend/src/utils/extractMermaidDiagram.ts`

#### Persistence, Identity, and Caching
MongoDB stores users, repositories, chunks/metadata, analyses, evaluations, and cached results. JWT issuance and verification support protected backend endpoints; the frontend has route handlers for cookie management and middleware for access control. Cache persistence reduces repeated AI/retrieval work.
- `backend/src/config/db.ts`
- `backend/src/models/User.model.ts`
- `backend/src/models/Repo.model.ts`
- `backend/src/models/Cache.model.ts`
- `backend/src/utils/jwt.ts`

#### Static Analysis and Evaluation
A second insight path runs ESLint-based quality analysis and converts findings into health-oriented results. The evaluation subsystem benchmarks retrieval/chunking and LLM faithfulness, enabling comparison between fixed and AST chunking strategies independently of interactive UI requests.
- `backend/src/services/analysis.service.ts`
- `backend/src/services/eslint.service.ts`
- `backend/src/services/evaluation.service.ts`
- `backend/src/services/evaluationRunner.service.ts`
- `backend/src/eval/testDataset.ts`

#### Runtime and External Infrastructure
The system runs a Node.js/Express TypeScript backend and Next.js/Tailwind TypeScript frontend. Material managed dependencies are GitHub for repository source, Cohere for embeddings, Pinecone for vector similarity search, Groq for generation, MongoDB Atlas for operational data, and email delivery through `backend/src/services/email.service.ts`. Deployment targets are Vercel (frontend) and Render (backend).

Main entry points: [`frontend/app/dashboard/page.tsx`](https://github.com/bhargavi1045/repolens/blob/main/frontend/app/dashboard/page.tsx) (Analysis dashboard), [`backend/src/api/controllers/analysis.controller.ts`](https://github.com/bhargavi1045/repolens/blob/main/backend/src/api/controllers/analysis.controller.ts) (Analysis controller), [`backend/src/api/middleware/auth.middleware.ts`](https://github.com/bhargavi1045/repolens/blob/main/backend/src/api/middleware/auth.middleware.ts) (Request guards), [`backend/src/api/controllers/repo.controller.ts`](https://github.com/bhargavi1045/repolens/blob/main/backend/src/api/controllers/repo.controller.ts) (Repository controller)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_client["Client application"]
  node_next_app["Next.js app<br/>frontend runtime<br/>[layout.tsx]"]
  node_dashboard["Analysis dashboard<br/>workspace UI<br/>[page.tsx]"]
  node_file_tree["Repository navigator<br/>dashboard component<br/>[FileTree.tsx]"]
  node_ai_panel["AI output panel<br/>dashboard component<br/>[AiPanel.tsx]"]
  node_client_api["Backend API client<br/>client API layer<br/>[api.ts]"]
end

subgraph group_backend["Backend API"]
  node_express_app["Express application<br/>backend runtime<br/>[app.ts]"]
  node_api_routes["API routes<br/>HTTP routing<br/>[index.ts]"]
  node_request_guards["Request guards<br/>middleware<br/>[auth.middleware.ts]"]
  node_repo_controller["Repository controller<br/>request controller<br/>[repo.controller.ts]"]
  node_analysis_controller["Analysis controller<br/>request controller"]
end

subgraph group_pipeline["Ingestion and AI"]
  node_ingestion["Repository ingestion<br/>pipeline orchestrator<br/>[ingest.service.ts]"]
  node_ast_chunking["AST-aware chunking<br/>source chunker"]
  node_embeddings["Embedding service<br/>embedding client"]
  node_rag["RAG retrieval<br/>retrieval service<br/>[rag.service.ts]"]
  node_llm_analysis["LLM analysis engine<br/>generation service<br/>[llm.service.ts]"]
  node_static_analysis["Static health analysis<br/>quality analysis service"]
  node_evaluation["Evaluation runner<br/>benchmark subsystem"]
end

subgraph group_data["Data and external services"]
  node_github_source{{"GitHub source API<br/>external source<br/>[github.service.ts]"}}
  node_pinecone[("Pinecone vector index<br/>vector database")]
  node_mongodb[("MongoDB Atlas<br/>operational database<br/>[db.ts]")]
  node_groq{{"Groq<br/>LLM provider"}}
end

node_next_app -->|"renders"| node_dashboard
node_dashboard -->|"shows"| node_file_tree
node_dashboard -->|"shows"| node_ai_panel
node_dashboard -->|"requests"| node_client_api
node_client_api -->|"HTTP"| node_express_app
node_express_app -->|"mounts"| node_api_routes
node_api_routes -->|"applies"| node_request_guards
node_request_guards -->|"authorizes"| node_repo_controller
node_request_guards -->|"authorizes"| node_analysis_controller
node_repo_controller -->|"ingests repository"| node_ingestion
node_analysis_controller -->|"requests grounded analysis"| node_rag
node_analysis_controller -->|"requests health analysis"| node_static_analysis
node_ingestion -->|"fetches files"| node_github_source
node_ingestion -->|"chunks source"| node_ast_chunking
node_ast_chunking -->|"chunks"| node_embeddings
node_embeddings -->|"indexes vectors"| node_pinecone
node_rag -->|"retrieves similar chunks"| node_pinecone
node_rag -->|"supplies context"| node_llm_analysis
node_llm_analysis -->|"generates via"| node_groq
node_repo_controller -->|"persists repository state"| node_mongodb
node_analysis_controller -->|"reads and caches results"| node_mongodb
node_evaluation -.->|"compares against fixed chunking"| node_ast_chunking
node_evaluation -.->|"measures faithfulness"| node_llm_analysis

click node_next_app "https://github.com/bhargavi1045/repolens/blob/main/frontend/app/layout.tsx"
click node_dashboard "https://github.com/bhargavi1045/repolens/blob/main/frontend/app/dashboard/page.tsx"
click node_file_tree "https://github.com/bhargavi1045/repolens/blob/main/frontend/components/dashboard/FileTree.tsx"
click node_ai_panel "https://github.com/bhargavi1045/repolens/blob/main/frontend/components/dashboard/AiPanel.tsx"
click node_client_api "https://github.com/bhargavi1045/repolens/blob/main/frontend/lib/api.ts"
click node_express_app "https://github.com/bhargavi1045/repolens/blob/main/backend/src/app.ts"
click node_api_routes "https://github.com/bhargavi1045/repolens/blob/main/backend/src/api/routes/index.ts"
click node_request_guards "https://github.com/bhargavi1045/repolens/blob/main/backend/src/api/middleware/auth.middleware.ts"
click node_repo_controller "https://github.com/bhargavi1045/repolens/blob/main/backend/src/api/controllers/repo.controller.ts"
click node_analysis_controller "https://github.com/bhargavi1045/repolens/blob/main/backend/src/api/controllers/analysis.controller.ts"
click node_ingestion "https://github.com/bhargavi1045/repolens/blob/main/backend/src/services/ingest.service.ts"
click node_github_source "https://github.com/bhargavi1045/repolens/blob/main/backend/src/services/github.service.ts"
click node_ast_chunking "https://github.com/bhargavi1045/repolens/blob/main/backend/src/services/astChunking.service.ts"
click node_embeddings "https://github.com/bhargavi1045/repolens/blob/main/backend/src/services/embedding.service.ts"
click node_pinecone "https://github.com/bhargavi1045/repolens/blob/main/backend/src/services/pinecone.service.ts"
click node_rag "https://github.com/bhargavi1045/repolens/blob/main/backend/src/services/rag.service.ts"
click node_llm_analysis "https://github.com/bhargavi1045/repolens/blob/main/backend/src/services/llm.service.ts"
click node_static_analysis "https://github.com/bhargavi1045/repolens/blob/main/backend/src/services/analysis.service.ts"
click node_evaluation "https://github.com/bhargavi1045/repolens/blob/main/backend/src/services/evaluationRunner.service.ts"
click node_mongodb "https://github.com/bhargavi1045/repolens/blob/main/backend/src/config/db.ts"

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_next_app,node_dashboard,node_file_tree,node_ai_panel,node_client_api toneBlue
class node_express_app,node_api_routes,node_request_guards,node_repo_controller,node_analysis_controller toneAmber
class node_ingestion,node_ast_chunking,node_embeddings,node_rag,node_llm_analysis,node_static_analysis,node_evaluation toneMint
class node_github_source,node_pinecone,node_mongodb,node_groq toneRose
```

## Components

### Client application

- [Next.js app](https://github.com/bhargavi1045/repolens/blob/main/frontend/app/layout.tsx): frontend runtime · Landing, authentication, and protected workspace. · `frontend/app/layout.tsx`
- [Analysis dashboard](https://github.com/bhargavi1045/repolens/blob/main/frontend/app/dashboard/page.tsx): workspace UI · Combines repository navigation, source viewing, and AI outputs. · `frontend/app/dashboard/page.tsx`
- [Repository navigator](https://github.com/bhargavi1045/repolens/blob/main/frontend/components/dashboard/FileTree.tsx): dashboard component · `frontend/components/dashboard/FileTree.tsx`
- [AI output panel](https://github.com/bhargavi1045/repolens/blob/main/frontend/components/dashboard/AiPanel.tsx): dashboard component · `frontend/components/dashboard/AiPanel.tsx`
- [Backend API client](https://github.com/bhargavi1045/repolens/blob/main/frontend/lib/api.ts): client API layer · `frontend/lib/api.ts`

### Backend API

- [Express application](https://github.com/bhargavi1045/repolens/blob/main/backend/src/app.ts): backend runtime · Composed by the server entry point. · `backend/src/app.ts`
- [API routes](https://github.com/bhargavi1045/repolens/blob/main/backend/src/api/routes/index.ts): HTTP routing · Separates authentication, repository, and analysis endpoints. · `backend/src/api/routes/index.ts`
- [Request guards](https://github.com/bhargavi1045/repolens/blob/main/backend/src/api/middleware/auth.middleware.ts): middleware · JWT protection and ingestion preconditions. · `backend/src/api/middleware/auth.middleware.ts`
- [Repository controller](https://github.com/bhargavi1045/repolens/blob/main/backend/src/api/controllers/repo.controller.ts): request controller · `backend/src/api/controllers/repo.controller.ts`
- [Analysis controller](https://github.com/bhargavi1045/repolens/blob/main/backend/src/api/controllers/analysis.controller.ts): request controller · `backend/src/api/controllers/analysis.controller.ts`

### Ingestion and AI

- [Repository ingestion](https://github.com/bhargavi1045/repolens/blob/main/backend/src/services/ingest.service.ts): pipeline orchestrator · Fetches, chunks, embeds, and indexes repository content. · `backend/src/services/ingest.service.ts`
- [AST-aware chunking](https://github.com/bhargavi1045/repolens/blob/main/backend/src/services/astChunking.service.ts): source chunker · Preserves function and class boundaries. · `backend/src/services/astChunking.service.ts`
- [Embedding service](https://github.com/bhargavi1045/repolens/blob/main/backend/src/services/embedding.service.ts): embedding client · Uses Cohere embeddings. · `backend/src/services/embedding.service.ts`
- [RAG retrieval](https://github.com/bhargavi1045/repolens/blob/main/backend/src/services/rag.service.ts): retrieval service · Retrieves indexed chunks and builds grounded context. · `backend/src/services/rag.service.ts`
- [LLM analysis engine](https://github.com/bhargavi1045/repolens/blob/main/backend/src/services/llm.service.ts): generation service · Produces explanations, diagrams, workflows, tests, and recommendations. · `backend/src/services/llm.service.ts`
- [Static health analysis](https://github.com/bhargavi1045/repolens/blob/main/backend/src/services/analysis.service.ts): quality analysis service · Runs ESLint-based repository health analysis. · `backend/src/services/analysis.service.ts`
- [Evaluation runner](https://github.com/bhargavi1045/repolens/blob/main/backend/src/services/evaluationRunner.service.ts): benchmark subsystem · Compares chunking, retrieval, and LLM faithfulness. · `backend/src/services/evaluationRunner.service.ts`

### Data and external services

- [GitHub source API](https://github.com/bhargavi1045/repolens/blob/main/backend/src/services/github.service.ts): external source · `backend/src/services/github.service.ts`
- [Pinecone vector index](https://github.com/bhargavi1045/repolens/blob/main/backend/src/services/pinecone.service.ts): vector database · `backend/src/services/pinecone.service.ts`
- [MongoDB Atlas](https://github.com/bhargavi1045/repolens/blob/main/backend/src/config/db.ts): operational database · Stores users, repositories, analyses, evaluations, and caches. · `backend/src/config/db.ts`
- **Groq**: LLM provider

## Connections

- Next.js app → Analysis dashboard: renders
- Analysis dashboard → Repository navigator: shows
- Analysis dashboard → AI output panel: shows
- Analysis dashboard → Backend API client: requests
- Backend API client → Express application: HTTP
- Express application → API routes: mounts
- API routes → Request guards: applies
- Request guards → Repository controller: authorizes
- Request guards → Analysis controller: authorizes
- Repository controller → Repository ingestion: ingests repository
- Analysis controller → RAG retrieval: requests grounded analysis
- Analysis controller → Static health analysis: requests health analysis
- Repository ingestion → GitHub source API: fetches files
- Repository ingestion → AST-aware chunking: chunks source
- AST-aware chunking → Embedding service: chunks
- Embedding service → Pinecone vector index: indexes vectors
- RAG retrieval → Pinecone vector index: retrieves similar chunks
- RAG retrieval → LLM analysis engine: supplies context
- LLM analysis engine → Groq: generates via
- Repository controller → MongoDB Atlas: persists repository state
- Analysis controller → MongoDB Atlas: reads and caches results
- Evaluation runner → AST-aware chunking: compares against fixed chunking
- Evaluation runner → LLM analysis engine: measures faithfulness
