# krishna-kumargupta/smart-code-reviewer architecture

> Architecture diagram of the GitHub repository krishna-kumargupta/smart-code-reviewer, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2026-07-19). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/krishna-kumargupta/smart-code-reviewer
- Repository: https://github.com/krishna-kumargupta/smart-code-reviewer

## Overview

#### Purpose and System Shape
Smart Code Reviewer automates GitHub pull-request analysis and feedback. The repository contains four deployable concerns: a React dashboard, a Node API/GitHub integration layer, a Node webhook ingress/queue service, and a Python FastAPI/Celery review worker. The Python `review-agent` is the primary analysis pipeline described by the README.

#### User Application and API Boundary
The browser application boots at `frontend/src/main.jsx` and routes from `frontend/src/App.jsx`. It uses Supabase-backed authentication via `frontend/src/context/AuthContext.jsx`, protects dashboard/admin areas through `frontend/src/layouts/ProtectedRoute.jsx` and `frontend/src/layouts/AdminRoute.jsx`, and calls backend/GitHub/review endpoints through `frontend/src/services/api.js`, `frontend/src/services/github.api.js`, and `frontend/src/services/reviewService.js`.

The Node backend entry point is `backend/server.js`. It exposes profile, admin, review, and GitHub routes (`backend/src/routes/review.routes.js`, `backend/src/routes/profile.js`, `backend/src/github/routes/githubRoutes.js`) with JWT and admin middleware at `backend/src/middleware/verifyJWT.js` and `backend/src/middleware/isAdmin.js`.

#### Identity, Persistence, and Repository Connection
Supabase/PostgreSQL is the shared application persistence and authentication boundary. Backend access is configured in `backend/src/config/supabase.js` and privileged service access in `backend/src/services/supabaseAdmin.js`; schema evolution is captured in `supabase/schema.sql` and `supabase/migrations/002_github_accounts.sql`.

GitHub OAuth/token and repository lifecycle logic are concentrated under `backend/src/github/services/githubOAuthService.js`, `backend/src/github/services/githubTokenService.js`, and `backend/src/github/services/githubRepositorySyncService.js`. This layer maps authenticated application users to GitHub accounts, access tokens, tracked repositories, and webhook setup.

#### GitHub Event Ingress and Dispatch
There are two webhook-facing implementations: GitHub integration routes in the backend (`backend/src/github/routes/githubWebhookRoutes.js`) and a dedicated webhook service rooted at `webhook-service/server.js`. The dedicated service verifies GitHub signatures in `webhook-service/src/utils/githubWebhookVerifier.js`, handles events in `webhook-service/src/controllers/webhookController.js`, and enqueues accepted work through `webhook-service/src/services/webhookQueueService.js`.

Redis is therefore the asynchronous handoff boundary between short-lived webhook processing and review execution; its connection configuration is `webhook-service/src/config/redis.js`. GitHub webhook authenticity must be established before queueing.

#### Review-Agent Runtime and Task Orchestration
The Python service starts at `review-agent/app/main.py`. It has service authentication middleware in `review-agent/app/auth/middleware.py`, application configuration in `review-agent/app/config.py`, and a Celery application in `review-agent/app/celery_app.py`. `review-agent/app/tasks.py` defines background review execution, allowing webhook/API requests to return independently of repository analysis.

The worker has its own database models/session boundary at `review-agent/app/db/models.py` and `review-agent/app/db/session.py`; integration or ownership relative to Supabase should be treated as a deployment/data-contract decision.

#### Review Pipeline
A queued PR review fetches repository and diff context through `review-agent/app/repo/fetch.py` and `review-agent/app/repo/diff.py`. It then limits/analyzes changed-code context using the impact slicer (`review-agent/app/slicing/graph.py`, `review-agent/app/slicing/budget.py`, `review-agent/app/slicing/symbols.py`).

Parallel or composed analysis domains include structural checks and circular dependency detection (`review-agent/app/structure/checker.py`, `review-agent/app/structure/circular_deps.py`) plus dependency vulnerability scanning through OSV (`review-agent/app/vuln/osv_runner.py`, `review-agent/app/vuln/osv_parser.py`). Language-specific structural rules live in `review-agent/app/structure/rules/`.

AI review is orchestrated with LangGraph in `review-agent/app/review/langgraph_review.py`, using model access in `review-agent/app/review/llm_client.py` and prompts in `review-agent/app/review/prompts.py`. Findings are scored and rendered into a unified report by `review-agent/app/merge/scorer.py` and `review-agent/app/merge/report.py`.

