# danosaurus-rex24/segura architecture

> Architecture diagram of the GitHub repository danosaurus-rex24/segura, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2026-08-26). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/danosaurus-rex24/segura
- Repository: https://github.com/danosaurus-rex24/segura

## Overview

#### Purpose and System Shape
Segura is an enterprise email-security prototype for detecting business email compromise (BEC) in Gmail. It is split into three decoupled runtimes: a browser-extension sensor, a FastAPI aggregation API, and a React/Vite executive dashboard. The extension evaluates messages locally, surfaces risk in Gmail, and reports flagged events to the backend.

#### Browser Extension Sensor
The extension is defined by `manifest.json` and injects Gmail-facing logic from `src/content/content-script.js`. This content script is the operational entry point in the browser: it observes/extracts email context from Gmail’s SPA DOM, invokes detection, adds an in-email risk banner, and sends threat events outward.

Key boundaries:
- Gmail DOM and user session remain inside the content-script environment.
- Detection is intentionally local and dependency-free.
- Only flagged-event data crosses to the backend API.

Paths: `manifest.json`, `src/content/content-script.js`.

#### Detection and Explanation Pipeline
The heuristic engine evaluates approximately 11 weighted fraud indicators, accumulates a score, and maps it into low, moderate, or high risk tiers. Signal definitions and scoring logic are centralized in `src/detection/signals.js`; user-facing reasoning is produced by `src/detection/explain.js`.

Control flow: extracted sender/body/metadata → signal evaluation → weighted score and triggered-signal set → risk tier → plain-English explanations → Gmail banner and API event payload.

Paths: `src/detection/signals.js`, `src/detection/explain.js`, `src/content/content-script.js`.

#### Backend Aggregator and Reporting API
The FastAPI application entry point is `segura-backend/main.py`. It exposes REST endpoints for event ingestion, organizational posture/statistics, flagged-email listing and drill-down, and monthly reporting. The backend is the boundary between individual browser detections and centralized dashboard reporting.

Supporting scripts indicate a seeded/demo-oriented data lifecycle and post-processing of stored explanations/snippets:
`segura-backend/seed_data.py`, `segura-backend/regenerate_explanations.py`, `segura-backend/fix_snippets.py`.

Paths: `segura-backend/main.py`, `segura-backend/seed_data.py`, `segura-backend/regenerate_explanations.py`.

#### Dashboard Application
The dashboard is a React 19 single-page application bootstrapped at `segura-dashboard/src/main.jsx` and composed from `segura-dashboard/src/App.jsx`. It presents backend-derived security posture for executive and analyst workflows, including overview, flagged-email review, individual incident detail, and monthly reporting.

Primary views:
- Operational posture and detection terminal: `segura-dashboard/src/pages/Overview.jsx`
- Filterable flag queue: `segura-dashboard/src/pages/FlaggedEmails.jsx`
- Threat drill-down: `segura-dashboard/src/pages/EmailDetail.jsx`
- Trend/report presentation and print export: `segura-dashboard/src/pages/MonthlyReport.jsx`

#### Presentation Shell and Design Boundary
Shared navigation/page composition resides in `segura-dashboard/src/components/Layout.jsx`; global visual and print styling are rooted in `segura-dashboard/src/App.css` and `segura-dashboard/src/index.css`. The dashboard is a presentation consumer of API data rather than a detection engine; risk calculation belongs to the extension/backend event model.

Paths: `segura-dashboard/src/components/Layout.jsx`, `segura-dashboard/src/App.css`, `segura-dashboard/src/index.css`.

#### Runtime and Integration Boundaries
Material runtimes are Chrome extension JavaScript, Python 3.10+ FastAPI/Uvicorn, and Node 18+/React/Vite. The extension communicates with the FastAPI service on its REST endpoints (development API on port 8000); the dashboard runs independently through Vite (typically port 5173/5174) and reads API-backed metrics. Gmail is the external source system, while browser DOM injection is the mechanism for sensor deployment.

