# adderalfox/nids-with-dqn architecture

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

- Interactive diagram: https://gitdiagram.com/adderalfox/nids-with-dqn
- Repository: https://github.com/adderalfox/nids-with-dqn

## Overview

This repository is a binary network intrusion detector trained with Deep Q-Learning on UNSW-NB15. Its principal workflow is to preprocess the training data, create an environment and DQN agent, train through repeated action/reward steps, and save a model. The README also describes evaluation by classification metrics and adaptive detection as product capabilities; the available excerpts do not establish how the test script uses the saved model or implements those capabilities, so those links are left unverified.

Main entry points: [`train.py`](https://github.com/adderalfox/nids-with-dqn/blob/main/train.py) (Training loop), [`preprocess.py`](https://github.com/adderalfox/nids-with-dqn/blob/main/preprocess.py) (Feature preprocessing), [`dqn_agent.py`](https://github.com/adderalfox/nids-with-dqn/blob/main/dqn_agent.py) (DQN agent), [`dqn_nids_model.pth`](https://github.com/adderalfox/nids-with-dqn/blob/main/dqn_nids_model.pth) (Trained model)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_data["Traffic data"]
  node_training_data[("Training traffic")]
  node_testing_data[("Testing traffic")]
  node_preprocessor["Feature preprocessing<br/>[preprocess.py]"]
end

subgraph group_learning["RL training"]
  node_trainer["Training loop<br/>[train.py]"]
  node_environment["Detection environment<br/>[nids_env.py]"]
  node_agent["DQN agent<br/>[dqn_agent.py]"]
  node_replay["Replay learning<br/>[dqn_agent.py]"]
end

subgraph group_outputs["Models and evaluation"]
  node_checkpoints["Training checkpoints"]
  node_model["Trained model<br/>[dqn_nids_model.pth]"]
  node_evaluator["Metric evaluation<br/>[test.py]"]
end

node_engineer(("Model operator"))

node_engineer -->|"starts training"| node_trainer
node_trainer -->|"calls"| node_preprocessor
node_training_data -->|"loads"| node_preprocessor
node_testing_data -->|"loads"| node_preprocessor
node_preprocessor -->|"returns features"| node_trainer
node_trainer -->|"creates"| node_environment
node_trainer -->|"creates"| node_agent
node_trainer -->|"resets and steps"| node_environment
node_trainer -->|"selects actions"| node_agent
node_trainer -->|"stores transitions"| node_agent
node_trainer -->|"trains periodically"| node_replay
node_agent -->|"updates networks"| node_replay
node_trainer -->|"saves checkpoints"| node_checkpoints
node_trainer -->|"saves weights"| node_model
node_engineer -.->|"evaluates metrics"| node_evaluator
node_model -.->|"evaluates with"| node_evaluator

click node_training_data "https://github.com/adderalfox/nids-with-dqn/blob/main/UNSW_NB15_training-set.csv"
click node_testing_data "https://github.com/adderalfox/nids-with-dqn/blob/main/UNSW_NB15_testing-set.csv"
click node_preprocessor "https://github.com/adderalfox/nids-with-dqn/blob/main/preprocess.py"
click node_trainer "https://github.com/adderalfox/nids-with-dqn/blob/main/train.py"
click node_environment "https://github.com/adderalfox/nids-with-dqn/blob/main/nids_env.py"
click node_agent "https://github.com/adderalfox/nids-with-dqn/blob/main/dqn_agent.py"
click node_replay "https://github.com/adderalfox/nids-with-dqn/blob/main/dqn_agent.py"
click node_model "https://github.com/adderalfox/nids-with-dqn/blob/main/dqn_nids_model.pth"
click node_evaluator "https://github.com/adderalfox/nids-with-dqn/blob/main/test.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_training_data,node_testing_data,node_preprocessor toneBlue
class node_trainer,node_environment,node_agent,node_replay toneAmber
class node_checkpoints,node_model,node_evaluator toneMint
class node_engineer toneIndigo
```

## Components

### Traffic data

- [Training traffic](https://github.com/adderalfox/nids-with-dqn/blob/main/UNSW_NB15_training-set.csv): `UNSW_NB15_training-set.csv`
- [Testing traffic](https://github.com/adderalfox/nids-with-dqn/blob/main/UNSW_NB15_testing-set.csv): `UNSW_NB15_testing-set.csv`
- [Feature preprocessing](https://github.com/adderalfox/nids-with-dqn/blob/main/preprocess.py): `preprocess.py`

### RL training

- [Training loop](https://github.com/adderalfox/nids-with-dqn/blob/main/train.py): `train.py`
- [Detection environment](https://github.com/adderalfox/nids-with-dqn/blob/main/nids_env.py): `nids_env.py`
- [DQN agent](https://github.com/adderalfox/nids-with-dqn/blob/main/dqn_agent.py): `dqn_agent.py`
- [Replay learning](https://github.com/adderalfox/nids-with-dqn/blob/main/dqn_agent.py): `dqn_agent.py`

### Models and evaluation

- **Training checkpoints**
- [Trained model](https://github.com/adderalfox/nids-with-dqn/blob/main/dqn_nids_model.pth): `dqn_nids_model.pth`
- [Metric evaluation](https://github.com/adderalfox/nids-with-dqn/blob/main/test.py): `test.py`

### Other components

- **Model operator**

## Connections

- Model operator → Training loop: starts training (evidence: `train.py`)
- Training loop → Feature preprocessing: calls (evidence: `train.py`)
- Training traffic → Feature preprocessing: loads
- Testing traffic → Feature preprocessing: loads
- Feature preprocessing → Training loop: returns features (evidence: `train.py`)
- Training loop → Detection environment: creates (evidence: `train.py`)
- Training loop → DQN agent: creates (evidence: `train.py`)
- Training loop → Detection environment: resets and steps (evidence: `train.py`)
- Training loop → DQN agent: selects actions (evidence: `train.py`)
- Training loop → DQN agent: stores transitions (evidence: `train.py`)
- Training loop → Replay learning: trains periodically (evidence: `train.py`)
- DQN agent → Replay learning: updates networks (evidence: `dqn_agent.py`)
- Training loop → Training checkpoints: saves checkpoints (evidence: `train.py`)
- Training loop → Trained model: saves weights (evidence: `train.py`)
- Model operator → Metric evaluation: evaluates metrics (evidence: `README.md`)
- Trained model → Metric evaluation: evaluates with
