# css-enjoyer/prism-backend architecture

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

- Interactive diagram: https://gitdiagram.com/css-enjoyer/prism-backend
- Repository: https://github.com/css-enjoyer/prism-backend

## Overview

Prism receives GitHub pull-request webhooks, verifies them, and schedules in-process review work. The worker fetches the diff, obtains structured feedback from an LLM, persists the analysis, and posts a formatted PR comment; separate authenticated endpoints expose stored analyses. The README documents the major integrations and workflow; the sampled sources show webhook dispatch, review processing, persistence, and retrieval implementation. The database and external services are represented at the integration level.

Main entry points: [`app/services/analysis.py`](https://github.com/css-enjoyer/prism-backend/blob/main/app/services/analysis.py) (Review orchestration), [`app/routers/analysis.py`](https://github.com/css-enjoyer/prism-backend/blob/main/app/routers/analysis.py) (Analysis endpoints), [`app/routers/webhook.py`](https://github.com/css-enjoyer/prism-backend/blob/main/app/routers/webhook.py) (Webhook verification), [`app/db/session.py`](https://github.com/css-enjoyer/prism-backend/blob/main/app/db/session.py) (Async DB sessions)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_entry["API entry"]
  node_app["FastAPI app<br/>[main.py]"]
  node_webhook["Webhook verification<br/>[webhook.py]"]
end

subgraph group_review["Review processing"]
  node_worker["Review orchestration<br/>[analysis.py]"]
  node_diff_fetch["Diff retrieval<br/>[analysis.py]"]
  node_llm_review["LLM review<br/>[analysis.py]"]
  node_comment_format["Comment formatting<br/>[analysis.py]"]
  node_github_api["GitHub API"]
  node_openrouter["OpenRouter LLM"]
end

subgraph group_storage["Persistence"]
  node_session["Async DB sessions<br/>[session.py]"]
  node_analysis_model["Analysis model<br/>[analysis.py]"]
  node_postgres[("PostgreSQL")]
end

subgraph group_retrieval["Analysis retrieval"]
  node_analysis_router["Analysis endpoints<br/>[analysis.py]"]
  node_api_auth["API-key auth<br/>[dependencies.py]"]
  node_response_schema["Analysis response<br/>[analysis.py]"]
end

node_github(("GitHub"))
node_api_consumer(("API consumer"))

node_github -->|"sends webhook"| node_webhook
node_app -->|"registers route"| node_webhook
node_app -->|"registers route"| node_analysis_router
node_webhook -->|"queues task"| node_worker
node_worker -->|"calls"| node_diff_fetch
node_diff_fetch -->|"fetches diff"| node_github_api
node_worker -->|"calls"| node_llm_review
node_llm_review -->|"requests review"| node_openrouter
node_worker -->|"opens sessions"| node_session
node_worker -->|"reads and writes"| node_analysis_model
node_session -->|"connects"| node_postgres
node_worker -->|"formats feedback"| node_comment_format
node_worker -->|"posts comment"| node_github_api
node_api_consumer -->|"requests analyses"| node_analysis_router
node_analysis_router -->|"requires key"| node_api_auth
node_analysis_router -->|"gets DB session"| node_session
node_analysis_router -->|"queries analyses"| node_analysis_model
node_analysis_router -->|"serializes response"| node_response_schema
node_response_schema -->|"maps model fields"| node_analysis_model

click node_app "https://github.com/css-enjoyer/prism-backend/blob/main/app/main.py"
click node_webhook "https://github.com/css-enjoyer/prism-backend/blob/main/app/routers/webhook.py"
click node_worker "https://github.com/css-enjoyer/prism-backend/blob/main/app/services/analysis.py"
click node_diff_fetch "https://github.com/css-enjoyer/prism-backend/blob/main/app/services/analysis.py"
click node_llm_review "https://github.com/css-enjoyer/prism-backend/blob/main/app/services/analysis.py"
click node_comment_format "https://github.com/css-enjoyer/prism-backend/blob/main/app/services/analysis.py"
click node_session "https://github.com/css-enjoyer/prism-backend/blob/main/app/db/session.py"
click node_analysis_model "https://github.com/css-enjoyer/prism-backend/blob/main/app/models/analysis.py"
click node_analysis_router "https://github.com/css-enjoyer/prism-backend/blob/main/app/routers/analysis.py"
click node_api_auth "https://github.com/css-enjoyer/prism-backend/blob/main/app/dependencies.py"
click node_response_schema "https://github.com/css-enjoyer/prism-backend/blob/main/app/schemas/analysis.py"

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,node_webhook toneBlue
class node_worker,node_diff_fetch,node_llm_review,node_comment_format,node_github_api,node_openrouter toneAmber
class node_session,node_analysis_model,node_postgres,node_api_consumer toneMint
class node_analysis_router,node_api_auth,node_response_schema toneRose
class node_github toneIndigo
```

## Components

### API entry

- [FastAPI app](https://github.com/css-enjoyer/prism-backend/blob/main/app/main.py): `app/main.py`
- [Webhook verification](https://github.com/css-enjoyer/prism-backend/blob/main/app/routers/webhook.py): `app/routers/webhook.py`

### Review processing

- [Review orchestration](https://github.com/css-enjoyer/prism-backend/blob/main/app/services/analysis.py): `app/services/analysis.py`
- [Diff retrieval](https://github.com/css-enjoyer/prism-backend/blob/main/app/services/analysis.py): `app/services/analysis.py`
- [LLM review](https://github.com/css-enjoyer/prism-backend/blob/main/app/services/analysis.py): `app/services/analysis.py`
- [Comment formatting](https://github.com/css-enjoyer/prism-backend/blob/main/app/services/analysis.py): `app/services/analysis.py`
- **GitHub API**
- **OpenRouter LLM**

### Persistence

- [Async DB sessions](https://github.com/css-enjoyer/prism-backend/blob/main/app/db/session.py): `app/db/session.py`
- [Analysis model](https://github.com/css-enjoyer/prism-backend/blob/main/app/models/analysis.py): `app/models/analysis.py`
- **PostgreSQL**

### Analysis retrieval

- [Analysis endpoints](https://github.com/css-enjoyer/prism-backend/blob/main/app/routers/analysis.py): `app/routers/analysis.py`
- [API-key auth](https://github.com/css-enjoyer/prism-backend/blob/main/app/dependencies.py): `app/dependencies.py`
- [Analysis response](https://github.com/css-enjoyer/prism-backend/blob/main/app/schemas/analysis.py): `app/schemas/analysis.py`

### Other components

- **GitHub**
- **API consumer**

## Connections

- GitHub → Webhook verification: sends webhook (evidence: `README.md`)
- FastAPI app → Webhook verification: registers route (evidence: `app/main.py`)
- FastAPI app → Analysis endpoints: registers route (evidence: `app/main.py`)
- Webhook verification → Review orchestration: queues task (evidence: `app/routers/webhook.py`)
- Review orchestration → Diff retrieval: calls (evidence: `app/services/analysis.py`)
- Diff retrieval → GitHub API: fetches diff (evidence: `README.md`)
- Review orchestration → LLM review: calls (evidence: `app/services/analysis.py`)
- LLM review → OpenRouter LLM: requests review (evidence: `app/services/analysis.py`)
- Review orchestration → Async DB sessions: opens sessions (evidence: `app/services/analysis.py`)
- Review orchestration → Analysis model: reads and writes (evidence: `app/services/analysis.py`)
- Async DB sessions → PostgreSQL: connects (evidence: `app/db/session.py`)
- Review orchestration → Comment formatting: formats feedback (evidence: `app/services/analysis.py`)
- Review orchestration → GitHub API: posts comment (evidence: `app/services/analysis.py`)
- API consumer → Analysis endpoints: requests analyses (evidence: `README.md`)
- Analysis endpoints → API-key auth: requires key (evidence: `app/routers/analysis.py`)
- Analysis endpoints → Async DB sessions: gets DB session (evidence: `app/routers/analysis.py`)
- Analysis endpoints → Analysis model: queries analyses (evidence: `app/routers/analysis.py`)
- Analysis endpoints → Analysis response: serializes response (evidence: `app/routers/analysis.py`)
- Analysis response → Analysis model: maps model fields (evidence: `app/schemas/analysis.py`)
