# mayu3000/zta-gateway architecture

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

- Interactive diagram: https://gitdiagram.com/mayu3000/zta-gateway
- Repository: https://github.com/mayu3000/zta-gateway

## Overview

This is a LAN device-risk monitoring and enforcement application with an admin web console. Its main workflow captures network packets, resolves traffic to devices, extracts behavioral features, scores risk against device baselines and network indicators, records audit history, and may quarantine a device. The console supports registration, email verification, admin approval, ban release, and threat traceback. The graph includes documented integrations and major runtime stages; where source was not excerpted, relationships are included only when supported by the source index or documented runtime calls.

Main entry points: [`run.py`](https://github.com/mayu3000/zta-gateway/blob/main/run.py) (Scoring runtime), [`app/routes.py`](https://github.com/mayu3000/zta-gateway/blob/main/app/routes.py) (Web routes), [`app/models.py`](https://github.com/mayu3000/zta-gateway/blob/main/app/models.py) (Domain and audit models), [`app/policy/composite.py`](https://github.com/mayu3000/zta-gateway/blob/main/app/policy/composite.py) (Composite risk)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_capture["Traffic capture"]
  node_sniffer["Packet sniffer<br/>[sniffer.py]"]
  node_buffer["Packet buffer<br/>[buffer.py]"]
  node_resolver["IP to MAC resolver<br/>[resolve.py]"]
  node_discovery["Device discovery<br/>[discovery.py]"]
  node_sync["Device synchronization<br/>[sync_devices.py]"]
end

subgraph group_analysis["Risk analysis"]
  node_features["Traffic features<br/>[extract.py]"]
  node_baseline["Baseline learning<br/>[model.py]"]
  node_baseline_config["Baseline settings<br/>[config.py]"]
  node_identity_risk["Identity risk<br/>[identity_risk.py]"]
  node_device_risk["Device risk<br/>[device_risk.py]"]
  node_network_risk["Network risk<br/>[network_risk.py]"]
  node_composite["Composite risk<br/>[composite.py]"]
  node_scoring["Behavior scoring<br/>[scoring.py]"]
end

subgraph group_response["Response and audit"]
  node_escalation["Ban escalation<br/>[escalation.py]"]
  node_quarantine["ARP quarantine<br/>[quarantine.py]"]
  node_forensic["Forensic log<br/>[forensic.py]"]
  node_traceback["Threat traceback<br/>[tracer.py]"]
end

subgraph group_console["Admin console"]
  node_mail["Verification email<br/>[mail.py]"]
  node_routes["Web routes<br/>[routes.py]"]
  node_middleware["Web middleware<br/>[middleware.py]"]
end

subgraph group_data["Application data"]
  node_models[("Domain and audit models<br/>[models.py]")]
end

node_network(("LAN traffic"))
node_operator(("Administrator"))
node_runtime["Scoring runtime<br/>[run.py]"]

node_network -->|"sends packets"| node_sniffer
node_sniffer -->|"queues packets"| node_buffer
node_features -->|"reads packets"| node_buffer
node_features -->|"resolves addresses"| node_resolver
node_discovery -->|"resolves devices"| node_resolver
node_runtime -->|"starts capture"| node_sniffer
node_runtime -->|"schedules scans"| node_sync
node_sync -->|"uses discovery"| node_discovery
node_runtime -->|"extracts features"| node_features
node_runtime -->|"updates baseline"| node_baseline
node_baseline -->|"persists statistics"| node_models
node_baseline -->|"reads sample setting"| node_baseline_config
node_runtime -->|"computes risk"| node_composite
node_composite -->|"evaluates identity"| node_identity_risk
node_composite -->|"evaluates device"| node_device_risk
node_composite -->|"evaluates network"| node_network_risk
node_composite -->|"evaluates behavior"| node_scoring
node_scoring -->|"reads baseline"| node_baseline
node_scoring -->|"reads thresholds"| node_baseline_config
node_runtime -->|"classifies risk"| node_scoring
node_runtime -->|"records risk and logs"| node_models
node_runtime -->|"gets ban threshold"| node_escalation
node_runtime -->|"quarantines device"| node_quarantine
node_runtime -->|"logs decisions"| node_forensic
node_routes -->|"releases device"| node_quarantine
node_routes -->|"logs admin actions"| node_forensic
node_routes -->|"requests timeline"| node_traceback
node_traceback -->|"queries risk history"| node_models
node_routes -->|"reads and updates"| node_models
node_routes -->|"sends verification"| node_mail
node_middleware -->|"checks user"| node_models
node_operator -->|"uses console"| node_routes
node_runtime -->|"loads data models"| node_models

click node_sniffer "https://github.com/mayu3000/zta-gateway/blob/main/app/capture/sniffer.py"
click node_buffer "https://github.com/mayu3000/zta-gateway/blob/main/app/capture/buffer.py"
click node_resolver "https://github.com/mayu3000/zta-gateway/blob/main/app/capture/resolve.py"
click node_discovery "https://github.com/mayu3000/zta-gateway/blob/main/app/discovery.py"
click node_sync "https://github.com/mayu3000/zta-gateway/blob/main/app/sync_devices.py"
click node_features "https://github.com/mayu3000/zta-gateway/blob/main/app/features/extract.py"
click node_baseline "https://github.com/mayu3000/zta-gateway/blob/main/app/baseline/model.py"
click node_baseline_config "https://github.com/mayu3000/zta-gateway/blob/main/app/baseline/config.py"
click node_identity_risk "https://github.com/mayu3000/zta-gateway/blob/main/app/policy/identity_risk.py"
click node_device_risk "https://github.com/mayu3000/zta-gateway/blob/main/app/policy/device_risk.py"
click node_network_risk "https://github.com/mayu3000/zta-gateway/blob/main/app/policy/network_risk.py"
click node_composite "https://github.com/mayu3000/zta-gateway/blob/main/app/policy/composite.py"
click node_scoring "https://github.com/mayu3000/zta-gateway/blob/main/app/policy/scoring.py"
click node_escalation "https://github.com/mayu3000/zta-gateway/blob/main/app/enforcement/escalation.py"
click node_quarantine "https://github.com/mayu3000/zta-gateway/blob/main/app/enforcement/quarantine.py"
click node_forensic "https://github.com/mayu3000/zta-gateway/blob/main/app/logging/forensic.py"
click node_traceback "https://github.com/mayu3000/zta-gateway/blob/main/app/traceback/tracer.py"
click node_mail "https://github.com/mayu3000/zta-gateway/blob/main/app/mail.py"
click node_routes "https://github.com/mayu3000/zta-gateway/blob/main/app/routes.py"
click node_middleware "https://github.com/mayu3000/zta-gateway/blob/main/app/middleware.py"
click node_models "https://github.com/mayu3000/zta-gateway/blob/main/app/models.py"
click node_runtime "https://github.com/mayu3000/zta-gateway/blob/main/run.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_sniffer,node_buffer,node_resolver,node_discovery,node_sync toneBlue
class node_features,node_baseline,node_baseline_config,node_identity_risk,node_device_risk,node_network_risk,node_composite,node_scoring toneAmber
class node_escalation,node_quarantine,node_forensic,node_traceback toneMint
class node_mail,node_routes,node_middleware toneRose
class node_models,node_network,node_operator toneIndigo
class node_runtime toneTeal
```

## Components

### Traffic capture

- [Packet sniffer](https://github.com/mayu3000/zta-gateway/blob/main/app/capture/sniffer.py): `app/capture/sniffer.py`
- [Packet buffer](https://github.com/mayu3000/zta-gateway/blob/main/app/capture/buffer.py): `app/capture/buffer.py`
- [IP to MAC resolver](https://github.com/mayu3000/zta-gateway/blob/main/app/capture/resolve.py): `app/capture/resolve.py`
- [Device discovery](https://github.com/mayu3000/zta-gateway/blob/main/app/discovery.py): `app/discovery.py`
- [Device synchronization](https://github.com/mayu3000/zta-gateway/blob/main/app/sync_devices.py): `app/sync_devices.py`

### Risk analysis

- [Traffic features](https://github.com/mayu3000/zta-gateway/blob/main/app/features/extract.py): `app/features/extract.py`
- [Baseline learning](https://github.com/mayu3000/zta-gateway/blob/main/app/baseline/model.py): `app/baseline/model.py`
- [Baseline settings](https://github.com/mayu3000/zta-gateway/blob/main/app/baseline/config.py): `app/baseline/config.py`
- [Identity risk](https://github.com/mayu3000/zta-gateway/blob/main/app/policy/identity_risk.py): `app/policy/identity_risk.py`
- [Device risk](https://github.com/mayu3000/zta-gateway/blob/main/app/policy/device_risk.py): `app/policy/device_risk.py`
- [Network risk](https://github.com/mayu3000/zta-gateway/blob/main/app/policy/network_risk.py): `app/policy/network_risk.py`
- [Composite risk](https://github.com/mayu3000/zta-gateway/blob/main/app/policy/composite.py): `app/policy/composite.py`
- [Behavior scoring](https://github.com/mayu3000/zta-gateway/blob/main/app/policy/scoring.py): `app/policy/scoring.py`

### Response and audit

- [Ban escalation](https://github.com/mayu3000/zta-gateway/blob/main/app/enforcement/escalation.py): `app/enforcement/escalation.py`
- [ARP quarantine](https://github.com/mayu3000/zta-gateway/blob/main/app/enforcement/quarantine.py): `app/enforcement/quarantine.py`
- [Forensic log](https://github.com/mayu3000/zta-gateway/blob/main/app/logging/forensic.py): `app/logging/forensic.py`
- [Threat traceback](https://github.com/mayu3000/zta-gateway/blob/main/app/traceback/tracer.py): `app/traceback/tracer.py`

### Admin console

- [Verification email](https://github.com/mayu3000/zta-gateway/blob/main/app/mail.py): `app/mail.py`
- [Web routes](https://github.com/mayu3000/zta-gateway/blob/main/app/routes.py): `app/routes.py`
- [Web middleware](https://github.com/mayu3000/zta-gateway/blob/main/app/middleware.py): `app/middleware.py`

### Application data

- [Domain and audit models](https://github.com/mayu3000/zta-gateway/blob/main/app/models.py): `app/models.py`

### Other components

- **LAN traffic**
- **Administrator**
- [Scoring runtime](https://github.com/mayu3000/zta-gateway/blob/main/run.py): `run.py`

## Connections

- LAN traffic → Packet sniffer: sends packets (evidence: `app/capture/sniffer.py`)
- Packet sniffer → Packet buffer: queues packets (evidence: `app/capture/sniffer.py`)
- Traffic features → Packet buffer: reads packets (evidence: `app/features/extract.py`)
- Traffic features → IP to MAC resolver: resolves addresses (evidence: `app/features/extract.py`)
- Device discovery → IP to MAC resolver: resolves devices (evidence: `app/discovery.py`)
- Scoring runtime → Packet sniffer: starts capture (evidence: `run.py`)
- Scoring runtime → Device synchronization: schedules scans (evidence: `run.py`)
- Device synchronization → Device discovery: uses discovery (evidence: `app/sync_devices.py`)
- Scoring runtime → Traffic features: extracts features (evidence: `run.py`)
- Scoring runtime → Baseline learning: updates baseline (evidence: `run.py`)
- Baseline learning → Domain and audit models: persists statistics (evidence: `app/baseline/model.py`)
- Baseline learning → Baseline settings: reads sample setting (evidence: `app/baseline/model.py`)
- Scoring runtime → Composite risk: computes risk (evidence: `run.py`)
- Composite risk → Identity risk: evaluates identity (evidence: `app/policy/composite.py`)
- Composite risk → Device risk: evaluates device (evidence: `app/policy/composite.py`)
- Composite risk → Network risk: evaluates network (evidence: `app/policy/composite.py`)
- Composite risk → Behavior scoring: evaluates behavior (evidence: `app/policy/composite.py`)
- Behavior scoring → Baseline learning: reads baseline (evidence: `app/policy/scoring.py`)
- Behavior scoring → Baseline settings: reads thresholds (evidence: `app/policy/scoring.py`)
- Scoring runtime → Behavior scoring: classifies risk (evidence: `run.py`)
- Scoring runtime → Domain and audit models: records risk and logs (evidence: `run.py`)
- Scoring runtime → Ban escalation: gets ban threshold (evidence: `run.py`)
- Scoring runtime → ARP quarantine: quarantines device (evidence: `run.py`)
- Scoring runtime → Forensic log: logs decisions (evidence: `run.py`)
- Web routes → ARP quarantine: releases device (evidence: `app/routes.py`)
- Web routes → Forensic log: logs admin actions (evidence: `app/routes.py`)
- Web routes → Threat traceback: requests timeline (evidence: `app/routes.py`)
- Threat traceback → Domain and audit models: queries risk history (evidence: `app/traceback/tracer.py`)
- Web routes → Domain and audit models: reads and updates (evidence: `app/routes.py`)
- Web routes → Verification email: sends verification (evidence: `app/routes.py`)
- Web middleware → Domain and audit models: checks user (evidence: `app/middleware.py`)
- Administrator → Web routes: uses console (evidence: `app/routes.py`)
- Scoring runtime → Domain and audit models: loads data models (evidence: `run.py`)
