# 0011ashwin/ai-build architecture

> Architecture diagram of the GitHub repository 0011ashwin/ai-build, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2026-04-12). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/0011ashwin/ai-build
- Repository: https://github.com/0011ashwin/ai-build

## Overview

1. **System shape:** This repo is a **multi-service, multi-agent auditing system**. The main boundary is between the **user-facing app** and a set of **six independent agent services**. Each agent is containerized separately and appears to run as its own deployment unit.

2. **Entry point for users:** The `app/` directory contains the **main FastAPI application** (`app/main.py`) plus a small **static web UI** (`frontend/app.js`, `index.html`, `style.css`). This is the front door for submitting a case, viewing results, and likely triggering the audit workflow.

3. **Orchestration layer:** The **Chief Justice** agent is the central coordinator. It likely receives the case context, fans out work to the specialist agents, collects their findings, and synthesizes the final verdict/report. In the architecture diagram, this should sit between the app and the specialist agents as the workflow controller.

4. **Specialist agent services:** The `agents/` folder contains five domain-focused agents plus the Chief Justice:
   - `quantitative_auditor` for statistical bias metrics
   - `legal_researcher` for legal precedent retrieval
   - `mitigator_juror` for fairness-context arguments
   - `strict_auditor_juror` for proxy-bias / prosecution-style scrutiny
   - `ethicist_juror` for human impact and SDG alignment  
   Each has its own `agent.py`, `adk_app.py`, `Dockerfile`, and `pyproject.toml`, which indicates they are deployed as isolated Python services.

5. **Shared logic boundary:** The `shared/` package holds reusable cross-service utilities:
   - `bias_calculator.py` for fairness metrics such as disparate impact/statistical parity
   - `vector_search_client.py` for retrieval-backed legal/contextual search
   - `report_generator.py` for assembling audit outputs
   - `authenticated_httpx.py` and `a2a_utils.py` for authenticated service-to-service / agent-to-agent communication  
   This shared layer reduces duplication and is the main internal coupling mechanism across services.

6. **Data flow through the workflow:** A typical flow is: **user submits a case in the app → Chief Justice coordinates the audit → specialist agents analyze from their own perspective → outputs are aggregated into a final report**. The legal researcher likely adds retrieved precedent, the quantitative auditor adds numeric fairness measures, and the jurors provide argumentative assessments that influence the final decision.

7. **External model/runtime dependency:** The README states the system is powered by **Gemini Pro** and **Google Cloud Vertex AI**. That means the agents are not just rule-based services; they are LLM-backed AI workers. In an architecture diagram, Vertex AI/Gemini should be shown as an external inference dependency used by the agents, especially the orchestrator and research/reasoning agents.

8. **RAG subsystem:** The `legal_researcher` plus `shared/vector_search_client.py` imply a **retrieval-augmented generation** path for legal/contextual grounding. This is a distinct subsystem from the pure fairness metrics path and should be represented as: agent → vector search / knowledge source → grounded answer returned to the jury workflow.

9. **Deployment and packaging model:** Every service has a `Dockerfile`, and the repo includes `docker-compose.yaml` for local orchestration, plus `cloudbuild.yaml` and multiple `deploy-*.ps1` scripts for GCP rollout. The architecture is therefore **container-first**, with local composition and cloud deployment as first-class concerns. `app/` and each agent are independently deployable units.

10. **Operational boundaries:** `DEPLOYMENT_GUIDE.md`, `config.yaml`, and `requirements.txt` support environment setup, while the app’s frontend remains lightweight and separate from the AI logic. The backend responsibilities are split cleanly: **presentation in `app/`**, **reasoning in agents**, **shared utilities in `shared/`**, and **cloud/model infrastructure outside the repo**.

