# arjun-bhattarai/netrecon architecture

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

- Interactive diagram: https://gitdiagram.com/arjun-bhattarai/netrecon
- Repository: https://github.com/arjun-bhattarai/netrecon

## Overview

1. **Overall shape**
   NetRecon is a small three-layer application: a **browser UI** in `templates/`, a **FastAPI backend** in `app.py`, and a **core analysis engine** in `Core/`. The backend is the orchestration layer that turns user requests into network discovery, port scanning, device classification, and risk analysis.

2. **Entry point and API boundary**
   `app.py` is the main server process. It likely exposes REST endpoints such as `/scan` and `/scan-network` mentioned in the README, and serves the HTML/JS frontend. This is the main boundary between the user interface and the scanning logic.

3. **Frontend subsystem**
   `templates/index.html` and `templates/api.js` form the client-side dashboard. The HTML provides the UI, while `api.js` sends requests to the FastAPI endpoints and renders scan results. The frontend does not appear to contain business logic; it delegates all analysis to the backend.

4. **Network discovery subsystem**
   `Core/network_scanner.py` is the network-wide discovery layer. Based on the README, it discovers active hosts on a subnet like `192.168.1.0/24` and gathers basic identity data such as IP, MAC address, and vendor. This is the first data-producing stage in the pipeline.

5. **Port scanning subsystem**
   `Core/port_scanner.py` handles host-level port inspection. It likely uses low-level socket probing for open ports, and may complement or validate Nmap-based discovery. The output of this module is a per-device list of exposed services or ports.

6. **Device classification subsystem**
   `Core/device_classifier.py` turns raw scan artifacts into a device type label such as router, PC, IP camera, or IoT device. This is a fingerprinting layer that likely uses observed ports, vendor information, and other host traits rather than requiring user input.

7. **Risk analysis subsystem**
   `Core/risk_engine.py` evaluates the security posture of a device based on what is exposed. The README calls out services such as SSH, SMB, and RDP, so this module likely maps open ports/services to a risk score or warnings. This is the final enrichment step before results are returned to the UI.

8. **End-to-end data flow**
   The main flow is: **user action in the browser → API request to FastAPI → network discovery → port scanning → device classification → risk scoring → JSON response → dashboard display**. For whole-network scans, the pipeline starts with subnet discovery and then enriches each discovered host. For single-host scans, the flow likely starts at the port-scanning stage.

9. **External tooling and runtime dependencies**
   The project runs on **Python** and uses **FastAPI** for the server. The README explicitly calls out **Nmap** for network discovery and **socket** for low-level port scanning. These tools are the key infrastructure dependencies and materially shape the architecture.

10. **Primary architectural boundary**
    The `Core/` package is the domain logic boundary. Everything under `Core/` is responsible for scan intelligence, while `app.py` is responsible for HTTP, request handling, and response formatting. That separation makes it straightforward to diagram the system as UI → API → core engines.

11. **Intended deployment context**
    This is a local-network reconnaissance tool, not a general internet-facing service. Its scope is centered on authorized LAN scanning and security inspection, so the important architectural constraint is that it operates on internal subnets and host-level exposures rather than on cloud resources or external integrations.

12. **What to show in an architecture diagram**
    A good diagram would include: a browser/dashboard, a FastAPI backend, the four core modules as separate processing blocks, and the external scanning dependencies (Nmap and socket) feeding those modules. The final outputs are discovered devices, open ports, device types, and risk indicators displayed back in the UI.

