# akazayh/cyber-guard architecture

> Architecture diagram of the GitHub repository akazayh/cyber-guard, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2026-05-28). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/akazayh/cyber-guard
- Repository: https://github.com/akazayh/cyber-guard

## Overview

CyberGuard is a single Python 3.8+ security toolkit organized as a menu-driven CLI application. The repository is small but split into clear functional modules under `CyberGuard/modules`, with `main.py` acting as the entrypoint and orchestration layer.

1. **Top-level architecture**
   - `main.py` is the user-facing controller: it presents the main menu, routes the user into one of the security tools, and likely coordinates return-to-menu behavior.
   - The rest of the repo is a set of feature modules that are mostly independent: network scanning, IDS monitoring, log analysis, and firewall management.

2. **Primary interaction model**
   - This is not a client-server app; it is an interactive local tool.
   - The architecture is a command-dispatch loop: user input selects a subsystem, the subsystem performs privileged system/network actions, then results are shown in the terminal and/or written to files.

3. **Network scanning subsystem**
   - `modules/network_scaner.py` encapsulates the Nmap-based scanning workflow.
   - It handles different scan modes, port targeting, service/version detection, and more advanced scan styles such as stealth/aggressive/vulnerability-oriented scans.
   - Its output is not only terminal text; scan results are persisted into an archive directory (`Archives_Nmap/` per the README), which makes scanning both interactive and auditable.

4. **Intrusion detection subsystem**
   - `modules/ids.py` is the live monitoring engine.
   - It is responsible for real-time traffic observation on wired and wireless interfaces, classifying suspicious activity, and generating alerts for events like ARP/DNS spoofing, floods, port scanning, and some wireless attack patterns.
   - This module appears to sit closest to raw network traffic, likely acting as the highest-privilege and most time-sensitive part of the system.

5. **IDS output and logging flow**
   - The IDS does not just alert in memory; it also writes session data to logs and PCAP traces.
   - That creates a clear pipeline: packet capture / observation -> detection logic -> live terminal alerts -> persisted forensic artifacts.
   - Those artifacts become the input for the log analysis subsystem.

6. **Log analysis subsystem**
   - `modules/analyze_logs.py` is the offline analysis layer.
   - It consumes IDS-generated logs and possibly other supported log sources, then searches for patterns, anomalies, and notable security events.
   - This is a boundary between live detection and retrospective investigation: unlike the IDS, it works on stored evidence rather than live traffic.

7. **Firewall management subsystem**
   - `modules/firewall_manger.py` controls local firewall policy on the host.
   - It exposes actions for blocking/unblocking IPs, managing ports and port ranges, and filtering protocols such as TCP, UDP, and ICMP.
   - The README’s “rule persistence” implies this module also touches system configuration so rules survive reboots, making it a host-level enforcement component rather than just a temporary session tool.

8. **Shared support code**
   - `modules/utils.py` is the cross-cutting support layer.
   - In a repo like this, that typically means shared formatting, validation, I/O helpers, terminal presentation, and common state handling used by the feature modules.
   - This module is the likely place where UI consistency and repeated logic are centralized so the four main tools remain decoupled.

9. **External dependencies and runtime constraints**
   - The app is Linux-oriented and requires root/sudo privileges, which is a major architectural constraint.
   - The README explicitly calls out `nmap`, `iptables`, and `beep`; those are system-level dependencies that directly influence how the modules operate.
   - The tool is therefore tightly bound to the local OS networking stack and firewall, not just Python libraries.

10. **Artifacts and persistence**
   - Key artifacts include Nmap archives, IDS logs, PCAP captures, and persistent firewall rules.
   - These files form the project’s main data boundary: live system events are transformed into stored evidence, then later read back by the analyzer.
   - That persistence is what makes the toolkit useful for both immediate response and later forensic review.

11. **Security/privilege boundary**
   - CyberGuard is explicitly an authorized-admin tool, not a passive viewer.
   - Its most sensitive operations cross from user-space Python into privileged system operations: packet monitoring, firewall rule changes, and network scanning with advanced techniques.
   - For an architecture diagram, this is an important boundary to show between the CLI app and the host OS/network stack.

