# niranjan20061907/ai-threat-detection architecture

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

- Interactive diagram: https://gitdiagram.com/niranjan20061907/ai-threat-detection
- Repository: https://github.com/niranjan20061907/ai-threat-detection

## Overview

This repository currently provides a command-line nginx-log detector: users scan logs with signature rules or inspect per-request features. The runtime flow parses each line, scores valid requests, and displays findings; feature inspection parses a selected line and prints its measurements. Rule detection and feature extraction share attack signatures and User-Agent lists. The README also describes planned ML, behavioral, alerting, and service capabilities, but these are not implemented in the supplied tree, so they are not mapped as runtime components.

Main entry points: [`backend/app/__main__.py`](https://github.com/niranjan20061907/ai-threat-detection/blob/main/backend/app/__main__.py) (Scan and inspect commands), [`backend/app/core/detection/rules.py`](https://github.com/niranjan20061907/ai-threat-detection/blob/main/backend/app/core/detection/rules.py) (Signature rule engine), [`backend/app/core/features/extractor.py`](https://github.com/niranjan20061907/ai-threat-detection/blob/main/backend/app/core/features/extractor.py) (Request feature extractor), [`backend/app/core/features/patterns.py`](https://github.com/niranjan20061907/ai-threat-detection/blob/main/backend/app/core/features/patterns.py) (Attack patterns and decoding)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_interface["CLI"]
  node_cli["Scan and inspect commands<br/>[__main__.py]"]
end

subgraph group_ingestion["Log ingestion"]
  node_parser["Combined-log parser<br/>[parsers.py]"]
end

subgraph group_detection["Rule detection"]
  node_engine["Signature rule engine<br/>[rules.py]"]
  node_severity["Severity classifier<br/>[severity.py]"]
end

subgraph group_features["Request features"]
  node_patterns["Attack patterns and decoding<br/>[patterns.py]"]
  node_signatures["Client-agent signatures<br/>[signatures.py]"]
  node_extractor["Request feature extractor<br/>[extractor.py]"]
  node_stats["Entropy statistics<br/>[stats.py]"]
end

node_user(("User"))
node_logfile["nginx log file"]

node_user -->|"runs commands"| node_cli
node_logfile -->|"supplies log"| node_cli
node_cli -->|"parses lines"| node_parser
node_cli -->|"scores entries"| node_engine
node_cli -->|"extracts features"| node_extractor
node_engine -->|"classifies score"| node_severity
node_engine -->|"matches patterns"| node_patterns
node_engine -->|"matches agents"| node_signatures
node_extractor -->|"decodes and matches"| node_patterns
node_extractor -->|"checks agents"| node_signatures
node_extractor -->|"calculates entropy"| node_stats

click node_cli "https://github.com/niranjan20061907/ai-threat-detection/blob/main/backend/app/__main__.py"
click node_parser "https://github.com/niranjan20061907/ai-threat-detection/blob/main/backend/app/core/ingestion/parsers.py"
click node_engine "https://github.com/niranjan20061907/ai-threat-detection/blob/main/backend/app/core/detection/rules.py"
click node_severity "https://github.com/niranjan20061907/ai-threat-detection/blob/main/backend/app/core/detection/severity.py"
click node_patterns "https://github.com/niranjan20061907/ai-threat-detection/blob/main/backend/app/core/features/patterns.py"
click node_signatures "https://github.com/niranjan20061907/ai-threat-detection/blob/main/backend/app/core/features/signatures.py"
click node_extractor "https://github.com/niranjan20061907/ai-threat-detection/blob/main/backend/app/core/features/extractor.py"
click node_stats "https://github.com/niranjan20061907/ai-threat-detection/blob/main/backend/app/core/features/stats.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_cli,node_user toneBlue
class node_parser toneAmber
class node_engine,node_severity toneMint
class node_patterns,node_signatures,node_extractor,node_stats toneRose
class node_logfile toneIndigo
```

## Components

### CLI

- [Scan and inspect commands](https://github.com/niranjan20061907/ai-threat-detection/blob/main/backend/app/__main__.py): `backend/app/__main__.py`

### Log ingestion

- [Combined-log parser](https://github.com/niranjan20061907/ai-threat-detection/blob/main/backend/app/core/ingestion/parsers.py): `backend/app/core/ingestion/parsers.py`

### Rule detection

- [Signature rule engine](https://github.com/niranjan20061907/ai-threat-detection/blob/main/backend/app/core/detection/rules.py): `backend/app/core/detection/rules.py`
- [Severity classifier](https://github.com/niranjan20061907/ai-threat-detection/blob/main/backend/app/core/detection/severity.py): `backend/app/core/detection/severity.py`

### Request features

- [Attack patterns and decoding](https://github.com/niranjan20061907/ai-threat-detection/blob/main/backend/app/core/features/patterns.py): `backend/app/core/features/patterns.py`
- [Client-agent signatures](https://github.com/niranjan20061907/ai-threat-detection/blob/main/backend/app/core/features/signatures.py): `backend/app/core/features/signatures.py`
- [Request feature extractor](https://github.com/niranjan20061907/ai-threat-detection/blob/main/backend/app/core/features/extractor.py): `backend/app/core/features/extractor.py`
- [Entropy statistics](https://github.com/niranjan20061907/ai-threat-detection/blob/main/backend/app/core/features/stats.py): `backend/app/core/features/stats.py`

### Other components

- **User**
- **nginx log file**

## Connections

- User → Scan and inspect commands: runs commands (evidence: `README.md`)
- nginx log file → Scan and inspect commands: supplies log (evidence: `backend/app/__main__.py`)
- Scan and inspect commands → Combined-log parser: parses lines (evidence: `backend/app/__main__.py`)
- Scan and inspect commands → Signature rule engine: scores entries (evidence: `backend/app/__main__.py`)
- Scan and inspect commands → Request feature extractor: extracts features (evidence: `backend/app/__main__.py`)
- Signature rule engine → Severity classifier: classifies score (evidence: `backend/app/core/detection/rules.py`)
- Signature rule engine → Attack patterns and decoding: matches patterns (evidence: `backend/app/core/detection/rules.py`)
- Signature rule engine → Client-agent signatures: matches agents (evidence: `backend/app/core/detection/rules.py`)
- Request feature extractor → Attack patterns and decoding: decodes and matches (evidence: `backend/app/core/features/extractor.py`)
- Request feature extractor → Client-agent signatures: checks agents (evidence: `backend/app/core/features/extractor.py`)
- Request feature extractor → Entropy statistics: calculates entropy (evidence: `backend/app/core/features/extractor.py`)
