# rajatrawal-06/gemma_hack architecture

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

- Interactive diagram: https://gitdiagram.com/rajatrawal-06/gemma_hack
- Repository: https://github.com/rajatrawal-06/gemma_hack

## Overview

#### Purpose and Operating Model
Project Sentinel is an edge-native public-safety incident-verification MVP. It treats camera and audio detections as timestamped evidence rather than automatic alerts, producing structured assessments for human operators. It explicitly excludes identity resolution, face recognition, and automated enforcement.

Primary entry points are the CLI demo at `scripts/run_demo.py` and Streamlit operator dashboard at `app.py`.

#### Canonical Data Contracts
Pydantic models define the system boundary between perception, fusion, reasoning, and review. Evidence packets carry modality-specific observations and capture timing; downstream stages operate on validated incident candidates and structured risk/review outputs.

- `src/sentinel/schemas.py`
- `src/sentinel/config.py`

Validation is a hard gate: model output is not allowed to become an incident report until it conforms to the defined schema.

#### Multimodal Evidence Fusion
The fusion layer buffers visual and audio evidence and aligns it by capture timestamp, accommodating modality latency/skew. It produces an `IncidentCandidate` with synchronization state, so missing or stale corroboration remains visible rather than being silently treated as negative evidence.

- `src/sentinel/fusion/engine.py`
- `src/sentinel/schemas.py`

Flow: perception/evidence inputs → timestamp-aware fusion buffer → fused candidate or explicitly degraded synchronization status.

#### Reasoning Boundary: Local Gemma or Offline Fallback
A reasoning adapter converts a fused candidate into strict JSON instructions for a Gemma-compatible OpenAI-style chat endpoint. Responses are schema-validated before report creation. The runtime is optional: a deterministic local/offline reasoner supports reproducible demos without model downloads, credentials, or network access.

- `src/sentinel/reasoning/gemma_client.py`
- `src/sentinel/reasoning/prompt.py`
- `src/sentinel/config.py`

The external model boundary is configured through `GEMMA_API_BASE` and `GEMMA_MODEL`; the expected deployment is a local server such as one on `localhost:8080/v1`.

#### Human Review and Operator Surface
The application presents evidence-backed assessments to an operator, preserving review as the actionability boundary. A generated assessment can communicate severity, rationale, modality corroboration, and synchronization limitations, but does not independently enforce an outcome.

- `app.py`
- `src/sentinel/schemas.py`

#### Demo and Scenario Harness
Curated scenarios drive the same evidence-to-fusion-to-reasoning path used by the runnable MVP. They demonstrate fall detection without audio corroboration, glass-break corroboration within the fusion window, and benign scenes intended to reduce alarm fatigue.

- `scripts/run_demo.py`
- `src/sentinel/demo/scenarios.py`
- `src/sentinel/fusion/engine.py`

#### Local Precedent Store
Prior incident reports can be appended to a local JSONL file and queried for similar historical outcomes. This is a lightweight forensic/context layer, not a managed database or remote retrieval service.

- `src/sentinel/precedent.py`
- `scripts/run_demo.py`

#### Runtime and Model Infrastructure
The project runs as Python with Streamlit for the dashboard and Pydantic-backed contracts. Optional model operations use Hugging Face authentication/access checks and download scripts; artifacts are expected under ignored `models/` storage. Runtime setup and model acquisition are separated from normal offline operation.

- `pyproject.toml`
- `requirements.txt`
- `scripts/verify_hf_access.py`
- `scripts/download_model.py`

