# mahdiisabry1/waf architecture

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

- Interactive diagram: https://gitdiagram.com/mahdiisabry1/waf
- Repository: https://github.com/mahdiisabry1/waf

## Overview

OWASP Security Lab is a browser-based security testing and monitoring app. Users run attack scenarios in the simulator; the Express server inspects requests with the WAF, records matches, and serves log/stat APIs and live updates to the dashboard. The README also describes a SIEM alerting capability, but its implementation is not present in the supplied tree, so that branch is shown as documented rather than verified. The README mentions MongoDB, while the sampled runtime uses an in-memory log store; the empty db.js excerpt does not establish a database connection.

Main entry points: [`backend/src/app.js`](https://github.com/mahdiisabry1/waf/blob/OWASPSL/backend/src/app.js) (Express server), [`backend/src/middleware/waf.js`](https://github.com/mahdiisabry1/waf/blob/OWASPSL/backend/src/middleware/waf.js) (WAF middleware), [`frontend/dashboard.js`](https://github.com/mahdiisabry1/waf/blob/OWASPSL/frontend/dashboard.js) (Live dashboard), [`frontend/simulator.html`](https://github.com/mahdiisabry1/waf/blob/OWASPSL/frontend/simulator.html) (Attack simulator)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_frontend["Browser tools"]
  node_simulator["Attack simulator<br/>[simulator.html]"]
  node_dashboard["Live dashboard<br/>[dashboard.js]"]
end

subgraph group_protection["Request inspection"]
  node_server["Express server<br/>[app.js]"]
  node_waf["WAF middleware<br/>[waf.js]"]
  node_rules["OWASP rules<br/>[rules.js]"]
  node_classifier["Match classifier<br/>[classifier.js]"]
end

subgraph group_monitoring["Logs and live monitoring"]
  node_logstore[("In-memory log store<br/>[logStore.js]")]
  node_wshub["WebSocket hub<br/>[wsHub.js]"]
  node_siem["SIEM alerting"]
end

node_user(("Lab user"))

node_user -->|"runs scenarios"| node_simulator
node_simulator -->|"sends test requests"| node_server
node_server -->|"registers middleware"| node_waf
node_waf -->|"matches patterns"| node_rules
node_waf -->|"classifies match"| node_classifier
node_waf -->|"reports matches"| node_logstore
node_server -->|"serves log APIs"| node_logstore
node_server -->|"broadcasts updates"| node_wshub
node_dashboard -->|"fetches stats and logs"| node_server
node_dashboard -->|"opens WebSocket"| node_server
node_user -->|"views monitoring"| node_dashboard
node_siem -.->|"broadcasts alerts"| node_wshub

click node_simulator "https://github.com/mahdiisabry1/waf/blob/OWASPSL/frontend/simulator.html"
click node_dashboard "https://github.com/mahdiisabry1/waf/blob/OWASPSL/frontend/dashboard.js"
click node_server "https://github.com/mahdiisabry1/waf/blob/OWASPSL/backend/src/app.js"
click node_waf "https://github.com/mahdiisabry1/waf/blob/OWASPSL/backend/src/middleware/waf.js"
click node_rules "https://github.com/mahdiisabry1/waf/blob/OWASPSL/backend/src/owasp/rules.js"
click node_classifier "https://github.com/mahdiisabry1/waf/blob/OWASPSL/backend/src/owasp/classifier.js"
click node_logstore "https://github.com/mahdiisabry1/waf/blob/OWASPSL/backend/src/services/logStore.js"
click node_wshub "https://github.com/mahdiisabry1/waf/blob/OWASPSL/backend/src/services/wsHub.js"
click node_siem "https://github.com/mahdiisabry1/waf/tree/OWASPSL/backend/src/services"

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_simulator,node_dashboard,node_user toneBlue
class node_server,node_waf,node_rules,node_classifier toneAmber
class node_logstore,node_wshub,node_siem toneMint
```

## Components

### Browser tools

- [Attack simulator](https://github.com/mahdiisabry1/waf/blob/OWASPSL/frontend/simulator.html): `frontend/simulator.html`
- [Live dashboard](https://github.com/mahdiisabry1/waf/blob/OWASPSL/frontend/dashboard.js): `frontend/dashboard.js`

### Request inspection

- [Express server](https://github.com/mahdiisabry1/waf/blob/OWASPSL/backend/src/app.js): `backend/src/app.js`
- [WAF middleware](https://github.com/mahdiisabry1/waf/blob/OWASPSL/backend/src/middleware/waf.js): `backend/src/middleware/waf.js`
- [OWASP rules](https://github.com/mahdiisabry1/waf/blob/OWASPSL/backend/src/owasp/rules.js): `backend/src/owasp/rules.js`
- [Match classifier](https://github.com/mahdiisabry1/waf/blob/OWASPSL/backend/src/owasp/classifier.js): `backend/src/owasp/classifier.js`

### Logs and live monitoring

- [In-memory log store](https://github.com/mahdiisabry1/waf/blob/OWASPSL/backend/src/services/logStore.js): `backend/src/services/logStore.js`
- [WebSocket hub](https://github.com/mahdiisabry1/waf/blob/OWASPSL/backend/src/services/wsHub.js): `backend/src/services/wsHub.js`
- [SIEM alerting](https://github.com/mahdiisabry1/waf/tree/OWASPSL/backend/src/services): `backend/src/services`

### Other components

- **Lab user**

## Connections

- Lab user → Attack simulator: runs scenarios (evidence: `README.md`)
- Attack simulator → Express server: sends test requests (evidence: `README.md`)
- Express server → WAF middleware: registers middleware (evidence: `backend/src/app.js`)
- WAF middleware → OWASP rules: matches patterns (evidence: `backend/src/middleware/waf.js`)
- WAF middleware → Match classifier: classifies match (evidence: `backend/src/middleware/waf.js`)
- WAF middleware → In-memory log store: reports matches (evidence: `backend/src/app.js`)
- Express server → In-memory log store: serves log APIs (evidence: `backend/src/app.js`)
- Express server → WebSocket hub: broadcasts updates (evidence: `backend/src/app.js`)
- Live dashboard → Express server: fetches stats and logs (evidence: `frontend/dashboard.js`)
- Live dashboard → Express server: opens WebSocket (evidence: `frontend/dashboard.js`)
- Lab user → Live dashboard: views monitoring (evidence: `README.md`)
- SIEM alerting → WebSocket hub: broadcasts alerts (evidence: `README.md`)
