# dndrmwn/modsecurity architecture

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

- Interactive diagram: https://gitdiagram.com/dndrmwn/modsecurity
- Repository: https://github.com/dndrmwn/modsecurity

## Overview

ModSecurity 2 is a web application firewall integrated with Apache, IIS, or its standalone server. Its main workflow accepts HTTP traffic, applies configured rules and request-body processing, then allows or intercepts the transaction and can produce audit logs. The tree also shows remote-rule, status-reporting, and audit-log-collector capabilities. Several integration and engine implementations were not sampled, so their connections are omitted or marked unverified rather than inferred as definite calls.

Main entry points: [`apache2/re_operators.c`](https://github.com/dndrmwn/modsecurity/blob/v2/master/apache2/re_operators.c) (Rules and operators), [`apache2/modsecurity.c`](https://github.com/dndrmwn/modsecurity/blob/v2/master/apache2/modsecurity.c) (Transaction engine), [`standalone/api.c`](https://github.com/dndrmwn/modsecurity/blob/v2/master/standalone/api.c) (Standalone API), [`iis/mymodule.cpp`](https://github.com/dndrmwn/modsecurity/blob/v2/master/iis/mymodule.cpp) (IIS module)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_integrations["Server integrations"]
  node_apache_module["Apache module<br/>[mod_security2.c]"]
  node_standalone_server["Standalone server<br/>[server.c]"]
  node_standalone_api["Standalone API<br/>[api.c]"]
  node_iis_module["IIS module<br/>[mymodule.cpp]"]
  node_iis_factory["IIS module factory<br/>[mymodulefactory.h]"]
end

subgraph group_engine["Rule engine"]
  node_engine_core["Transaction engine<br/>[modsecurity.c]"]
  node_configuration["Configuration<br/>[apache2_config.c]"]
  node_rule_engine["Rules and operators<br/>[re_operators.c]"]
  node_transformations["Rule transformations<br/>[re_tfns.c]"]
  node_utility_layer["Engine utilities<br/>[msc_util.c]"]
  node_geo_lookup["Geolocation<br/>[msc_geo.c]"]
  node_re_engine["Regular expressions<br/>[re.c]"]
  node_crypto["Cryptography<br/>[msc_crypt.c]"]
  node_gsb["Google Safe Browsing<br/>[msc_gsb.h]"]
  node_acmp["Pattern matching<br/>[acmp.c]"]
  node_extensions["Rule extensions<br/>[mod_op_strstr.c]"]
end

subgraph group_processing["Request processing"]
  node_request_body["Request body handling<br/>[msc_reqbody.c]"]
  node_body_parsers["Body parsers<br/>[msc_parsers.c]"]
  node_multipart["Multipart parser<br/>[msc_multipart.c]"]
end

subgraph group_operations["Logging and operations"]
  node_audit_logging["Audit logging<br/>[msc_logging.c]"]
  node_remote_rules["Remote rules<br/>[msc_remote_rules.c]"]
  node_status_engine["Status reporting"]
  node_persistence[("Persistent storage<br/>[persist_dbm.c]")]
end

subgraph group_audit["Audit log tools"]
  node_mlogc["Audit log collector<br/>[mlogc.c]"]
  node_audit_parser["Audit log parser<br/>[alp2_pp.c]"]
end

node_http_client(("HTTP client"))

node_http_client -->|"sends requests"| node_standalone_server
node_standalone_server -.->|"uses API"| node_standalone_api
node_standalone_api -.->|"processes transactions"| node_engine_core
node_iis_module -->|"registers factory"| node_iis_factory
node_iis_module -->|"uses API"| node_standalone_api
node_apache_module -.->|"dispatches requests"| node_engine_core
node_configuration -.->|"configures"| node_engine_core
node_engine_core -.->|"evaluates rules"| node_rule_engine
node_rule_engine -.->|"applies transforms"| node_transformations
node_rule_engine -->|"matches patterns"| node_re_engine
node_rule_engine -->|"checks geolocation"| node_geo_lookup
node_rule_engine -->|"checks reputation"| node_gsb
node_rule_engine -->|"uses matching"| node_acmp
node_rule_engine -->|"uses cryptography"| node_crypto
node_rule_engine -->|"uses utilities"| node_utility_layer
node_engine_core -.->|"handles bodies"| node_request_body
node_request_body -.->|"selects parsers"| node_body_parsers
node_body_parsers -.->|"parses multipart"| node_multipart
node_engine_core -.->|"writes audit logs"| node_audit_logging
node_engine_core -.->|"loads rules"| node_remote_rules
node_engine_core -.->|"stores state"| node_persistence
node_engine_core -.->|"reports status"| node_status_engine
node_mlogc -.->|"parses log entries"| node_audit_parser
node_rule_engine -.->|"registers extensions"| node_extensions

click node_apache_module "https://github.com/dndrmwn/modsecurity/blob/v2/master/apache2/mod_security2.c"
click node_standalone_server "https://github.com/dndrmwn/modsecurity/blob/v2/master/standalone/server.c"
click node_standalone_api "https://github.com/dndrmwn/modsecurity/blob/v2/master/standalone/api.c"
click node_iis_module "https://github.com/dndrmwn/modsecurity/blob/v2/master/iis/mymodule.cpp"
click node_iis_factory "https://github.com/dndrmwn/modsecurity/blob/v2/master/iis/mymodulefactory.h"
click node_engine_core "https://github.com/dndrmwn/modsecurity/blob/v2/master/apache2/modsecurity.c"
click node_configuration "https://github.com/dndrmwn/modsecurity/blob/v2/master/apache2/apache2_config.c"
click node_rule_engine "https://github.com/dndrmwn/modsecurity/blob/v2/master/apache2/re_operators.c"
click node_transformations "https://github.com/dndrmwn/modsecurity/blob/v2/master/apache2/re_tfns.c"
click node_utility_layer "https://github.com/dndrmwn/modsecurity/blob/v2/master/apache2/msc_util.c"
click node_request_body "https://github.com/dndrmwn/modsecurity/blob/v2/master/apache2/msc_reqbody.c"
click node_body_parsers "https://github.com/dndrmwn/modsecurity/blob/v2/master/apache2/msc_parsers.c"
click node_multipart "https://github.com/dndrmwn/modsecurity/blob/v2/master/apache2/msc_multipart.c"
click node_audit_logging "https://github.com/dndrmwn/modsecurity/blob/v2/master/apache2/msc_logging.c"
click node_remote_rules "https://github.com/dndrmwn/modsecurity/blob/v2/master/apache2/msc_remote_rules.c"
click node_status_engine "https://github.com/dndrmwn/modsecurity/blob/v2/master/apache2/msc_status_engine.c"
click node_mlogc "https://github.com/dndrmwn/modsecurity/blob/v2/master/mlogc/mlogc.c"
click node_audit_parser "https://github.com/dndrmwn/modsecurity/blob/v2/master/alp2/alp2_pp.c"
click node_persistence "https://github.com/dndrmwn/modsecurity/blob/v2/master/apache2/persist_dbm.c"
click node_geo_lookup "https://github.com/dndrmwn/modsecurity/blob/v2/master/apache2/msc_geo.c"
click node_re_engine "https://github.com/dndrmwn/modsecurity/blob/v2/master/apache2/re.c"
click node_crypto "https://github.com/dndrmwn/modsecurity/blob/v2/master/apache2/msc_crypt.c"
click node_gsb "https://github.com/dndrmwn/modsecurity/blob/v2/master/apache2/msc_gsb.h"
click node_acmp "https://github.com/dndrmwn/modsecurity/blob/v2/master/apache2/acmp.c"
click node_extensions "https://github.com/dndrmwn/modsecurity/blob/v2/master/ext/mod_op_strstr.c"

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_apache_module,node_standalone_server,node_standalone_api,node_iis_module,node_iis_factory,node_http_client toneBlue
class node_engine_core,node_configuration,node_rule_engine,node_transformations,node_utility_layer,node_geo_lookup,node_re_engine,node_crypto,node_gsb,node_acmp,node_extensions toneAmber
class node_request_body,node_body_parsers,node_multipart toneMint
class node_audit_logging,node_remote_rules,node_status_engine,node_persistence toneRose
class node_mlogc,node_audit_parser toneIndigo
```

## Components

### Server integrations

- [Apache module](https://github.com/dndrmwn/modsecurity/blob/v2/master/apache2/mod_security2.c): `apache2/mod_security2.c`
- [Standalone server](https://github.com/dndrmwn/modsecurity/blob/v2/master/standalone/server.c): `standalone/server.c`
- [Standalone API](https://github.com/dndrmwn/modsecurity/blob/v2/master/standalone/api.c): `standalone/api.c`
- [IIS module](https://github.com/dndrmwn/modsecurity/blob/v2/master/iis/mymodule.cpp): `iis/mymodule.cpp`
- [IIS module factory](https://github.com/dndrmwn/modsecurity/blob/v2/master/iis/mymodulefactory.h): `iis/mymodulefactory.h`

### Rule engine

- [Transaction engine](https://github.com/dndrmwn/modsecurity/blob/v2/master/apache2/modsecurity.c): `apache2/modsecurity.c`
- [Configuration](https://github.com/dndrmwn/modsecurity/blob/v2/master/apache2/apache2_config.c): `apache2/apache2_config.c`
- [Rules and operators](https://github.com/dndrmwn/modsecurity/blob/v2/master/apache2/re_operators.c): `apache2/re_operators.c`
- [Rule transformations](https://github.com/dndrmwn/modsecurity/blob/v2/master/apache2/re_tfns.c): `apache2/re_tfns.c`
- [Engine utilities](https://github.com/dndrmwn/modsecurity/blob/v2/master/apache2/msc_util.c): `apache2/msc_util.c`
- [Geolocation](https://github.com/dndrmwn/modsecurity/blob/v2/master/apache2/msc_geo.c): `apache2/msc_geo.c`
- [Regular expressions](https://github.com/dndrmwn/modsecurity/blob/v2/master/apache2/re.c): `apache2/re.c`
- [Cryptography](https://github.com/dndrmwn/modsecurity/blob/v2/master/apache2/msc_crypt.c): `apache2/msc_crypt.c`
- [Google Safe Browsing](https://github.com/dndrmwn/modsecurity/blob/v2/master/apache2/msc_gsb.h): `apache2/msc_gsb.h`
- [Pattern matching](https://github.com/dndrmwn/modsecurity/blob/v2/master/apache2/acmp.c): `apache2/acmp.c`
- [Rule extensions](https://github.com/dndrmwn/modsecurity/blob/v2/master/ext/mod_op_strstr.c): `ext/mod_op_strstr.c`

### Request processing

- [Request body handling](https://github.com/dndrmwn/modsecurity/blob/v2/master/apache2/msc_reqbody.c): `apache2/msc_reqbody.c`
- [Body parsers](https://github.com/dndrmwn/modsecurity/blob/v2/master/apache2/msc_parsers.c): `apache2/msc_parsers.c`
- [Multipart parser](https://github.com/dndrmwn/modsecurity/blob/v2/master/apache2/msc_multipart.c): `apache2/msc_multipart.c`

### Logging and operations

- [Audit logging](https://github.com/dndrmwn/modsecurity/blob/v2/master/apache2/msc_logging.c): `apache2/msc_logging.c`
- [Remote rules](https://github.com/dndrmwn/modsecurity/blob/v2/master/apache2/msc_remote_rules.c): `apache2/msc_remote_rules.c`
- [Status reporting](https://github.com/dndrmwn/modsecurity/blob/v2/master/apache2/msc_status_engine.c): `apache2/msc_status_engine.c`
- [Persistent storage](https://github.com/dndrmwn/modsecurity/blob/v2/master/apache2/persist_dbm.c): `apache2/persist_dbm.c`

### Audit log tools

- [Audit log collector](https://github.com/dndrmwn/modsecurity/blob/v2/master/mlogc/mlogc.c): `mlogc/mlogc.c`
- [Audit log parser](https://github.com/dndrmwn/modsecurity/blob/v2/master/alp2/alp2_pp.c): `alp2/alp2_pp.c`

### Other components

- **HTTP client**

## Connections

- HTTP client → Standalone server: sends requests (evidence: `standalone/server.c`)
- Standalone server → Standalone API: uses API
- Standalone API → Transaction engine: processes transactions
- IIS module → IIS module factory: registers factory (evidence: `iis/mymodule.cpp`)
- IIS module → Standalone API: uses API (evidence: `iis/mymodule.cpp`)
- Apache module → Transaction engine: dispatches requests
- Configuration → Transaction engine: configures
- Transaction engine → Rules and operators: evaluates rules
- Rules and operators → Rule transformations: applies transforms
- Rules and operators → Regular expressions: matches patterns (evidence: `apache2/re_operators.c`)
- Rules and operators → Geolocation: checks geolocation (evidence: `apache2/re_operators.c`)
- Rules and operators → Google Safe Browsing: checks reputation (evidence: `apache2/re_operators.c`)
- Rules and operators → Pattern matching: uses matching (evidence: `apache2/re_operators.c`)
- Rules and operators → Cryptography: uses cryptography (evidence: `apache2/re_operators.c`)
- Rules and operators → Engine utilities: uses utilities (evidence: `apache2/re_operators.c`)
- Transaction engine → Request body handling: handles bodies
- Request body handling → Body parsers: selects parsers
- Body parsers → Multipart parser: parses multipart
- Transaction engine → Audit logging: writes audit logs
- Transaction engine → Remote rules: loads rules
- Transaction engine → Persistent storage: stores state
- Transaction engine → Status reporting: reports status
- Audit log collector → Audit log parser: parses log entries
- Rules and operators → Rule extensions: registers extensions