Main entry points: [`src/sentinel/reasoning/gemma_client.py`](https://github.com/rajatrawal-06/gemma_hack/blob/main/src/sentinel/reasoning/gemma_client.py) (Reasoning adapter), [`src/sentinel/schemas.py`](https://github.com/rajatrawal-06/gemma_hack/blob/main/src/sentinel/schemas.py) (Structured assessment), [`scripts/run_demo.py`](https://github.com/rajatrawal-06/gemma_hack/blob/main/scripts/run_demo.py) (CLI demo), [`src/sentinel/fusion/engine.py`](https://github.com/rajatrawal-06/gemma_hack/blob/main/src/sentinel/fusion/engine.py) (Fusion engine)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_entry["Operator &amp; Demo"]
  node_dashboard["Streamlit dashboard<br/>operator UI<br/>[app.py]"]
  node_demo["CLI demo<br/>scenario runner<br/>[run_demo.py]"]
  node_scenarios["Curated scenarios<br/>evidence fixtures<br/>[scenarios.py]"]
  node_review(("Human review<br/>actionability boundary<br/>[app.py]"))
end

subgraph group_pipeline["Evidence Pipeline"]
  node_perception["Perception evidence<br/>visual and audio inputs"]
  node_contracts["Pydantic contracts<br/>validated schemas<br/>[schemas.py]"]
  node_fusion{{"Fusion engine<br/>multimodal fusion<br/>[engine.py]"}}
  node_fusion_buffer["Timestamp fusion buffer<br/>alignment layer<br/>[engine.py]"]
  node_candidate["Incident candidate<br/>validated candidate<br/>[schemas.py]"]
end

subgraph group_reasoning["Reasoning"]
  node_prompt["Strict JSON prompt<br/>reasoning prompt<br/>[prompt.py]"]
  node_reasoner{{"Reasoning adapter<br/>Gemma client<br/>[gemma_client.py]"}}
  node_gemma["Local Gemma endpoint<br/>optional model server"]
  node_offline["Offline reasoner<br/>deterministic fallback<br/>[gemma_client.py]"]
  node_assessment["Structured assessment<br/>validated report<br/>[schemas.py]"]
end

subgraph group_local["Local Context &amp; Model Setup"]
  node_precedent[("Precedent store<br/>local JSONL history<br/>[precedent.py]")]
  node_runtime_config["Runtime configuration<br/>settings<br/>[config.py]"]
  node_model_setup["Model acquisition<br/>optional setup scripts<br/>[download_model.py]"]
end

node_scenarios -->|"drives"| node_demo
node_demo -->|"emits"| node_perception
node_perception -->|"validated as evidence"| node_contracts
node_contracts -->|"evidence packets"| node_fusion
node_fusion -->|"buffers"| node_fusion_buffer
node_fusion_buffer -->|"aligns by capture time"| node_candidate
node_candidate -->|"formats"| node_prompt
node_prompt -->|"strict JSON request"| node_reasoner
node_runtime_config -.->|"configures"| node_reasoner
node_reasoner -->|"optional inference"| node_gemma
node_reasoner -.->|"fallback"| node_offline
node_gemma -->|"validated response"| node_assessment
node_offline -->|"deterministic response"| node_assessment
node_assessment -->|"evidence-backed assessment"| node_review
node_dashboard -->|"supports"| node_review
node_demo -->|"append/query reports"| node_precedent
node_precedent -.->|"historical context"| node_assessment
node_model_setup -.->|"provisions artifacts"| node_gemma

click node_dashboard "https://github.com/rajatrawal-06/gemma_hack/blob/main/app.py"
click node_demo "https://github.com/rajatrawal-06/gemma_hack/blob/main/scripts/run_demo.py"
click node_scenarios "https://github.com/rajatrawal-06/gemma_hack/blob/main/src/sentinel/demo/scenarios.py"
click node_contracts "https://github.com/rajatrawal-06/gemma_hack/blob/main/src/sentinel/schemas.py"
click node_fusion "https://github.com/rajatrawal-06/gemma_hack/blob/main/src/sentinel/fusion/engine.py"
click node_fusion_buffer "https://github.com/rajatrawal-06/gemma_hack/blob/main/src/sentinel/fusion/engine.py"
click node_candidate "https://github.com/rajatrawal-06/gemma_hack/blob/main/src/sentinel/schemas.py"
click node_prompt "https://github.com/rajatrawal-06/gemma_hack/blob/main/src/sentinel/reasoning/prompt.py"
click node_reasoner "https://github.com/rajatrawal-06/gemma_hack/blob/main/src/sentinel/reasoning/gemma_client.py"
click node_offline "https://github.com/rajatrawal-06/gemma_hack/blob/main/src/sentinel/reasoning/gemma_client.py"
click node_assessment "https://github.com/rajatrawal-06/gemma_hack/blob/main/src/sentinel/schemas.py"
click node_review "https://github.com/rajatrawal-06/gemma_hack/blob/main/app.py"
click node_precedent "https://github.com/rajatrawal-06/gemma_hack/blob/main/src/sentinel/precedent.py"
click node_runtime_config "https://github.com/rajatrawal-06/gemma_hack/blob/main/src/sentinel/config.py"
click node_model_setup "https://github.com/rajatrawal-06/gemma_hack/blob/main/scripts/download_model.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_dashboard,node_demo,node_scenarios,node_review toneBlue
class node_perception,node_contracts,node_fusion,node_fusion_buffer,node_candidate toneAmber
class node_prompt,node_reasoner,node_gemma,node_offline,node_assessment toneMint
class node_precedent,node_runtime_config,node_model_setup toneRose
```

## Components

### Operator & Demo

- [Streamlit dashboard](https://github.com/rajatrawal-06/gemma_hack/blob/main/app.py): operator UI · Presents assessments for human review. · `app.py`
- [CLI demo](https://github.com/rajatrawal-06/gemma_hack/blob/main/scripts/run_demo.py): scenario runner · Runs the end-to-end MVP pipeline. · `scripts/run_demo.py`
- [Curated scenarios](https://github.com/rajatrawal-06/gemma_hack/blob/main/src/sentinel/demo/scenarios.py): evidence fixtures · Includes corroborated, degraded, and benign cases. · `src/sentinel/demo/scenarios.py`
- [Human review](https://github.com/rajatrawal-06/gemma_hack/blob/main/app.py): actionability boundary · Operators assess evidence; no automated enforcement occurs. · `app.py`

### Evidence Pipeline

- **Perception evidence**: visual and audio inputs · Timestamped modality observations.
- [Pydantic contracts](https://github.com/rajatrawal-06/gemma_hack/blob/main/src/sentinel/schemas.py): validated schemas · Defines evidence, candidates, assessments, and review outputs. · `src/sentinel/schemas.py`
- [Fusion engine](https://github.com/rajatrawal-06/gemma_hack/blob/main/src/sentinel/fusion/engine.py): multimodal fusion · Builds incident candidates with synchronization state. · `src/sentinel/fusion/engine.py`
- [Timestamp fusion buffer](https://github.com/rajatrawal-06/gemma_hack/blob/main/src/sentinel/fusion/engine.py): alignment layer · Accommodates modality latency and skew. · `src/sentinel/fusion/engine.py`
- [Incident candidate](https://github.com/rajatrawal-06/gemma_hack/blob/main/src/sentinel/schemas.py): validated candidate · Retains degraded or missing corroboration explicitly. · `src/sentinel/schemas.py`

### Reasoning

- [Strict JSON prompt](https://github.com/rajatrawal-06/gemma_hack/blob/main/src/sentinel/reasoning/prompt.py): reasoning prompt · `src/sentinel/reasoning/prompt.py`
- [Reasoning adapter](https://github.com/rajatrawal-06/gemma_hack/blob/main/src/sentinel/reasoning/gemma_client.py): Gemma client · Validates model output before report creation. · `src/sentinel/reasoning/gemma_client.py`
- **Local Gemma endpoint**: optional model server · OpenAI-style local chat endpoint.
- [Offline reasoner](https://github.com/rajatrawal-06/gemma_hack/blob/main/src/sentinel/reasoning/gemma_client.py): deterministic fallback · Supports reproducible operation without network or model downloads. · `src/sentinel/reasoning/gemma_client.py`
- [Structured assessment](https://github.com/rajatrawal-06/gemma_hack/blob/main/src/sentinel/schemas.py): validated report · Contains severity, rationale, corroboration, and limitations. · `src/sentinel/schemas.py`

### Local Context & Model Setup

- [Precedent store](https://github.com/rajatrawal-06/gemma_hack/blob/main/src/sentinel/precedent.py): local JSONL history · Appends reports and finds similar prior outcomes. · `src/sentinel/precedent.py`
- [Runtime configuration](https://github.com/rajatrawal-06/gemma_hack/blob/main/src/sentinel/config.py): settings · Configures model endpoint and model selection. · `src/sentinel/config.py`
- [Model acquisition](https://github.com/rajatrawal-06/gemma_hack/blob/main/scripts/download_model.py): optional setup scripts · Checks Hugging Face access and downloads local artifacts. · `scripts/download_model.py`

## Connections

- Curated scenarios → CLI demo: drives
- CLI demo → Perception evidence: emits
- Perception evidence → Pydantic contracts: validated as evidence
- Pydantic contracts → Fusion engine: evidence packets
- Fusion engine → Timestamp fusion buffer: buffers
- Timestamp fusion buffer → Incident candidate: aligns by capture time
- Incident candidate → Strict JSON prompt: formats
- Strict JSON prompt → Reasoning adapter: strict JSON request
- Runtime configuration → Reasoning adapter: configures
- Reasoning adapter → Local Gemma endpoint: optional inference
- Reasoning adapter → Offline reasoner: fallback
- Local Gemma endpoint → Structured assessment: validated response
- Offline reasoner → Structured assessment: deterministic response
- Structured assessment → Human review: evidence-backed assessment
- Streamlit dashboard → Human review: supports
- CLI demo → Precedent store: append/query reports
- Precedent store → Structured assessment: historical context
- Model acquisition → Local Gemma endpoint: provisions artifacts