Main entry points: [`agents/chief_justice/agent.py`](https://github.com/0011ashwin/ai-build/blob/main/agents/chief_justice/agent.py) (Chief Justice), [`docker-compose.yaml`](https://github.com/0011ashwin/ai-build/blob/main/docker-compose.yaml) (Compose), [`shared/report_generator.py`](https://github.com/0011ashwin/ai-build/blob/main/shared/report_generator.py) (Report Gen), [`agents/quantitative_auditor/agent.py`](https://github.com/0011ashwin/ai-build/blob/main/agents/quantitative_auditor/agent.py) (Quant Auditor)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_app["User App"]
  node_app_main["Main API<br/>FastAPI app<br/>[main.py]"]
  node_app_ui["Web UI<br/>static frontend<br/>[index.html]"]
  node_app_js["UI logic<br/>frontend script<br/>[app.js]"]
end

subgraph group_agents["Agent Services"]
  node_chief_justice{{"Chief Justice<br/>orchestrator agent<br/>[agent.py]"}}
  node_quant_auditor{{"Quant Auditor<br/>metrics agent<br/>[agent.py]"}}
  node_legal_researcher{{"Legal Researcher<br/>RAG agent<br/>[agent.py]"}}
  node_mitigator_juror{{"Mitigator Juror<br/>argument agent<br/>[agent.py]"}}
  node_strict_juror{{"Strict Juror<br/>scrutiny agent<br/>[agent.py]"}}
  node_ethicist_juror{{"Ethicist Juror<br/>impact agent<br/>[agent.py]"}}
end

subgraph group_shared["Shared Core"]
  node_bias_calc["Bias Calc<br/>fairness utils<br/>[bias_calculator.py]"]
  node_vector_search["Vector Search<br/>retrieval client"]
  node_report_gen["Report Gen<br/>output assembly"]
  node_auth_httpx["Auth HTTPX<br/>service client"]
  node_a2a_utils["A2A Utils<br/>agent comms<br/>[a2a_utils.py]"]
end

subgraph group_external["External Services"]
  node_vertex_ai[("Vertex AI<br/>LLM runtime")]
  node_knowledge_source[("Knowledge Source<br/>retrieval backend")]
  node_compose["Compose<br/>local orchestration"]
  node_cloud_deploy["Cloud Deploy<br/>deployment tooling<br/>[cloudbuild.yaml]"]
end

node_app_ui -->|"submit case"| node_app_main
node_app_js -->|"API calls"| node_app_main
node_app_main -->|"start audit"| node_chief_justice
node_chief_justice -->|"request metrics"| node_quant_auditor
node_chief_justice -->|"request precedent"| node_legal_researcher
node_chief_justice -->|"request mitigation"| node_mitigator_juror
node_chief_justice -->|"request scrutiny"| node_strict_juror
node_chief_justice -->|"request ethics"| node_ethicist_juror
node_quant_auditor -->|"uses"| node_bias_calc
node_legal_researcher -->|"retrieves"| node_vector_search
node_vector_search -->|"queries"| node_knowledge_source
node_chief_justice -->|"assemble report"| node_report_gen
node_quant_auditor -->|"metrics input"| node_report_gen
node_legal_researcher -->|"research input"| node_report_gen
node_mitigator_juror -->|"argument input"| node_report_gen
node_strict_juror -->|"critique input"| node_report_gen
node_ethicist_juror -->|"ethics input"| node_report_gen
node_chief_justice -->|"LLM calls"| node_vertex_ai
node_quant_auditor -->|"LLM calls"| node_vertex_ai
node_legal_researcher -->|"LLM calls"| node_vertex_ai
node_mitigator_juror -->|"LLM calls"| node_vertex_ai
node_strict_juror -->|"LLM calls"| node_vertex_ai
node_ethicist_juror -->|"LLM calls"| node_vertex_ai
node_chief_justice -->|"service calls"| node_auth_httpx
node_chief_justice -->|"agent comms"| node_a2a_utils
node_compose -->|"runs"| node_app_main
node_compose -->|"runs"| node_chief_justice
node_compose -->|"runs"| node_quant_auditor
node_compose -->|"runs"| node_legal_researcher
node_compose -->|"runs"| node_mitigator_juror
node_compose -->|"runs"| node_strict_juror
node_compose -->|"runs"| node_ethicist_juror
node_cloud_deploy -->|"deploys"| node_compose

click node_app_main "https://github.com/0011ashwin/ai-build/blob/main/app/main.py"
click node_app_ui "https://github.com/0011ashwin/ai-build/blob/main/app/frontend/index.html"
click node_app_js "https://github.com/0011ashwin/ai-build/blob/main/app/frontend/app.js"
click node_chief_justice "https://github.com/0011ashwin/ai-build/blob/main/agents/chief_justice/agent.py"
click node_quant_auditor "https://github.com/0011ashwin/ai-build/blob/main/agents/quantitative_auditor/agent.py"
click node_legal_researcher "https://github.com/0011ashwin/ai-build/blob/main/agents/legal_researcher/agent.py"
click node_mitigator_juror "https://github.com/0011ashwin/ai-build/blob/main/agents/mitigator_juror/agent.py"
click node_strict_juror "https://github.com/0011ashwin/ai-build/blob/main/agents/strict_auditor_juror/agent.py"
click node_ethicist_juror "https://github.com/0011ashwin/ai-build/blob/main/agents/ethicist_juror/agent.py"
click node_bias_calc "https://github.com/0011ashwin/ai-build/blob/main/shared/bias_calculator.py"
click node_vector_search "https://github.com/0011ashwin/ai-build/blob/main/shared/vector_search_client.py"
click node_report_gen "https://github.com/0011ashwin/ai-build/blob/main/shared/report_generator.py"
click node_auth_httpx "https://github.com/0011ashwin/ai-build/blob/main/shared/authenticated_httpx.py"
click node_a2a_utils "https://github.com/0011ashwin/ai-build/blob/main/shared/a2a_utils.py"
click node_compose "https://github.com/0011ashwin/ai-build/blob/main/docker-compose.yaml"
click node_cloud_deploy "https://github.com/0011ashwin/ai-build/blob/main/cloudbuild.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_app_main,node_app_ui,node_app_js toneBlue
class node_chief_justice,node_quant_auditor,node_legal_researcher,node_mitigator_juror,node_strict_juror,node_ethicist_juror toneAmber
class node_bias_calc,node_vector_search,node_report_gen,node_auth_httpx,node_a2a_utils toneMint
class node_vertex_ai,node_knowledge_source,node_compose,node_cloud_deploy toneRose
```

## Components

### User App

FastAPI front door and lightweight web UI.

- [Main API](https://github.com/0011ashwin/ai-build/blob/main/app/main.py): FastAPI app · Submits cases and serves the audit workflow entrypoint. · `app/main.py`
- [Web UI](https://github.com/0011ashwin/ai-build/blob/main/app/frontend/index.html): static frontend · Minimal browser interface for case input and results. · `app/frontend/index.html`
- [UI logic](https://github.com/0011ashwin/ai-build/blob/main/app/frontend/app.js): frontend script · Client-side behavior for the web interface. · `app/frontend/app.js`

### Agent Services

Independent LLM-backed auditing and reasoning services.

- [Chief Justice](https://github.com/0011ashwin/ai-build/blob/main/agents/chief_justice/agent.py): orchestrator agent · Coordinates specialist agents and synthesizes the final verdict. · `agents/chief_justice/agent.py`
- [Quant Auditor](https://github.com/0011ashwin/ai-build/blob/main/agents/quantitative_auditor/agent.py): metrics agent · Computes statistical fairness and bias measures. · `agents/quantitative_auditor/agent.py`
- [Legal Researcher](https://github.com/0011ashwin/ai-build/blob/main/agents/legal_researcher/agent.py): RAG agent · Retrieves legal precedent and contextual grounding. · `agents/legal_researcher/agent.py`
- [Mitigator Juror](https://github.com/0011ashwin/ai-build/blob/main/agents/mitigator_juror/agent.py): argument agent · Builds fairness-context and mitigation arguments. · `agents/mitigator_juror/agent.py`
- [Strict Juror](https://github.com/0011ashwin/ai-build/blob/main/agents/strict_auditor_juror/agent.py): scrutiny agent · Applies proxy-bias and prosecution-style critique. · `agents/strict_auditor_juror/agent.py`
- [Ethicist Juror](https://github.com/0011ashwin/ai-build/blob/main/agents/ethicist_juror/agent.py): impact agent · Evaluates human impact and SDG alignment. · `agents/ethicist_juror/agent.py`

### Shared Core

Reusable cross-service utilities and output assembly.

- [Bias Calc](https://github.com/0011ashwin/ai-build/blob/main/shared/bias_calculator.py): fairness utils · Reusable disparate impact and parity calculations. · `shared/bias_calculator.py`
- [Vector Search](https://github.com/0011ashwin/ai-build/blob/main/shared/vector_search_client.py): retrieval client · Shared client for grounded legal/context lookup. · `shared/vector_search_client.py`
- [Report Gen](https://github.com/0011ashwin/ai-build/blob/main/shared/report_generator.py): output assembly · Formats and assembles audit findings into final reports. · `shared/report_generator.py`
- [Auth HTTPX](https://github.com/0011ashwin/ai-build/blob/main/shared/authenticated_httpx.py): service client · Authenticated HTTP client for service-to-service calls. · `shared/authenticated_httpx.py`
- [A2A Utils](https://github.com/0011ashwin/ai-build/blob/main/shared/a2a_utils.py): agent comms · Helpers for agent-to-agent communication patterns. · `shared/a2a_utils.py`

### External Services

Model, search, and deployment dependencies outside the repo.

- **Vertex AI**: LLM runtime · External Gemini/Vertex inference runtime used by agents.
- **Knowledge Source**: retrieval backend · External corpus or index queried for legal grounding.
- [Compose](https://github.com/0011ashwin/ai-build/blob/main/docker-compose.yaml): local orchestration · Container composition for running the app and agents locally. · `docker-compose.yaml`
- [Cloud Deploy](https://github.com/0011ashwin/ai-build/blob/main/cloudbuild.yaml): deployment tooling · GCP build and rollout scripts for containerized services. · `cloudbuild.yaml`

## Connections

- Web UI → Main API: submit case · Browser UI sends cases into the API backend.
- UI logic → Main API: API calls · Client script drives requests and result rendering.
- Main API → Chief Justice: start audit · Main app hands case context to the orchestrator.
- Chief Justice → Quant Auditor: request metrics · Delegates statistical bias analysis.
- Chief Justice → Legal Researcher: request precedent · Delegates grounded legal/context retrieval.
- Chief Justice → Mitigator Juror: request mitigation · Delegates fairness and mitigation reasoning.
- Chief Justice → Strict Juror: request scrutiny · Delegates adversarial proxy-bias review.
- Chief Justice → Ethicist Juror: request ethics · Delegates human-impact and responsibility assessment.
- Quant Auditor → Bias Calc: uses · Computes fairness metrics through shared logic.
- Legal Researcher → Vector Search: retrieves · Grounds answers using retrieval client.
- Vector Search → Knowledge Source: queries · Searches external indexed knowledge.
- Chief Justice → Report Gen: assemble report · Combines specialist findings into the final output.
- Quant Auditor → Report Gen: metrics input · Feeds numeric analysis into the report.
- Legal Researcher → Report Gen: research input · Feeds retrieved precedent into the report.
- Mitigator Juror → Report Gen: argument input · Feeds mitigation reasoning into the report.
- Strict Juror → Report Gen: critique input · Feeds adversarial critique into the report.
- Ethicist Juror → Report Gen: ethics input · Feeds human-impact assessment into the report.
- Chief Justice → Vertex AI: LLM calls · Coordinator relies on external Gemini/Vertex inference.
- Quant Auditor → Vertex AI: LLM calls · Reasoning and summarization use external model runtime.
- Legal Researcher → Vertex AI: LLM calls · Retrieval-augmented generation uses external model runtime.
- Mitigator Juror → Vertex AI: LLM calls · Argument synthesis uses external model runtime.
- Strict Juror → Vertex AI: LLM calls · Adversarial analysis uses external model runtime.
- Ethicist Juror → Vertex AI: LLM calls · Ethical assessment uses external model runtime.
- Chief Justice → Auth HTTPX: service calls · Uses authenticated transport for internal requests.
- Chief Justice → A2A Utils: agent comms · Uses shared helpers for inter-agent coordination.
- Compose → Main API: runs · Local container orchestration includes the app service.
- Compose → Chief Justice: runs · Local container orchestration includes the orchestrator agent.
- Compose → Quant Auditor: runs · Local container orchestration includes specialist agents.
- Compose → Legal Researcher: runs · Local container orchestration includes specialist agents.
- Compose → Mitigator Juror: runs · Local container orchestration includes specialist agents.
- Compose → Strict Juror: runs · Local container orchestration includes specialist agents.
- Compose → Ethicist Juror: runs · Local container orchestration includes specialist agents.
- Cloud Deploy → Compose: deploys · Deployment tooling mirrors the containerized service layout.
