# r-nikhil-ganesh/fair architecture

> Architecture diagram of the GitHub repository r-nikhil-ganesh/fair, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2026-10-13). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/r-nikhil-ganesh/fair
- Repository: https://github.com/r-nikhil-ganesh/fair

## Overview

FairLend AI is a lending-fairness audit dashboard. Users sign in, upload or select data, map protected and outcome columns, and start an audit; results are stored and presented as metrics, disparity findings, summaries, and mitigation recommendations. The documented product also supports model audits and PDF export, though the README marks AI evaluation and export as mocked or placeholder. The frontend-to-backend API boundary is visible, but its server-side wiring is not fully established by the excerpts; that link is shown as unverified.

Main entry points: [`backend/celery_worker.py`](https://github.com/r-nikhil-ganesh/fair/blob/main/backend/celery_worker.py) (Audit worker), [`src/lib/ai.ts`](https://github.com/r-nikhil-ganesh/fair/blob/main/src/lib/ai.ts) (Audit client), [`src/lib/firebase.ts`](https://github.com/r-nikhil-ganesh/fair/blob/main/src/lib/firebase.ts) (Firebase client setup), [`src/app/dashboard/audit/[id]/page.tsx`](https://github.com/r-nikhil-ganesh/fair/blob/main/src/app/dashboard/audit/%5Bid%5D/page.tsx) (Audit report)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_access["Access and onboarding"]
  node_login["Google sign-in<br/>[page.tsx]"]
  node_auth["Auth and route guard<br/>[AuthContext.tsx]"]
  node_wizard["Data and column setup"]
end

subgraph group_frontend["Audit experience"]
  node_newaudit["Start audit<br/>[page.tsx]"]
  node_ai_client["Audit client<br/>[ai.ts]"]
  node_dashboard["Dashboard overview<br/>[page.tsx]"]
  node_history["Audit history<br/>[page.tsx]"]
  node_report["Audit report<br/>[page.tsx]"]
  node_report_adapter["Report normalization"]
  node_audit_components["Metrics and findings<br/>[AuditInsights.tsx]"]
  node_pdf["PDF export"]
end

subgraph group_services["Audit services"]
  node_api["Audit API<br/>[main.py]"]
  node_worker["Audit worker<br/>[celery_worker.py]"]
  node_fairness["Historical fairness metrics<br/>[fairness_engine.py]"]
  node_model_audit["Model fairness audit<br/>[model_auditor.py]"]
  node_counterfactuals["Counterfactual analysis<br/>[counterfactuals.py]"]
  node_narratives["AI narratives and plans<br/>[gemini_client.py]"]
  node_pii["PII detection<br/>[pii_detector.py]"]
end

subgraph group_data["Persistence and integrations"]
  node_firestore_client["Worker Firestore access"]
  node_firebase["Firebase client setup<br/>[firebase.ts]"]
  node_firestore[("Firestore audit records")]
  node_storage[("Firebase file storage")]
end

node_user(("Auditor"))
node_google_auth["Google authentication"]
node_backend_api["Backend HTTP service"]

node_user -->|"signs in"| node_login
node_login -->|"uses auth"| node_firebase
node_firebase -->|"authenticates"| node_google_auth
node_auth -->|"observes auth"| node_firebase
node_user -->|"configures data"| node_wizard
node_wizard -->|"submits setup"| node_newaudit
node_newaudit -->|"starts audit"| node_ai_client
node_ai_client -->|"uploads files"| node_firebase
node_ai_client -->|"writes audit"| node_firestore
node_ai_client -->|"requests audit"| node_backend_api
node_backend_api -.->|"routes requests"| node_api
node_api -.->|"queues work"| node_worker
node_worker -->|"computes metrics"| node_fairness
node_worker -->|"runs model audit"| node_model_audit
node_worker -->|"generates narratives"| node_narratives
node_worker -->|"updates records"| node_firestore_client
node_worker -->|"checks PII"| node_pii
node_model_audit -->|"computes fairness"| node_fairness
node_narratives -->|"uses analysis"| node_counterfactuals
node_narratives -->|"uses metrics"| node_fairness
node_firestore_client -.->|"persists results"| node_firestore
node_worker -.->|"loads datasets"| node_storage
node_user -->|"reviews audits"| node_dashboard
node_dashboard -->|"reads audits"| node_firestore
node_history -->|"reads history"| node_firestore
node_report -->|"loads report"| node_firestore
node_report -->|"normalizes data"| node_report_adapter
node_dashboard -->|"maps records"| node_report_adapter
node_history -->|"maps records"| node_report_adapter
node_report -.->|"renders findings"| node_audit_components
node_user -.->|"requests export"| node_pdf

click node_login "https://github.com/r-nikhil-ganesh/fair/blob/main/src/app/login/page.tsx"
click node_auth "https://github.com/r-nikhil-ganesh/fair/blob/main/src/lib/AuthContext.tsx"
click node_wizard "https://github.com/r-nikhil-ganesh/fair/blob/main/src/components/OnboardingWizard.tsx"
click node_newaudit "https://github.com/r-nikhil-ganesh/fair/blob/main/src/app/audit/new/page.tsx"
click node_ai_client "https://github.com/r-nikhil-ganesh/fair/blob/main/src/lib/ai.ts"
click node_dashboard "https://github.com/r-nikhil-ganesh/fair/blob/main/src/app/dashboard/page.tsx"
click node_history "https://github.com/r-nikhil-ganesh/fair/blob/main/src/app/dashboard/history/page.tsx"
click node_report "https://github.com/r-nikhil-ganesh/fair/blob/main/src/app/dashboard/audit/%5Bid%5D/page.tsx"
click node_report_adapter "https://github.com/r-nikhil-ganesh/fair/blob/main/src/lib/auditReportAdapter.ts"
click node_audit_components "https://github.com/r-nikhil-ganesh/fair/blob/main/src/components/audit/AuditInsights.tsx"
click node_pdf "https://github.com/r-nikhil-ganesh/fair/blob/main/src/components/PdfExportButton.tsx"
click node_api "https://github.com/r-nikhil-ganesh/fair/blob/main/backend/main.py"
click node_worker "https://github.com/r-nikhil-ganesh/fair/blob/main/backend/celery_worker.py"
click node_fairness "https://github.com/r-nikhil-ganesh/fair/blob/main/backend/fairness_engine.py"
click node_model_audit "https://github.com/r-nikhil-ganesh/fair/blob/main/backend/model_auditor.py"
click node_counterfactuals "https://github.com/r-nikhil-ganesh/fair/blob/main/backend/counterfactuals.py"
click node_narratives "https://github.com/r-nikhil-ganesh/fair/blob/main/backend/gemini_client.py"
click node_pii "https://github.com/r-nikhil-ganesh/fair/blob/main/backend/pii_detector.py"
click node_firestore_client "https://github.com/r-nikhil-ganesh/fair/blob/main/backend/firestore_client.py"
click node_firebase "https://github.com/r-nikhil-ganesh/fair/blob/main/src/lib/firebase.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_login,node_auth,node_wizard toneBlue
class node_newaudit,node_ai_client,node_dashboard,node_history,node_report,node_report_adapter,node_audit_components,node_pdf toneAmber
class node_api,node_worker,node_fairness,node_model_audit,node_counterfactuals,node_narratives,node_pii toneMint
class node_firestore_client,node_firebase,node_firestore,node_storage toneRose
class node_user,node_google_auth,node_backend_api toneIndigo
```

## Components

### Access and onboarding

- [Google sign-in](https://github.com/r-nikhil-ganesh/fair/blob/main/src/app/login/page.tsx): `src/app/login/page.tsx`
- [Auth and route guard](https://github.com/r-nikhil-ganesh/fair/blob/main/src/lib/AuthContext.tsx): `src/lib/AuthContext.tsx`
- [Data and column setup](https://github.com/r-nikhil-ganesh/fair/blob/main/src/components/OnboardingWizard.tsx): `src/components/OnboardingWizard.tsx`

### Audit experience

- [Start audit](https://github.com/r-nikhil-ganesh/fair/blob/main/src/app/audit/new/page.tsx): `src/app/audit/new/page.tsx`
- [Audit client](https://github.com/r-nikhil-ganesh/fair/blob/main/src/lib/ai.ts): `src/lib/ai.ts`
- [Dashboard overview](https://github.com/r-nikhil-ganesh/fair/blob/main/src/app/dashboard/page.tsx): `src/app/dashboard/page.tsx`
- [Audit history](https://github.com/r-nikhil-ganesh/fair/blob/main/src/app/dashboard/history/page.tsx): `src/app/dashboard/history/page.tsx`
- [Audit report](https://github.com/r-nikhil-ganesh/fair/blob/main/src/app/dashboard/audit/%5Bid%5D/page.tsx): `src/app/dashboard/audit/[id]/page.tsx`
- [Report normalization](https://github.com/r-nikhil-ganesh/fair/blob/main/src/lib/auditReportAdapter.ts): `src/lib/auditReportAdapter.ts`
- [Metrics and findings](https://github.com/r-nikhil-ganesh/fair/blob/main/src/components/audit/AuditInsights.tsx): `src/components/audit/AuditInsights.tsx`
- [PDF export](https://github.com/r-nikhil-ganesh/fair/blob/main/src/components/PdfExportButton.tsx): `src/components/PdfExportButton.tsx`

### Audit services

- [Audit API](https://github.com/r-nikhil-ganesh/fair/blob/main/backend/main.py): `backend/main.py`
- [Audit worker](https://github.com/r-nikhil-ganesh/fair/blob/main/backend/celery_worker.py): `backend/celery_worker.py`
- [Historical fairness metrics](https://github.com/r-nikhil-ganesh/fair/blob/main/backend/fairness_engine.py): `backend/fairness_engine.py`
- [Model fairness audit](https://github.com/r-nikhil-ganesh/fair/blob/main/backend/model_auditor.py): `backend/model_auditor.py`
- [Counterfactual analysis](https://github.com/r-nikhil-ganesh/fair/blob/main/backend/counterfactuals.py): `backend/counterfactuals.py`
- [AI narratives and plans](https://github.com/r-nikhil-ganesh/fair/blob/main/backend/gemini_client.py): `backend/gemini_client.py`
- [PII detection](https://github.com/r-nikhil-ganesh/fair/blob/main/backend/pii_detector.py): `backend/pii_detector.py`

### Persistence and integrations

- [Worker Firestore access](https://github.com/r-nikhil-ganesh/fair/blob/main/backend/firestore_client.py): `backend/firestore_client.py`
- [Firebase client setup](https://github.com/r-nikhil-ganesh/fair/blob/main/src/lib/firebase.ts): `src/lib/firebase.ts`
- **Firestore audit records**
- **Firebase file storage**

### Other components

- **Auditor**
- **Google authentication**
- **Backend HTTP service**

## Connections

- Auditor → Google sign-in: signs in (evidence: `src/app/login/page.tsx`)
- Google sign-in → Firebase client setup: uses auth (evidence: `src/app/login/page.tsx`)
- Firebase client setup → Google authentication: authenticates (evidence: `src/lib/firebase.ts`)
- Auth and route guard → Firebase client setup: observes auth (evidence: `src/lib/AuthContext.tsx`)
- Auditor → Data and column setup: configures data (evidence: `src/components/OnboardingWizard.tsx`)
- Data and column setup → Start audit: submits setup (evidence: `src/app/audit/new/page.tsx`)
- Start audit → Audit client: starts audit (evidence: `src/app/audit/new/page.tsx`)
- Audit client → Firebase client setup: uploads files (evidence: `src/lib/ai.ts`)
- Audit client → Firestore audit records: writes audit (evidence: `src/lib/ai.ts`)
- Audit client → Backend HTTP service: requests audit (evidence: `src/lib/ai.ts`)
- Backend HTTP service → Audit API: routes requests
- Audit API → Audit worker: queues work (evidence: `backend/main.py`)
- Audit worker → Historical fairness metrics: computes metrics (evidence: `backend/celery_worker.py`)
- Audit worker → Model fairness audit: runs model audit (evidence: `backend/celery_worker.py`)
- Audit worker → AI narratives and plans: generates narratives (evidence: `backend/celery_worker.py`)
- Audit worker → Worker Firestore access: updates records (evidence: `backend/celery_worker.py`)
- Audit worker → PII detection: checks PII (evidence: `backend/celery_worker.py`)
- Model fairness audit → Historical fairness metrics: computes fairness (evidence: `backend/model_auditor.py`)
- AI narratives and plans → Counterfactual analysis: uses analysis (evidence: `backend/gemini_client.py`)
- AI narratives and plans → Historical fairness metrics: uses metrics (evidence: `backend/gemini_client.py`)
- Worker Firestore access → Firestore audit records: persists results
- Audit worker → Firebase file storage: loads datasets
- Auditor → Dashboard overview: reviews audits (evidence: `src/app/dashboard/page.tsx`)
- Dashboard overview → Firestore audit records: reads audits (evidence: `src/app/dashboard/page.tsx`)
- Audit history → Firestore audit records: reads history (evidence: `src/app/dashboard/history/page.tsx`)
- Audit report → Firestore audit records: loads report (evidence: `src/app/dashboard/audit/[id]/page.tsx`)
- Audit report → Report normalization: normalizes data (evidence: `src/app/dashboard/audit/[id]/page.tsx`)
- Dashboard overview → Report normalization: maps records (evidence: `src/app/dashboard/page.tsx`)
- Audit history → Report normalization: maps records (evidence: `src/app/dashboard/history/page.tsx`)
- Audit report → Metrics and findings: renders findings (evidence: `src/app/dashboard/audit/[id]/page.tsx`)
- Auditor → PDF export: requests export
