# riyan-ai-code/impact-iq architecture

> Architecture diagram of the GitHub repository riyan-ai-code/impact-iq, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2026-09-17). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/riyan-ai-code/impact-iq
- Repository: https://github.com/riyan-ai-code/impact-iq

## Overview

#### Purpose and Entry Points
ImpactIQ evaluates GitHub pull requests for deployment risk, combining deterministic static analyzers, ML/risk scoring, and LLM-generated release guidance. The backend FastAPI application starts through `backend/main.py` and application assembly in `backend/app/main.py`. The user-facing Next.js application starts from `frontend/app/page.tsx`, with authenticated product navigation under `frontend/app/dashboard/layout.tsx`.

#### Web UI and Client Boundaries
The Next.js 15/React frontend provides dashboard surfaces for analysis, dependency, evidence, risk, reports, integrations, and graph exploration. API access is centralized through `frontend/lib/api.ts` and `frontend/services/api.ts`; auth and hosted-data integration are represented by `frontend/lib/nhost.ts` and `frontend/services/nhostAuthService.ts`. Dashboard pages are presentation/client boundaries rather than analysis implementations, e.g. `frontend/app/dashboard/analysis/page.tsx`, `frontend/app/dashboard/knowledge-graph/page.tsx`.

#### API, Authentication, and Request Control
FastAPI route modules expose domains including analysis, GitHub, repositories, reports, graph, integrations, and projects: `backend/api/analysis.py`, `backend/api/github.py`, `backend/api/graph.py`. Cross-cutting middleware handles JWT/auth context, webhook processing, CORS, errors, logging, and rate limiting, notably `backend/middleware/auth_middleware.py`, `backend/middleware/github_webhook_middleware.py`, and `backend/middleware/rate_limit_middleware.py`. Shared settings, database lifecycle, security, and dependency injection reside in `backend/core/config.py`, `backend/core/database.py`, and `backend/core/security.py`.

#### GitHub Intake and Analysis Pipeline
GitHub OAuth, repository/PR retrieval, contributor data, and webhook behavior are encapsulated in `backend/services/github/oauth_service.py`, `backend/services/github/github_service.py`, and `backend/services/github/webhook_service.py`. A pull-request event/diff enters the analysis service layer, where parsing and six analysis domains assess code/API changes, dependencies, security, Docker, and CI/CD: `backend/services/analysis/diff_parser.py`, `backend/services/analysis/dependency_service.py`, `backend/services/analysis/security_service.py`. This is the principal external boundary: GitHub-supplied events and source metadata are normalized before risk decisions.

#### Risk, Release, and AI Evidence
Analyzer findings feed correlation, conflict resolution, historical context, blast-radius/dependency traversal, and deterministic scoring: `backend/services/analysis/correlation_engine.py`, `backend/services/analysis/risk_engine.py`, `backend/services/analysis/release_gate_service.py`. AI summary generation and RAG evidence construction turn these results into explanations, testing guidance, and checklists via `backend/services/analysis/ai_summary.py` and `backend/services/rag/evidence_builder.py`. LangChain brokers Gemini or OpenAI GPT-4; model artifacts for impact-risk evaluation are checked in under `backend/ml/model.py` and `backend/ml/weights/impact_risk_model.pt`.

#### Persistence and Knowledge Graph
SQLAlchemy models and repository classes separate API/service behavior from persistence: `backend/models/analysis.py`, `backend/models/repository.py`, `backend/repositories/analysis_repository.py`. PostgreSQL/Supabase is the intended persistent store, with SQLite fallback locally. Core relational schema and RAG/embedding migrations are in `database/schema.sql`, `database/migrations/001_phase2_rag.sql`, and `database/migrations/002_chunk_embeddings.sql`. Knowledge-graph extraction and traversal support dependency/blast-radius queries through `backend/services/graph/extractor.py` and `backend/services/graph/traversal_service.py`.