Main entry points: [`segura-backend/main.py`](https://github.com/danosaurus-rex24/segura/blob/main/segura-backend/main.py) (FastAPI Application), [`segura-dashboard/src/components/Layout.jsx`](https://github.com/danosaurus-rex24/segura/blob/main/segura-dashboard/src/components/Layout.jsx) (Shared Layout), [`src/content/content-script.js`](https://github.com/danosaurus-rex24/segura/blob/main/src/content/content-script.js) (Gmail Content Script), [`segura-dashboard/src/App.jsx`](https://github.com/danosaurus-rex24/segura/blob/main/segura-dashboard/src/App.jsx) (Dashboard App)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_extension["Chrome Extension"]
  node_manifest["Extension Manifest<br/>extension config<br/>[manifest.json]"]
  node_content["Gmail Content Script<br/>browser sensor<br/>[content-script.js]"]
  node_signals["Fraud Signals<br/>heuristic engine<br/>[signals.js]"]
  node_explain["Risk Explanations<br/>explanation builder<br/>[explain.js]"]
end

subgraph group_backend["FastAPI Backend"]
  node_api["FastAPI Application<br/>REST API<br/>[main.py]"]
  node_seed["Demo Data Seeder<br/>data lifecycle script<br/>[seed_data.py]"]
  node_regenerate["Explanation Regenerator<br/>data maintenance script"]
end

subgraph group_dashboard["React Dashboard"]
  node_dashboard_main["Dashboard Bootstrap<br/>React entry<br/>[main.jsx]"]
  node_app["Dashboard App<br/>SPA composition<br/>[App.jsx]"]
  node_layout["Shared Layout<br/>presentation shell<br/>[Layout.jsx]"]
  node_overview["Overview<br/>posture view<br/>[Overview.jsx]"]
  node_flagged["Flagged Email Queue<br/>review view<br/>[FlaggedEmails.jsx]"]
  node_detail["Incident Detail<br/>drill-down view<br/>[EmailDetail.jsx]"]
  node_report["Monthly Report<br/>report view<br/>[MonthlyReport.jsx]"]
  node_styles["Global &amp; Print Styles<br/>presentation styles<br/>[App.css]"]
end

node_gmail(("Gmail<br/>external email UI"))

node_manifest -->|"injects into Gmail"| node_content
node_gmail -->|"email DOM context"| node_content
node_content -->|"sender, body, metadata"| node_signals
node_signals -->|"score, tier, triggered signals"| node_explain
node_explain -->|"banner reasoning"| node_content
node_content -->|"flagged threat events"| node_api
node_seed -.->|"seeds demo data"| node_api
node_regenerate -.->|"updates stored explanations"| node_api
node_dashboard_main -->|"boots"| node_app
node_app -->|"composes shell"| node_layout
node_layout -->|"hosts"| node_overview
node_layout -->|"hosts"| node_flagged
node_layout -->|"hosts"| node_detail
node_layout -->|"hosts"| node_report
node_styles -.->|"global styling"| node_app
node_api -->|"posture metrics"| node_overview
node_api -->|"flagged-email list"| node_flagged
node_api -->|"incident data"| node_detail
node_api -->|"monthly reporting data"| node_report

click node_manifest "https://github.com/danosaurus-rex24/segura/blob/main/manifest.json"
click node_content "https://github.com/danosaurus-rex24/segura/blob/main/src/content/content-script.js"
click node_signals "https://github.com/danosaurus-rex24/segura/blob/main/src/detection/signals.js"
click node_explain "https://github.com/danosaurus-rex24/segura/blob/main/src/detection/explain.js"
click node_api "https://github.com/danosaurus-rex24/segura/blob/main/segura-backend/main.py"
click node_seed "https://github.com/danosaurus-rex24/segura/blob/main/segura-backend/seed_data.py"
click node_regenerate "https://github.com/danosaurus-rex24/segura/blob/main/segura-backend/regenerate_explanations.py"
click node_dashboard_main "https://github.com/danosaurus-rex24/segura/blob/main/segura-dashboard/src/main.jsx"
click node_app "https://github.com/danosaurus-rex24/segura/blob/main/segura-dashboard/src/App.jsx"
click node_layout "https://github.com/danosaurus-rex24/segura/blob/main/segura-dashboard/src/components/Layout.jsx"
click node_overview "https://github.com/danosaurus-rex24/segura/blob/main/segura-dashboard/src/pages/Overview.jsx"
click node_flagged "https://github.com/danosaurus-rex24/segura/blob/main/segura-dashboard/src/pages/FlaggedEmails.jsx"
click node_detail "https://github.com/danosaurus-rex24/segura/blob/main/segura-dashboard/src/pages/EmailDetail.jsx"
click node_report "https://github.com/danosaurus-rex24/segura/blob/main/segura-dashboard/src/pages/MonthlyReport.jsx"
click node_styles "https://github.com/danosaurus-rex24/segura/blob/main/segura-dashboard/src/App.css"

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_manifest,node_content,node_signals,node_explain toneBlue
class node_api,node_seed,node_regenerate toneAmber
class node_dashboard_main,node_app,node_layout,node_overview,node_flagged,node_detail,node_report,node_styles toneMint
class node_gmail toneNeutral
```

## Components

### Chrome Extension

Local Gmail sensor runtime.

- [Extension Manifest](https://github.com/danosaurus-rex24/segura/blob/main/manifest.json): extension config · Declares Gmail injection. · `manifest.json`
- [Gmail Content Script](https://github.com/danosaurus-rex24/segura/blob/main/src/content/content-script.js): browser sensor · Extracts messages, renders banners, and reports flags. · `src/content/content-script.js`
- [Fraud Signals](https://github.com/danosaurus-rex24/segura/blob/main/src/detection/signals.js): heuristic engine · Evaluates weighted BEC indicators. · `src/detection/signals.js`
- [Risk Explanations](https://github.com/danosaurus-rex24/segura/blob/main/src/detection/explain.js): explanation builder · Produces user-facing reasons for triggered signals. · `src/detection/explain.js`

### FastAPI Backend

Central event and reporting API.

- [FastAPI Application](https://github.com/danosaurus-rex24/segura/blob/main/segura-backend/main.py): REST API · Ingests events and serves posture, incidents, and reports. · `segura-backend/main.py`
- [Demo Data Seeder](https://github.com/danosaurus-rex24/segura/blob/main/segura-backend/seed_data.py): data lifecycle script · Seeds demonstration reporting data. · `segura-backend/seed_data.py`
- [Explanation Regenerator](https://github.com/danosaurus-rex24/segura/blob/main/segura-backend/regenerate_explanations.py): data maintenance script · Post-processes stored explanations. · `segura-backend/regenerate_explanations.py`

### React Dashboard

Independent reporting SPA.

- [Dashboard Bootstrap](https://github.com/danosaurus-rex24/segura/blob/main/segura-dashboard/src/main.jsx): React entry · `segura-dashboard/src/main.jsx`
- [Dashboard App](https://github.com/danosaurus-rex24/segura/blob/main/segura-dashboard/src/App.jsx): SPA composition · Composes API-backed executive and analyst workflows. · `segura-dashboard/src/App.jsx`
- [Shared Layout](https://github.com/danosaurus-rex24/segura/blob/main/segura-dashboard/src/components/Layout.jsx): presentation shell · Provides shared navigation and page composition. · `segura-dashboard/src/components/Layout.jsx`
- [Overview](https://github.com/danosaurus-rex24/segura/blob/main/segura-dashboard/src/pages/Overview.jsx): posture view · Shows operational posture and detection terminal. · `segura-dashboard/src/pages/Overview.jsx`
- [Flagged Email Queue](https://github.com/danosaurus-rex24/segura/blob/main/segura-dashboard/src/pages/FlaggedEmails.jsx): review view · Provides filterable flagged-email review. · `segura-dashboard/src/pages/FlaggedEmails.jsx`
- [Incident Detail](https://github.com/danosaurus-rex24/segura/blob/main/segura-dashboard/src/pages/EmailDetail.jsx): drill-down view · Shows individual threat details. · `segura-dashboard/src/pages/EmailDetail.jsx`
- [Monthly Report](https://github.com/danosaurus-rex24/segura/blob/main/segura-dashboard/src/pages/MonthlyReport.jsx): report view · Presents trends and print export. · `segura-dashboard/src/pages/MonthlyReport.jsx`
- [Global & Print Styles](https://github.com/danosaurus-rex24/segura/blob/main/segura-dashboard/src/App.css): presentation styles · Defines dashboard visual and print styling. · `segura-dashboard/src/App.css`

### Other components

- **Gmail**: external email UI · Source email context and host DOM.

## Connections

- Extension Manifest → Gmail Content Script: injects into Gmail
- Gmail → Gmail Content Script: email DOM context
- Gmail Content Script → Fraud Signals: sender, body, metadata
- Fraud Signals → Risk Explanations: score, tier, triggered signals
- Risk Explanations → Gmail Content Script: banner reasoning
- Gmail Content Script → FastAPI Application: flagged threat events
- Demo Data Seeder → FastAPI Application: seeds demo data
- Explanation Regenerator → FastAPI Application: updates stored explanations
- Dashboard Bootstrap → Dashboard App: boots
- Dashboard App → Shared Layout: composes shell
- Shared Layout → Overview: hosts
- Shared Layout → Flagged Email Queue: hosts
- Shared Layout → Incident Detail: hosts
- Shared Layout → Monthly Report: hosts
- Global & Print Styles → Dashboard App: global styling
- FastAPI Application → Overview: posture metrics
- FastAPI Application → Flagged Email Queue: flagged-email list
- FastAPI Application → Incident Detail: incident data
- FastAPI Application → Monthly Report: monthly reporting data