12. **Overall system decomposition**
   - You can think of the repo as four user-facing capabilities wrapped by one CLI shell:
     - active reconnaissance,
     - live intrusion detection,
     - offline log forensics,
     - local firewall enforcement.
   - The modules are connected mainly through shared UI conventions and persisted artifacts, not through a complex internal service graph.

Main entry points: [`CyberGuard/main.py`](https://github.com/akazayh/cyber-guard/blob/main/CyberGuard/main.py) (Main menu), [`CyberGuard/modules/ids.py`](https://github.com/akazayh/cyber-guard/blob/main/CyberGuard/modules/ids.py) (IDS monitor), [`CyberGuard/modules/network_scaner.py`](https://github.com/akazayh/cyber-guard/blob/main/CyberGuard/modules/network_scaner.py) (Network scan), [`CyberGuard/modules/firewall_manger.py`](https://github.com/akazayh/cyber-guard/blob/main/CyberGuard/modules/firewall_manger.py) (Firewall manager)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_grp_cli["CLI shell"]
  node_main_py["Main menu<br/>cli entrypoint<br/>[main.py]"]
  node_utils_py["Shared utils<br/>support<br/>[utils.py]"]
  node_terminal_ui(("Terminal I/O<br/>interface"))
end

subgraph group_grp_tools["Security tools"]
  node_scan_mod["Network scan<br/>scanner<br/>[network_scaner.py]"]
  node_ids_mod["IDS monitor<br/>detection engine<br/>[ids.py]"]
  node_logs_mod["Log analysis<br/>forensics<br/>[analyze_logs.py]"]
  node_fw_mod["Firewall manager<br/>policy control<br/>[firewall_manger.py]"]
end

subgraph group_grp_data["Artifacts"]
  node_nmap_archive[("Nmap archive<br/>scan output")]
  node_ids_logs["IDS logs<br/>event log"]
  node_pcap_traces["PCAP traces<br/>capture artifact"]
  node_fw_rules[("Firewall rules<br/>policy state")]
end

subgraph group_grp_host["Host stack"]
  node_host_stack{{"OS network stack<br/>privileged boundary"}}
  node_nmap_dep["Nmap<br/>system dependency"]
  node_iptables_dep["iptables<br/>system dependency"]
  node_beep_dep["beep<br/>system dependency"]
end

node_main_py -->|"drives"| node_terminal_ui
node_main_py -->|"dispatches"| node_scan_mod
node_main_py -->|"dispatches"| node_ids_mod
node_main_py -->|"dispatches"| node_logs_mod
node_main_py -->|"dispatches"| node_fw_mod
node_main_py -->|"uses"| node_utils_py
node_scan_mod -->|"uses"| node_utils_py
node_ids_mod -->|"uses"| node_utils_py
node_logs_mod -->|"uses"| node_utils_py
node_fw_mod -->|"uses"| node_utils_py
node_scan_mod -->|"invokes"| node_nmap_dep
node_scan_mod -->|"writes"| node_nmap_archive
node_ids_mod -->|"observes"| node_host_stack
node_ids_mod -->|"writes"| node_ids_logs
node_ids_mod -->|"captures"| node_pcap_traces
node_ids_mod -->|"alerts"| node_beep_dep
node_logs_mod -->|"reads"| node_ids_logs
node_logs_mod -->|"reads"| node_pcap_traces
node_fw_mod -->|"controls"| node_iptables_dep
node_fw_mod -->|"persists"| node_fw_rules
node_fw_mod -->|"enforces"| node_host_stack
node_scan_mod -->|"probes"| node_host_stack

click node_main_py "https://github.com/akazayh/cyber-guard/blob/main/CyberGuard/main.py"
click node_utils_py "https://github.com/akazayh/cyber-guard/blob/main/CyberGuard/modules/utils.py"
click node_scan_mod "https://github.com/akazayh/cyber-guard/blob/main/CyberGuard/modules/network_scaner.py"
click node_ids_mod "https://github.com/akazayh/cyber-guard/blob/main/CyberGuard/modules/ids.py"
click node_logs_mod "https://github.com/akazayh/cyber-guard/blob/main/CyberGuard/modules/analyze_logs.py"
click node_fw_mod "https://github.com/akazayh/cyber-guard/blob/main/CyberGuard/modules/firewall_manger.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_main_py,node_utils_py,node_terminal_ui toneBlue
class node_scan_mod,node_ids_mod,node_logs_mod,node_fw_mod toneAmber
class node_nmap_archive,node_ids_logs,node_pcap_traces,node_fw_rules toneMint
class node_host_stack,node_nmap_dep,node_iptables_dep,node_beep_dep toneRose
```

## Components

### CLI shell

Interactive menu and shared presentation layer

- [Main menu](https://github.com/akazayh/cyber-guard/blob/main/CyberGuard/main.py): cli entrypoint · Menu-driven controller that routes users to each tool · `CyberGuard/main.py`
- [Shared utils](https://github.com/akazayh/cyber-guard/blob/main/CyberGuard/modules/utils.py): support · Common formatting, validation, and I/O helpers shared across modules · `CyberGuard/modules/utils.py`
- **Terminal I/O**: interface · User-facing command loop and console output surface

### Security tools

Core operational modules for scanning, detection, analysis, and enforcement

- [Network scan](https://github.com/akazayh/cyber-guard/blob/main/CyberGuard/modules/network_scaner.py): scanner · Nmap-based scanning workflows and scan modes · `CyberGuard/modules/network_scaner.py`
- [IDS monitor](https://github.com/akazayh/cyber-guard/blob/main/CyberGuard/modules/ids.py): detection engine · Live network observation and suspicious-activity detection · `CyberGuard/modules/ids.py`
- [Log analysis](https://github.com/akazayh/cyber-guard/blob/main/CyberGuard/modules/analyze_logs.py): forensics · Offline analysis of IDS logs and related evidence · `CyberGuard/modules/analyze_logs.py`
- [Firewall manager](https://github.com/akazayh/cyber-guard/blob/main/CyberGuard/modules/firewall_manger.py): policy control · Host firewall actions for blocking, ports, and protocol filtering · `CyberGuard/modules/firewall_manger.py`

### Artifacts

Persisted evidence and policy state produced or consumed by the tools

- **Nmap archive**: scan output · Persisted scan results for later review
- **IDS logs**: event log · Session logs written by live monitoring
- **PCAP traces**: capture artifact · Packet capture files used for forensic review
- **Firewall rules**: policy state · Persisted host firewall configuration

### Host stack

External system capabilities and OS-level dependencies

- **OS network stack**: privileged boundary · Local kernel and networking facilities accessed by the toolkit
- **Nmap**: system dependency · External scanner used by the network scan module
- **iptables**: system dependency · External firewall control interface
- **beep**: system dependency · Audible alert dependency used by monitoring workflows

## Connections

- Main menu → Terminal I/O: drives · Presents menu and routes user choices
- Main menu → Network scan: dispatches · Launches the scanning workflow
- Main menu → IDS monitor: dispatches · Launches live monitoring
- Main menu → Log analysis: dispatches · Launches offline analysis
- Main menu → Firewall manager: dispatches · Launches firewall management
- Main menu → Shared utils: uses · Shares common helpers and UI conventions
- Network scan → Shared utils: uses · Shared formatting and input/output helpers
- IDS monitor → Shared utils: uses · Shared helpers for alerts and presentation
- Log analysis → Shared utils: uses · Shared helpers for reporting and parsing
- Firewall manager → Shared utils: uses · Shared helpers for host-policy actions
- Network scan → Nmap: invokes · Runs external scanning commands
- Network scan → Nmap archive: writes · Persists scan output for later review
- IDS monitor → OS network stack: observes · Monitors live traffic on the local network stack
- IDS monitor → IDS logs: writes · Stores detection sessions and alerts
- IDS monitor → PCAP traces: captures · Produces packet capture artifacts
- IDS monitor → beep: alerts · May emit audible warnings
- Log analysis → IDS logs: reads · Consumes IDS session logs
- Log analysis → PCAP traces: reads · Uses captured traces as forensic evidence
- Firewall manager → iptables: controls · Applies host firewall rules through system tooling
- Firewall manager → Firewall rules: persists · Maintains rule state across sessions or reboot
- Firewall manager → OS network stack: enforces · Interacts with kernel-level packet filtering
- Network scan → OS network stack: probes · Performs network reconnaissance against local interfaces and targets
