# sonic-12/api-sentinel architecture

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

- Interactive diagram: https://gitdiagram.com/sonic-12/api-sentinel
- Repository: https://github.com/sonic-12/api-sentinel

## Overview

#### Purpose and System Shape
API-Sentinel is a runtime API-security system for detecting BOLA, BFLA, enumeration, rate abuse, PII exposure, and undocumented (“shadow”) APIs without application middleware. It captures HTTP traffic through kernel eBPF, processes it in Python, exposes security state through FastAPI, and renders it in a React dashboard.

#### Entry Points and Runtimes
- Target/demo FastAPI application: `backend/app/main.py`
- Dashboard FastAPI service: `backend/dashboard_api/main.py`
- Kernel/userspace capture executable: `ebpf/api-sentinel-libbpf/src/main.rs`
- React/Vite browser entry: `frontend/src/main.jsx`, with application routing/UI composition in `frontend/src/App.jsx`
- Material runtimes are Linux eBPF/kernel facilities, Rust with libbpf-rs, Python 3.10+/FastAPI/Uvicorn, and React/Vite.

#### Kernel Capture and Enforcement Boundary
The lowest layer attaches eBPF probes to observe traffic, sends captured events through a ring buffer, and uses pinned BPF-map state for enforcement decisions. Rust owns program loading, event consumption, and the bridge to userspace; BPF owns kernel-resident packet/request observation and blocking control.
- `ebpf/api-sentinel-libbpf/src/bpf/api_sentinel.bpf.c`
- `ebpf/api-sentinel-libbpf/src/bpf/api_sentinel.h`
- `ebpf/api-sentinel-libbpf/src/main.rs`

#### Detection Engine
Captured request data enters the Python parser/detection subsystem. It reconstructs and decodes requests, validates relevant fields, masks sensitive values before dashboard exposure, and runs behavior/security detectors. BOLA detection is a dedicated engine; rate limiting and enforcement integration provide paths for classifying or acting on abusive traffic.
- `backend/parser/integration.py`
- `backend/parser/request_parser.py`
- `backend/parser/bola_engine.py`
- `backend/parser/enforcer.py`
- `backend/parser/masking.py`

#### Discovery Pipeline
Detection-derived or observed request records flow into a separate discovery pipeline that normalizes endpoints, compares observed APIs with known inventory, generates OpenAPI-oriented output, and writes reports. This is the boundary where raw runtime traffic becomes API posture and shadow-API findings.
- `backend/discovery/pipeline.py`
- `backend/discovery/normalizer.py`
- `backend/discovery/comparator.py`
- `backend/discovery/openapi_generator.py`
- `backend/discovery/report_writer.py`

#### Dashboard API and Data Contract
A dedicated FastAPI dashboard API serves the frontend’s aggregate statistics, alerts, logs, discovery results, and related security views. Its data layer is the backend-facing contract; the browser should consume this API rather than parser or discovery internals directly.
- `backend/dashboard_api/main.py`
- `backend/dashboard_api/data.py`
- `backend/dashboard_api/__init__.py`

#### Frontend Presentation
The React dashboard presents operational and analytical views for alerts, masked logs, discovery posture, OWASP coverage, analytics, and configuration. `frontend/src/api.js` is the client-side service boundary to the dashboard API; page modules organize feature views.
- `frontend/src/api.js`
- `frontend/src/pages/Dashboard.jsx`
- `frontend/src/pages/Alerts.jsx`
- `frontend/src/pages/Discovery.jsx`
- `frontend/src/pages/MaskedLogs.jsx`

#### Primary Control Flow
Client requests reach the target application while eBPF observes them independently. Kernel events are consumed by Rust and delivered to the Python detection path. Detection outputs may trigger kernel enforcement and feed discovery/reporting. The dashboard API reads the resulting security/discovery data, and the React client displays it. Design-level details and operational sequencing are maintained in `Documentation/Architecture.md` and `PROCEDURE.md`.