Main entry points: [`app.py`](https://github.com/arjun-bhattarai/netrecon/blob/main/app.py) (FastAPI app), [`Core/network_scanner.py`](https://github.com/arjun-bhattarai/netrecon/blob/main/Core/network_scanner.py) (Network scan), [`Core/port_scanner.py`](https://github.com/arjun-bhattarai/netrecon/blob/main/Core/port_scanner.py) (Port scan), [`templates/api.js`](https://github.com/arjun-bhattarai/netrecon/blob/main/templates/api.js) (API client)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_frontend["Frontend"]
  node_browser(("Browser<br/>user interface"))
  node_dashboard["Dashboard<br/>static UI<br/>[index.html]"]
  node_api_js["API client<br/>client script<br/>[api.js]"]
end

subgraph group_backend["Backend"]
  node_app_py["FastAPI app<br/>server entry<br/>[app.py]"]
  node_scan_routes{{"Scan routes<br/>request boundary"}}
  node_response_fmt["Response format<br/>payload shaping"]
  node_scan_results["Scan results<br/>discovery output"]
  node_risk_flags["Risk flags<br/>analysis output"]
end

subgraph group_core["Core"]
  node_network_scanner["Network scan<br/>discovery engine<br/>[network_scanner.py]"]
  node_port_scanner["Port scan<br/>probe engine<br/>[port_scanner.py]"]
  node_device_classifier["Classifier<br/>fingerprinting"]
  node_risk_engine["Risk engine<br/>assessment<br/>[risk_engine.py]"]
end

subgraph group_external["External"]
  node_nmap{{"Nmap<br/>external tool"}}
  node_socket{{"Socket<br/>runtime library"}}
  node_python{{"Python<br/>runtime"}}
end

node_browser -->|"opens"| node_dashboard
node_dashboard -->|"loads"| node_api_js
node_api_js -->|"requests"| node_scan_routes
node_scan_routes -->|"handled by"| node_app_py
node_app_py -->|"network scan"| node_network_scanner
node_app_py -->|"port scan"| node_port_scanner
node_app_py -->|"classify"| node_device_classifier
node_app_py -->|"assess"| node_risk_engine
node_network_scanner -->|"uses"| node_nmap
node_port_scanner -->|"uses"| node_socket
node_network_scanner -->|"produces"| node_scan_results
node_port_scanner -->|"produces"| node_scan_results
node_device_classifier -->|"enriches"| node_scan_results
node_risk_engine -->|"produces"| node_risk_flags
node_scan_results -->|"assembled by"| node_response_fmt
node_risk_flags -->|"assembled by"| node_response_fmt
node_response_fmt -->|"returns"| node_api_js
node_app_py -->|"runs on"| node_python

click node_dashboard "https://github.com/arjun-bhattarai/netrecon/blob/main/templates/index.html"
click node_api_js "https://github.com/arjun-bhattarai/netrecon/blob/main/templates/api.js"
click node_app_py "https://github.com/arjun-bhattarai/netrecon/blob/main/app.py"
click node_network_scanner "https://github.com/arjun-bhattarai/netrecon/blob/main/Core/network_scanner.py"
click node_port_scanner "https://github.com/arjun-bhattarai/netrecon/blob/main/Core/port_scanner.py"
click node_device_classifier "https://github.com/arjun-bhattarai/netrecon/blob/main/Core/device_classifier.py"
click node_risk_engine "https://github.com/arjun-bhattarai/netrecon/blob/main/Core/risk_engine.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_browser,node_dashboard,node_api_js toneBlue
class node_app_py,node_scan_routes,node_response_fmt,node_scan_results,node_risk_flags toneAmber
class node_network_scanner,node_port_scanner,node_device_classifier,node_risk_engine toneMint
class node_nmap,node_socket,node_python toneRose
```

## Components

### Frontend

Browser-facing UI

- **Browser**: user interface · User initiates scans and views results
- [Dashboard](https://github.com/arjun-bhattarai/netrecon/blob/main/templates/index.html): static UI · Main scan interface and results view · `templates/index.html`
- [API client](https://github.com/arjun-bhattarai/netrecon/blob/main/templates/api.js): client script · Calls backend endpoints and renders responses · `templates/api.js`

### Backend

HTTP and orchestration layer

- [FastAPI app](https://github.com/arjun-bhattarai/netrecon/blob/main/app.py): server entry · HTTP server, routing, and orchestration · `app.py`
- **Scan routes**: request boundary · Exposes scan and network-scan operations
- **Response format**: payload shaping · Packages analysis results for the UI
- **Scan results**: discovery output · Hosts, ports, device types, and vendor data
- **Risk flags**: analysis output · Warnings and security posture indicators

### Core

Scan and analysis engines

- [Network scan](https://github.com/arjun-bhattarai/netrecon/blob/main/Core/network_scanner.py): discovery engine · Finds active hosts and basic identity data · `Core/network_scanner.py`
- [Port scan](https://github.com/arjun-bhattarai/netrecon/blob/main/Core/port_scanner.py): probe engine · Checks host ports and exposed services · `Core/port_scanner.py`
- [Classifier](https://github.com/arjun-bhattarai/netrecon/blob/main/Core/device_classifier.py): fingerprinting · Infers device type from scan artifacts · `Core/device_classifier.py`
- [Risk engine](https://github.com/arjun-bhattarai/netrecon/blob/main/Core/risk_engine.py): assessment · Scores exposed services and flags concerns · `Core/risk_engine.py`

### External

Runtime and scanning dependencies

- **Nmap**: external tool · Network discovery dependency
- **Socket**: runtime library · Low-level port probing dependency
- **Python**: runtime · Executes the backend and core modules

## Connections

- Browser → Dashboard: opens · The user views the web dashboard
- Dashboard → API client: loads · HTML loads client-side request logic
- API client → Scan routes: requests · Client calls scan endpoints
- Scan routes → FastAPI app: handled by · FastAPI receives HTTP requests
- FastAPI app → Network scan: network scan · Subnet discovery starts here
- FastAPI app → Port scan: port scan · Host-level probing for open services
- FastAPI app → Classifier: classify · Observed traits are turned into device labels
- FastAPI app → Risk engine: assess · Exposure data is converted into risk signals
- Network scan → Nmap: uses · Discovery relies on Nmap
- Port scan → Socket: uses · Port probing relies on sockets
- Network scan → Scan results: produces · Outputs discovered hosts and identity data
- Port scan → Scan results: produces · Outputs open ports and services
- Classifier → Scan results: enriches · Adds inferred device types
- Risk engine → Risk flags: produces · Creates warnings and risk scores
- Scan results → Response format: assembled by · Backend combines discovery outputs
- Risk flags → Response format: assembled by · Risk data is merged into the response
- Response format → API client: returns · JSON response is consumed by the UI
- FastAPI app → Python: runs on · Backend executes in the Python runtime