#### Deployment Topology
Docker Compose runs frontend and backend locally/production, with Nginx as the production reverse-proxy boundary: `docker-compose.yml`, `docker-compose.prod.yml`, `nginx/nginx.conf`. The backend is containerized by `backend/Dockerfile`; frontend by `frontend/Dockerfile`. Deployment targets include Vercel for Next.js, Render, AWS App Runner, and ECS/EC2 via `frontend/vercel.json`, `render.yaml`, `apprunner.yaml`, and `aws/cloudformation.yaml`. GitHub Actions deployment workflows are in `.github/workflows/deploy-aws.yml` and `.github/workflows/deploy-render.yml`.

Main entry points: [`backend/services/analysis/risk_engine.py`](https://github.com/riyan-ai-code/impact-iq/blob/main/backend/services/analysis/risk_engine.py) (Risk & release gate), [`backend/app/main.py`](https://github.com/riyan-ai-code/impact-iq/blob/main/backend/app/main.py) (FastAPI application), [`backend/api/analysis.py`](https://github.com/riyan-ai-code/impact-iq/blob/main/backend/api/analysis.py) (Domain routes), [`backend/services/github/github_service.py`](https://github.com/riyan-ai-code/impact-iq/blob/main/backend/services/github/github_service.py) (GitHub intake)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_frontend["Frontend"]
  node_ui["Next.js dashboard<br/>web client<br/>[layout.tsx]"]
  node_client_api["Client API layer<br/>frontend client<br/>[api.ts]"]
  node_nhost["Nhost auth<br/>hosted auth<br/>[nhost.ts]"]
end

subgraph group_backend["Backend API"]
  node_fastapi["FastAPI application<br/>API server<br/>[main.py]"]
  node_routes["Domain routes<br/>route modules<br/>[analysis.py]"]
  node_request_control["Auth &amp; request control<br/>middleware<br/>[auth_middleware.py]"]
  node_github{{"GitHub<br/>external platform"}}
  node_github_services["GitHub intake<br/>integration services<br/>[github_service.py]"]
end

subgraph group_pipeline["Analysis Pipeline"]
  node_diff_analysis["Diff &amp; domain analyzers<br/>analysis services<br/>[diff_parser.py]"]
  node_correlation["Correlation engine<br/>finding correlation"]
  node_risk["Risk &amp; release gate<br/>decision engine<br/>[risk_engine.py]"]
  node_ai_evidence["AI evidence &amp; guidance<br/>RAG and LLM service<br/>[ai_summary.py]"]
  node_llm{{"Gemini / GPT-4<br/>external models"}}
end

subgraph group_data["Data &amp; Knowledge"]
  node_knowledge_graph["Knowledge graph<br/>graph services"]
  node_persistence["Repositories &amp; models<br/>persistence layer"]
  node_database[("PostgreSQL / Supabase<br/>relational store<br/>[schema.sql]")]
end

subgraph group_delivery["Deployment"]
  node_containers["Compose &amp; Nginx<br/>runtime topology"]
  node_cloud_deploy["Cloud deployment<br/>deployment targets"]
end

node_ui -->|"uses"| node_client_api
node_ui -->|"authenticates"| node_nhost
node_client_api -->|"API requests"| node_fastapi
node_nhost -->|"JWT context"| node_fastapi
node_fastapi -->|"applies"| node_request_control
node_request_control -->|"authorizes requests"| node_routes
node_routes -->|"GitHub operations"| node_github_services
node_github -->|"webhooks"| node_request_control
node_github_services -->|"OAuth and PR retrieval"| node_github
node_github_services -->|"normalized PR diff"| node_diff_analysis
node_diff_analysis -->|"findings"| node_correlation
node_correlation -->|"resolved evidence"| node_risk
node_knowledge_graph -->|"dependency blast radius"| node_risk
node_risk -->|"risk decision"| node_ai_evidence
node_ai_evidence -->|"LLM generation"| node_llm
node_ai_evidence -->|"stores guidance"| node_persistence
node_risk -->|"stores analyses"| node_persistence
node_persistence -->|"SQLAlchemy"| node_database
node_database -->|"schema and embeddings"| node_knowledge_graph
node_routes -->|"graph queries"| node_knowledge_graph
node_containers -->|"serves frontend"| node_ui
node_containers -->|"runs backend"| node_fastapi
node_cloud_deploy -.->|"deploys runtime"| node_containers

click node_ui "https://github.com/riyan-ai-code/impact-iq/blob/main/frontend/app/dashboard/layout.tsx"
click node_client_api "https://github.com/riyan-ai-code/impact-iq/blob/main/frontend/lib/api.ts"
click node_nhost "https://github.com/riyan-ai-code/impact-iq/blob/main/frontend/lib/nhost.ts"
click node_fastapi "https://github.com/riyan-ai-code/impact-iq/blob/main/backend/app/main.py"
click node_routes "https://github.com/riyan-ai-code/impact-iq/blob/main/backend/api/analysis.py"
click node_request_control "https://github.com/riyan-ai-code/impact-iq/blob/main/backend/middleware/auth_middleware.py"
click node_github_services "https://github.com/riyan-ai-code/impact-iq/blob/main/backend/services/github/github_service.py"
click node_diff_analysis "https://github.com/riyan-ai-code/impact-iq/blob/main/backend/services/analysis/diff_parser.py"
click node_correlation "https://github.com/riyan-ai-code/impact-iq/blob/main/backend/services/analysis/correlation_engine.py"
click node_risk "https://github.com/riyan-ai-code/impact-iq/blob/main/backend/services/analysis/risk_engine.py"
click node_ai_evidence "https://github.com/riyan-ai-code/impact-iq/blob/main/backend/services/analysis/ai_summary.py"
click node_knowledge_graph "https://github.com/riyan-ai-code/impact-iq/blob/main/backend/services/graph/traversal_service.py"
click node_persistence "https://github.com/riyan-ai-code/impact-iq/blob/main/backend/repositories/analysis_repository.py"
click node_database "https://github.com/riyan-ai-code/impact-iq/blob/main/database/schema.sql"
click node_containers "https://github.com/riyan-ai-code/impact-iq/blob/main/docker-compose.prod.yml"
click node_cloud_deploy "https://github.com/riyan-ai-code/impact-iq/blob/main/aws/cloudformation.yaml"

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_ui,node_client_api,node_nhost toneBlue
class node_fastapi,node_routes,node_request_control,node_github,node_github_services toneAmber
class node_diff_analysis,node_correlation,node_risk,node_ai_evidence,node_llm toneMint
class node_knowledge_graph,node_persistence,node_database toneRose
class node_containers,node_cloud_deploy toneIndigo
```

## Components

### Frontend

- [Next.js dashboard](https://github.com/riyan-ai-code/impact-iq/blob/main/frontend/app/dashboard/layout.tsx): web client · Authenticated analysis and graph product surfaces. · `frontend/app/dashboard/layout.tsx`
- [Client API layer](https://github.com/riyan-ai-code/impact-iq/blob/main/frontend/lib/api.ts): frontend client · `frontend/lib/api.ts`
- [Nhost auth](https://github.com/riyan-ai-code/impact-iq/blob/main/frontend/lib/nhost.ts): hosted auth · `frontend/lib/nhost.ts`

### Backend API

- [FastAPI application](https://github.com/riyan-ai-code/impact-iq/blob/main/backend/app/main.py): API server · `backend/app/main.py`
- [Domain routes](https://github.com/riyan-ai-code/impact-iq/blob/main/backend/api/analysis.py): route modules · Analysis, GitHub, graph, reports, and integrations APIs. · `backend/api/analysis.py`
- [Auth & request control](https://github.com/riyan-ai-code/impact-iq/blob/main/backend/middleware/auth_middleware.py): middleware · JWT context, webhooks, rate limits, and request policy. · `backend/middleware/auth_middleware.py`
- **GitHub**: external platform · OAuth, pull requests, repository metadata, and webhooks.
- [GitHub intake](https://github.com/riyan-ai-code/impact-iq/blob/main/backend/services/github/github_service.py): integration services · Normalizes GitHub events, PRs, and repository data. · `backend/services/github/github_service.py`

### Analysis Pipeline

- [Diff & domain analyzers](https://github.com/riyan-ai-code/impact-iq/blob/main/backend/services/analysis/diff_parser.py): analysis services · Parses changes and evaluates dependency, security, Docker, and CI/CD impact. · `backend/services/analysis/diff_parser.py`
- [Correlation engine](https://github.com/riyan-ai-code/impact-iq/blob/main/backend/services/analysis/correlation_engine.py): finding correlation · Resolves conflicts and combines analysis evidence. · `backend/services/analysis/correlation_engine.py`
- [Risk & release gate](https://github.com/riyan-ai-code/impact-iq/blob/main/backend/services/analysis/risk_engine.py): decision engine · Scores risk using history and blast radius, then produces release decisions. · `backend/services/analysis/risk_engine.py`
- [AI evidence & guidance](https://github.com/riyan-ai-code/impact-iq/blob/main/backend/services/analysis/ai_summary.py): RAG and LLM service · Builds evidence and generates explanations, testing guidance, and checklists. · `backend/services/analysis/ai_summary.py`
- **Gemini / GPT-4**: external models

### Data & Knowledge

- [Knowledge graph](https://github.com/riyan-ai-code/impact-iq/blob/main/backend/services/graph/traversal_service.py): graph services · Extracts relationships and traverses dependencies for blast-radius queries. · `backend/services/graph/traversal_service.py`
- [Repositories & models](https://github.com/riyan-ai-code/impact-iq/blob/main/backend/repositories/analysis_repository.py): persistence layer · SQLAlchemy models and repositories isolate storage access. · `backend/repositories/analysis_repository.py`
- [PostgreSQL / Supabase](https://github.com/riyan-ai-code/impact-iq/blob/main/database/schema.sql): relational store · SQLite is used as a local fallback. · `database/schema.sql`

### Deployment

- [Compose & Nginx](https://github.com/riyan-ai-code/impact-iq/blob/main/docker-compose.prod.yml): runtime topology · Runs frontend and backend behind the production reverse proxy. · `docker-compose.prod.yml`
- [Cloud deployment](https://github.com/riyan-ai-code/impact-iq/blob/main/aws/cloudformation.yaml): deployment targets · Vercel, Render, and AWS targets are deployed by GitHub Actions. · `aws/cloudformation.yaml`

## Connections

- Next.js dashboard → Client API layer: uses
- Next.js dashboard → Nhost auth: authenticates
- Client API layer → FastAPI application: API requests
- Nhost auth → FastAPI application: JWT context
- FastAPI application → Auth & request control: applies
- Auth & request control → Domain routes: authorizes requests
- Domain routes → GitHub intake: GitHub operations
- GitHub → Auth & request control: webhooks
- GitHub intake → GitHub: OAuth and PR retrieval
- GitHub intake → Diff & domain analyzers: normalized PR diff
- Diff & domain analyzers → Correlation engine: findings
- Correlation engine → Risk & release gate: resolved evidence
- Knowledge graph → Risk & release gate: dependency blast radius
- Risk & release gate → AI evidence & guidance: risk decision
- AI evidence & guidance → Gemini / GPT-4: LLM generation
- AI evidence & guidance → Repositories & models: stores guidance
- Risk & release gate → Repositories & models: stores analyses
- Repositories & models → PostgreSQL / Supabase: SQLAlchemy
- PostgreSQL / Supabase → Knowledge graph: schema and embeddings
- Domain routes → Knowledge graph: graph queries
- Compose & Nginx → Next.js dashboard: serves frontend
- Compose & Nginx → FastAPI application: runs backend
- Cloud deployment → Compose & Nginx: deploys runtime