Main entry points: [`backend/parser/integration.py`](https://github.com/sonic-12/api-sentinel/blob/API-Sentinel/backend/parser/integration.py) (Detection Integration), [`backend/discovery/comparator.py`](https://github.com/sonic-12/api-sentinel/blob/API-Sentinel/backend/discovery/comparator.py) (Inventory Comparator), [`ebpf/api-sentinel-libbpf/src/bpf/api_sentinel.bpf.c`](https://github.com/sonic-12/api-sentinel/blob/API-Sentinel/ebpf/api-sentinel-libbpf/src/bpf/api_sentinel.bpf.c) (eBPF Programs), [`backend/dashboard_api/data.py`](https://github.com/sonic-12/api-sentinel/blob/API-Sentinel/backend/dashboard_api/data.py) (Dashboard Data Layer)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_capture["Kernel Capture"]
  node_bpf{{"eBPF Programs<br/>kernel eBPF<br/>[api_sentinel.bpf.c]"}}
  node_rust_bridge["libbpf Capture Bridge<br/>Rust/libbpf-rs<br/>[main.rs]"]
end

subgraph group_detection["Detection Engine"]
  node_request_parser["Request Parser<br/>Python parser<br/>[request_parser.py]"]
  node_masking["Sensitive Data Masking<br/>Python sanitizer<br/>[masking.py]"]
  node_bola_engine["BOLA Engine<br/>security detector<br/>[bola_engine.py]"]
  node_detection_integration["Detection Integration<br/>Python orchestration<br/>[integration.py]"]
  node_enforcer["Enforcement Adapter<br/>Python enforcement<br/>[enforcer.py]"]
end

subgraph group_discovery["API Discovery"]
  node_discovery_pipeline["Discovery Pipeline<br/>Python pipeline<br/>[pipeline.py]"]
  node_normalizer["Endpoint Normalizer<br/>discovery stage<br/>[normalizer.py]"]
  node_inventory_comparator["Inventory Comparator<br/>discovery stage<br/>[comparator.py]"]
  node_openapi_generator["OpenAPI Generator<br/>discovery output"]
  node_report_writer["Discovery Reports<br/>report output<br/>[report_writer.py]"]
end

subgraph group_dashboard["Dashboard"]
  node_dashboard_api["Dashboard API<br/>FastAPI service<br/>[main.py]"]
  node_dashboard_data[("Dashboard Data Layer<br/>data contract<br/>[data.py]")]
  node_react_dashboard["React Dashboard<br/>React/Vite client<br/>[App.jsx]"]
  node_frontend_api["Dashboard API Client<br/>frontend service<br/>[api.js]"]
end

node_client(("API Clients<br/>external clients"))
node_target_api["Target FastAPI App<br/>FastAPI service<br/>[main.py]"]

node_client -->|"HTTP requests"| node_target_api
node_client -.->|"traffic observed"| node_bpf
node_bpf -->|"ring-buffer events"| node_rust_bridge
node_rust_bridge -->|"captured requests"| node_request_parser
node_request_parser -->|"decoded request data"| node_detection_integration
node_detection_integration -->|"authorization analysis"| node_bola_engine
node_detection_integration -->|"security records"| node_masking
node_detection_integration -->|"abuse findings"| node_enforcer
node_enforcer -->|"enforcement decisions"| node_bpf
node_detection_integration -->|"observed records"| node_discovery_pipeline
node_discovery_pipeline -->|"observed endpoints"| node_normalizer
node_normalizer -->|"normalized inventory"| node_inventory_comparator
node_inventory_comparator -->|"discovered API model"| node_openapi_generator
node_inventory_comparator -->|"shadow API findings"| node_report_writer
node_masking -->|"masked logs and alerts"| node_dashboard_data
node_report_writer -->|"discovery results"| node_dashboard_data
node_dashboard_data -->|"security views"| node_dashboard_api
node_frontend_api -->|"dashboard requests"| node_dashboard_api
node_react_dashboard -->|"loads views"| node_frontend_api

click node_target_api "https://github.com/sonic-12/api-sentinel/blob/API-Sentinel/backend/app/main.py"
click node_bpf "https://github.com/sonic-12/api-sentinel/blob/API-Sentinel/ebpf/api-sentinel-libbpf/src/bpf/api_sentinel.bpf.c"
click node_rust_bridge "https://github.com/sonic-12/api-sentinel/blob/API-Sentinel/ebpf/api-sentinel-libbpf/src/main.rs"
click node_request_parser "https://github.com/sonic-12/api-sentinel/blob/API-Sentinel/backend/parser/request_parser.py"
click node_masking "https://github.com/sonic-12/api-sentinel/blob/API-Sentinel/backend/parser/masking.py"
click node_bola_engine "https://github.com/sonic-12/api-sentinel/blob/API-Sentinel/backend/parser/bola_engine.py"
click node_detection_integration "https://github.com/sonic-12/api-sentinel/blob/API-Sentinel/backend/parser/integration.py"
click node_enforcer "https://github.com/sonic-12/api-sentinel/blob/API-Sentinel/backend/parser/enforcer.py"
click node_discovery_pipeline "https://github.com/sonic-12/api-sentinel/blob/API-Sentinel/backend/discovery/pipeline.py"
click node_normalizer "https://github.com/sonic-12/api-sentinel/blob/API-Sentinel/backend/discovery/normalizer.py"
click node_inventory_comparator "https://github.com/sonic-12/api-sentinel/blob/API-Sentinel/backend/discovery/comparator.py"
click node_openapi_generator "https://github.com/sonic-12/api-sentinel/blob/API-Sentinel/backend/discovery/openapi_generator.py"
click node_report_writer "https://github.com/sonic-12/api-sentinel/blob/API-Sentinel/backend/discovery/report_writer.py"
click node_dashboard_api "https://github.com/sonic-12/api-sentinel/blob/API-Sentinel/backend/dashboard_api/main.py"
click node_dashboard_data "https://github.com/sonic-12/api-sentinel/blob/API-Sentinel/backend/dashboard_api/data.py"
click node_react_dashboard "https://github.com/sonic-12/api-sentinel/blob/API-Sentinel/frontend/src/App.jsx"
click node_frontend_api "https://github.com/sonic-12/api-sentinel/blob/API-Sentinel/frontend/src/api.js"

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_bpf,node_rust_bridge toneBlue
class node_request_parser,node_masking,node_bola_engine,node_detection_integration,node_enforcer toneAmber
class node_discovery_pipeline,node_normalizer,node_inventory_comparator,node_openapi_generator,node_report_writer toneMint
class node_dashboard_api,node_dashboard_data,node_react_dashboard,node_frontend_api toneRose
class node_client,node_target_api toneNeutral
```

## Components

### Kernel Capture

Traffic observation and enforcement boundary.

- [eBPF Programs](https://github.com/sonic-12/api-sentinel/blob/API-Sentinel/ebpf/api-sentinel-libbpf/src/bpf/api_sentinel.bpf.c): kernel eBPF · Observes requests and applies map-backed blocking decisions. · `ebpf/api-sentinel-libbpf/src/bpf/api_sentinel.bpf.c`
- [libbpf Capture Bridge](https://github.com/sonic-12/api-sentinel/blob/API-Sentinel/ebpf/api-sentinel-libbpf/src/main.rs): Rust/libbpf-rs · Loads BPF, consumes ring-buffer events, and bridges userspace. · `ebpf/api-sentinel-libbpf/src/main.rs`

### Detection Engine

Python request analysis and response controls.

- [Request Parser](https://github.com/sonic-12/api-sentinel/blob/API-Sentinel/backend/parser/request_parser.py): Python parser · Reconstructs, decodes, and validates captured requests. · `backend/parser/request_parser.py`
- [Sensitive Data Masking](https://github.com/sonic-12/api-sentinel/blob/API-Sentinel/backend/parser/masking.py): Python sanitizer · Masks sensitive values before security data is exposed. · `backend/parser/masking.py`
- [BOLA Engine](https://github.com/sonic-12/api-sentinel/blob/API-Sentinel/backend/parser/bola_engine.py): security detector · Analyzes object-level authorization behavior. · `backend/parser/bola_engine.py`
- [Detection Integration](https://github.com/sonic-12/api-sentinel/blob/API-Sentinel/backend/parser/integration.py): Python orchestration · Coordinates parser inputs and detector outputs. · `backend/parser/integration.py`
- [Enforcement Adapter](https://github.com/sonic-12/api-sentinel/blob/API-Sentinel/backend/parser/enforcer.py): Python enforcement · Classifies abusive traffic and drives enforcement integration. · `backend/parser/enforcer.py`

### API Discovery

Observed traffic becomes API posture findings.

- [Discovery Pipeline](https://github.com/sonic-12/api-sentinel/blob/API-Sentinel/backend/discovery/pipeline.py): Python pipeline · Converts observed records into API posture processing. · `backend/discovery/pipeline.py`
- [Endpoint Normalizer](https://github.com/sonic-12/api-sentinel/blob/API-Sentinel/backend/discovery/normalizer.py): discovery stage · `backend/discovery/normalizer.py`
- [Inventory Comparator](https://github.com/sonic-12/api-sentinel/blob/API-Sentinel/backend/discovery/comparator.py): discovery stage · Identifies undocumented and shadow APIs. · `backend/discovery/comparator.py`
- [OpenAPI Generator](https://github.com/sonic-12/api-sentinel/blob/API-Sentinel/backend/discovery/openapi_generator.py): discovery output · `backend/discovery/openapi_generator.py`
- [Discovery Reports](https://github.com/sonic-12/api-sentinel/blob/API-Sentinel/backend/discovery/report_writer.py): report output · `backend/discovery/report_writer.py`

### Dashboard

Security-data API and browser presentation.

- [Dashboard API](https://github.com/sonic-12/api-sentinel/blob/API-Sentinel/backend/dashboard_api/main.py): FastAPI service · Backend-facing contract for aggregate security views. · `backend/dashboard_api/main.py`
- [Dashboard Data Layer](https://github.com/sonic-12/api-sentinel/blob/API-Sentinel/backend/dashboard_api/data.py): data contract · Supplies statistics, alerts, logs, and discovery results. · `backend/dashboard_api/data.py`
- [React Dashboard](https://github.com/sonic-12/api-sentinel/blob/API-Sentinel/frontend/src/App.jsx): React/Vite client · Operational views for alerts, logs, and discovery posture. · `frontend/src/App.jsx`
- [Dashboard API Client](https://github.com/sonic-12/api-sentinel/blob/API-Sentinel/frontend/src/api.js): frontend service · `frontend/src/api.js`

### Other components

- **API Clients**: external clients
- [Target FastAPI App](https://github.com/sonic-12/api-sentinel/blob/API-Sentinel/backend/app/main.py): FastAPI service · Protected application traffic source. · `backend/app/main.py`

## Connections

- API Clients → Target FastAPI App: HTTP requests
- API Clients → eBPF Programs: traffic observed
- eBPF Programs → libbpf Capture Bridge: ring-buffer events
- libbpf Capture Bridge → Request Parser: captured requests
- Request Parser → Detection Integration: decoded request data
- Detection Integration → BOLA Engine: authorization analysis
- Detection Integration → Sensitive Data Masking: security records
- Detection Integration → Enforcement Adapter: abuse findings
- Enforcement Adapter → eBPF Programs: enforcement decisions
- Detection Integration → Discovery Pipeline: observed records
- Discovery Pipeline → Endpoint Normalizer: observed endpoints
- Endpoint Normalizer → Inventory Comparator: normalized inventory
- Inventory Comparator → OpenAPI Generator: discovered API model
- Inventory Comparator → Discovery Reports: shadow API findings
- Sensitive Data Masking → Dashboard Data Layer: masked logs and alerts
- Discovery Reports → Dashboard Data Layer: discovery results
- Dashboard Data Layer → Dashboard API: security views
- Dashboard API Client → Dashboard API: dashboard requests
- React Dashboard → Dashboard API Client: loads views