#### Outputs and External Services
The worker publishes completed review feedback back to GitHub through `review-agent/app/notify/github_comment.py`; optional email notification is isolated in `review-agent/app/notify/email_client.py`. Material external dependencies are GitHub OAuth/API/webhooks, OpenAI-compatible LLM access, OSV Scanner, Redis/Celery, and PostgreSQL/Supabase. Container composition begins at `docker-compose.yml`, while the review worker’s container contract is `review-agent/Dockerfile`.

Main entry points: [`backend/server.js`](https://github.com/krishna-kumargupta/smart-code-reviewer/blob/main/backend/server.js) (Node API), [`backend/src/github/services/githubOAuthService.js`](https://github.com/krishna-kumargupta/smart-code-reviewer/blob/main/backend/src/github/services/githubOAuthService.js) (GitHub account lifecycle), [`review-agent/app/repo/fetch.py`](https://github.com/krishna-kumargupta/smart-code-reviewer/blob/main/review-agent/app/repo/fetch.py) (Repository and diff fetch), [`review-agent/app/slicing/graph.py`](https://github.com/krishna-kumargupta/smart-code-reviewer/blob/main/review-agent/app/slicing/graph.py) (Impact slicing)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_frontend["Dashboard"]
  node_browser["React application<br/>browser UI<br/>[main.jsx]"]
  node_frontend_auth["Auth and route guards<br/>frontend auth<br/>[AuthContext.jsx]"]
  node_frontend_api["API clients<br/>frontend service<br/>[api.js]"]
end

subgraph group_backend["Node API &amp; GitHub"]
  node_node_api["Node API<br/>Express service<br/>[server.js]"]
  node_api_auth["JWT and admin guard<br/>API middleware<br/>[verifyJWT.js]"]
  node_github_lifecycle["GitHub account lifecycle<br/>GitHub service"]
  node_backend_webhook["Backend webhook routes<br/>webhook endpoint"]
end

subgraph group_ingress["Webhook Ingress"]
  node_webhook_service["Webhook service<br/>Node ingress service<br/>[server.js]"]
  node_webhook_verify["Signature verification<br/>webhook security"]
  node_webhook_queue["Event queue publisher<br/>queue producer"]
end

subgraph group_review["Review Agent"]
  node_review_api["FastAPI review service<br/>Python API<br/>[main.py]"]
  node_celery_tasks["Celery review tasks<br/>task worker<br/>[tasks.py]"]
  node_repo_context["Repository and diff fetch<br/>review pipeline<br/>[fetch.py]"]
  node_impact_slice["Impact slicing<br/>analysis stage<br/>[graph.py]"]
  node_static_analysis["Structure and vulnerability checks<br/>analysis stage<br/>[checker.py]"]
  node_ai_review["LangGraph AI review<br/>LLM orchestration"]
  node_report["Scoring and report<br/>review output<br/>[report.py]"]
  node_github_notify["GitHub feedback publisher<br/>notification adapter<br/>[github_comment.py]"]
end

node_supabase[("Supabase / PostgreSQL<br/>identity and persistence<br/>[schema.sql]")]
node_github{{"GitHub<br/>external platform"}}
node_redis["Redis<br/>async broker<br/>[redis.js]"]
node_llm_osv{{"LLM and OSV Scanner<br/>analysis providers"}}

node_browser -->|"authenticates"| node_frontend_auth
node_frontend_auth -->|"Supabase auth"| node_supabase
node_browser -->|"invokes"| node_frontend_api
node_frontend_api -->|"API requests"| node_node_api
node_node_api -->|"protects routes"| node_api_auth
node_node_api -->|"profiles and app data"| node_supabase
node_node_api -->|"GitHub routes"| node_github_lifecycle
node_github_lifecycle -->|"OAuth, tokens, repositories"| node_github
node_github_lifecycle -->|"account and repository mapping"| node_supabase
node_github -.->|"webhook events"| node_backend_webhook
node_github -->|"webhook events"| node_webhook_service
node_webhook_service -->|"verifies first"| node_webhook_verify
node_webhook_verify -->|"accepted event"| node_webhook_queue
node_webhook_queue -->|"enqueue"| node_redis
node_redis -->|"dispatch review"| node_celery_tasks
node_review_api -->|"starts tasks"| node_celery_tasks
node_celery_tasks -->|"fetch PR context"| node_repo_context
node_repo_context -->|"repository and diff API"| node_github
node_repo_context -->|"changed context"| node_impact_slice
node_impact_slice -->|"bounded code context"| node_static_analysis
node_impact_slice -->|"bounded code context"| node_ai_review
node_static_analysis -->|"OSV vulnerability scan"| node_llm_osv
node_ai_review -->|"model inference"| node_llm_osv
node_static_analysis -->|"findings"| node_report
node_ai_review -->|"findings"| node_report
node_report -->|"completed feedback"| node_github_notify
node_github_notify -->|"PR comments"| node_github

click node_browser "https://github.com/krishna-kumargupta/smart-code-reviewer/blob/main/frontend/src/main.jsx"
click node_frontend_auth "https://github.com/krishna-kumargupta/smart-code-reviewer/blob/main/frontend/src/context/AuthContext.jsx"
click node_frontend_api "https://github.com/krishna-kumargupta/smart-code-reviewer/blob/main/frontend/src/services/api.js"
click node_node_api "https://github.com/krishna-kumargupta/smart-code-reviewer/blob/main/backend/server.js"
click node_api_auth "https://github.com/krishna-kumargupta/smart-code-reviewer/blob/main/backend/src/middleware/verifyJWT.js"
click node_github_lifecycle "https://github.com/krishna-kumargupta/smart-code-reviewer/blob/main/backend/src/github/services/githubOAuthService.js"
click node_backend_webhook "https://github.com/krishna-kumargupta/smart-code-reviewer/blob/main/backend/src/github/routes/githubWebhookRoutes.js"
click node_webhook_service "https://github.com/krishna-kumargupta/smart-code-reviewer/blob/main/webhook-service/server.js"
click node_webhook_verify "https://github.com/krishna-kumargupta/smart-code-reviewer/blob/main/webhook-service/src/utils/githubWebhookVerifier.js"
click node_webhook_queue "https://github.com/krishna-kumargupta/smart-code-reviewer/blob/main/webhook-service/src/services/webhookQueueService.js"
click node_review_api "https://github.com/krishna-kumargupta/smart-code-reviewer/blob/main/review-agent/app/main.py"
click node_celery_tasks "https://github.com/krishna-kumargupta/smart-code-reviewer/blob/main/review-agent/app/tasks.py"
click node_repo_context "https://github.com/krishna-kumargupta/smart-code-reviewer/blob/main/review-agent/app/repo/fetch.py"
click node_impact_slice "https://github.com/krishna-kumargupta/smart-code-reviewer/blob/main/review-agent/app/slicing/graph.py"
click node_static_analysis "https://github.com/krishna-kumargupta/smart-code-reviewer/blob/main/review-agent/app/structure/checker.py"
click node_ai_review "https://github.com/krishna-kumargupta/smart-code-reviewer/blob/main/review-agent/app/review/langgraph_review.py"
click node_report "https://github.com/krishna-kumargupta/smart-code-reviewer/blob/main/review-agent/app/merge/report.py"
click node_github_notify "https://github.com/krishna-kumargupta/smart-code-reviewer/blob/main/review-agent/app/notify/github_comment.py"
click node_supabase "https://github.com/krishna-kumargupta/smart-code-reviewer/blob/main/supabase/schema.sql"
click node_redis "https://github.com/krishna-kumargupta/smart-code-reviewer/blob/main/webhook-service/src/config/redis.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_browser,node_frontend_auth,node_frontend_api toneBlue
class node_node_api,node_api_auth,node_github_lifecycle,node_backend_webhook toneAmber
class node_webhook_service,node_webhook_verify,node_webhook_queue toneMint
class node_review_api,node_celery_tasks,node_repo_context,node_impact_slice,node_static_analysis,node_ai_review,node_report,node_github_notify toneRose
class node_supabase,node_github,node_redis,node_llm_osv toneNeutral
```

## Components

### Dashboard

- [React application](https://github.com/krishna-kumargupta/smart-code-reviewer/blob/main/frontend/src/main.jsx): browser UI · Authenticated dashboard for review and repository workflows. · `frontend/src/main.jsx`
- [Auth and route guards](https://github.com/krishna-kumargupta/smart-code-reviewer/blob/main/frontend/src/context/AuthContext.jsx): frontend auth · `frontend/src/context/AuthContext.jsx`
- [API clients](https://github.com/krishna-kumargupta/smart-code-reviewer/blob/main/frontend/src/services/api.js): frontend service · `frontend/src/services/api.js`

### Node API & GitHub

- [Node API](https://github.com/krishna-kumargupta/smart-code-reviewer/blob/main/backend/server.js): Express service · Profiles, administration, review, and GitHub endpoints. · `backend/server.js`
- [JWT and admin guard](https://github.com/krishna-kumargupta/smart-code-reviewer/blob/main/backend/src/middleware/verifyJWT.js): API middleware · `backend/src/middleware/verifyJWT.js`
- [GitHub account lifecycle](https://github.com/krishna-kumargupta/smart-code-reviewer/blob/main/backend/src/github/services/githubOAuthService.js): GitHub service · Manages OAuth tokens, tracked repositories, and webhook setup. · `backend/src/github/services/githubOAuthService.js`
- [Backend webhook routes](https://github.com/krishna-kumargupta/smart-code-reviewer/blob/main/backend/src/github/routes/githubWebhookRoutes.js): webhook endpoint · `backend/src/github/routes/githubWebhookRoutes.js`

### Webhook Ingress

- [Webhook service](https://github.com/krishna-kumargupta/smart-code-reviewer/blob/main/webhook-service/server.js): Node ingress service · Short-lived GitHub event receiver and dispatcher. · `webhook-service/server.js`
- [Signature verification](https://github.com/krishna-kumargupta/smart-code-reviewer/blob/main/webhook-service/src/utils/githubWebhookVerifier.js): webhook security · `webhook-service/src/utils/githubWebhookVerifier.js`
- [Event queue publisher](https://github.com/krishna-kumargupta/smart-code-reviewer/blob/main/webhook-service/src/services/webhookQueueService.js): queue producer · `webhook-service/src/services/webhookQueueService.js`

### Review Agent

- [FastAPI review service](https://github.com/krishna-kumargupta/smart-code-reviewer/blob/main/review-agent/app/main.py): Python API · Authenticated review runtime and task entry point. · `review-agent/app/main.py`
- [Celery review tasks](https://github.com/krishna-kumargupta/smart-code-reviewer/blob/main/review-agent/app/tasks.py): task worker · Runs reviews independently of request handling. · `review-agent/app/tasks.py`
- [Repository and diff fetch](https://github.com/krishna-kumargupta/smart-code-reviewer/blob/main/review-agent/app/repo/fetch.py): review pipeline · `review-agent/app/repo/fetch.py`
- [Impact slicing](https://github.com/krishna-kumargupta/smart-code-reviewer/blob/main/review-agent/app/slicing/graph.py): analysis stage · Bounds changed-code context before analysis. · `review-agent/app/slicing/graph.py`
- [Structure and vulnerability checks](https://github.com/krishna-kumargupta/smart-code-reviewer/blob/main/review-agent/app/structure/checker.py): analysis stage · Combines structural rules, dependency cycles, and OSV scanning. · `review-agent/app/structure/checker.py`
- [LangGraph AI review](https://github.com/krishna-kumargupta/smart-code-reviewer/blob/main/review-agent/app/review/langgraph_review.py): LLM orchestration · `review-agent/app/review/langgraph_review.py`
- [Scoring and report](https://github.com/krishna-kumargupta/smart-code-reviewer/blob/main/review-agent/app/merge/report.py): review output · `review-agent/app/merge/report.py`
- [GitHub feedback publisher](https://github.com/krishna-kumargupta/smart-code-reviewer/blob/main/review-agent/app/notify/github_comment.py): notification adapter · `review-agent/app/notify/github_comment.py`

### Other components

- [Supabase / PostgreSQL](https://github.com/krishna-kumargupta/smart-code-reviewer/blob/main/supabase/schema.sql): identity and persistence · Shared application authentication and persistence boundary. · `supabase/schema.sql`
- **GitHub**: external platform · OAuth, repositories, pull requests, and webhook source.
- [Redis](https://github.com/krishna-kumargupta/smart-code-reviewer/blob/main/webhook-service/src/config/redis.js): async broker · Queue handoff and Celery broker. · `webhook-service/src/config/redis.js`
- **LLM and OSV Scanner**: analysis providers

## Connections

- React application → Auth and route guards: authenticates
- Auth and route guards → Supabase / PostgreSQL: Supabase auth
- React application → API clients: invokes
- API clients → Node API: API requests
- Node API → JWT and admin guard: protects routes
- Node API → Supabase / PostgreSQL: profiles and app data
- Node API → GitHub account lifecycle: GitHub routes
- GitHub account lifecycle → GitHub: OAuth, tokens, repositories
- GitHub account lifecycle → Supabase / PostgreSQL: account and repository mapping
- GitHub → Backend webhook routes: webhook events
- GitHub → Webhook service: webhook events
- Webhook service → Signature verification: verifies first
- Signature verification → Event queue publisher: accepted event
- Event queue publisher → Redis: enqueue
- Redis → Celery review tasks: dispatch review
- FastAPI review service → Celery review tasks: starts tasks
- Celery review tasks → Repository and diff fetch: fetch PR context
- Repository and diff fetch → GitHub: repository and diff API
- Repository and diff fetch → Impact slicing: changed context
- Impact slicing → Structure and vulnerability checks: bounded code context
- Impact slicing → LangGraph AI review: bounded code context
- Structure and vulnerability checks → LLM and OSV Scanner: OSV vulnerability scan
- LangGraph AI review → LLM and OSV Scanner: model inference
- Structure and vulnerability checks → Scoring and report: findings
- LangGraph AI review → Scoring and report: findings
- Scoring and report → GitHub feedback publisher: completed feedback
- GitHub feedback publisher → GitHub: PR comments
