# da2minutenoodle/maxsecuritywaf architecture

> Architecture diagram of the GitHub repository da2minutenoodle/maxsecuritywaf, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2025-04-03). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/da2minutenoodle/maxsecuritywaf
- Repository: https://github.com/da2minutenoodle/maxsecuritywaf

## Overview

##### Main Components
- Frontend/UI Layer:
- Represented by the Razor pages in the Pages directory. This includes multiple UI components (e.g., Dashboard, Login, Logs, UserManagement, Blacklist) and static assets (CSS and JS in wwwroot).
- The Components subfolder housing reusable elements like NavMenu, LoginRedirect, and Switch.

- Controllers and API Layer:
- Controllers (LoginController.cs, LogController.cs) serve as endpoints for processing HTTP requests.
- They receive input from the UI and invoke backend services.

- Business Logic / Services Layer:
- Contains service classes (e.g., LogService, WAFMiddleware, WAFMiddlewareService) that encapsulate core business logic for logging actions, handling WAF policies, and processing middleware requests.

- Data Access / Persistence Layer:
- Managed by the Entity Framework, with the WAFContext file and associated Migrations directory.
- This is where database models (e.g., LogEntry.cs) are defined and schema migrations are maintained.

- External Integration:
- Interaction with WebGoat, an external vulnerable application. Although WebGoat runs as a separate Java process, the README specifies its address and integration handling through configuration within appsettings.json.

- Configuration & Startup:
- Files like Program.cs, appsettings.json, and configuration for SSL in the README illustrate how deployment, endpoint configuration (HTTP/HTTPS), and external dependency endpoints (WebGoat) are set up.

##### Relationships and Interactions
- The Browser (or client) interacts with the UI layer’s Razor pages, which are loaded along with static assets.
- User actions trigger HTTP requests routed to the Controllers (e.g., LoginController, LogController).
- Controllers utilize the Services layer (e.g., LogService and WAFMiddleware) to process business logic and implement the WAF logic.
- The Services then interact with the Data Access layer (through WAFContext and Entity Framework) to persist or retrieve data (such as log entries).
- The configuration allows the middleware and services to communicate with the WebGoat application by pointing to its address, ensuring that requests or data can be forwarded or compared.
- Deployment configuration (via appsettings.json) dictates critical operational aspects like endpoint URLs, SSL certificates, and firewall settings.

##### Architectural Patterns and Design Principles
- Separation of Concerns: Clearly divided layers (UI, Controller, Service, Data Access) ensure that each component has its own responsibility.
- Modular Design: The use of Razor components for the UI and dedicated service classes makes the system easily extensible.
- Middleware Integration: Custom middleware (WAFMiddleware) intercepts and processes HTTP requests to enable security features.
- External Service Integration: The system design considers external dependencies (WebGoat) and allows configuration changes to accommodate different environments.

## Diagram (Mermaid)

```mermaid
flowchart TD
    Browser["Browser"]:::external

    subgraph "Frontend/UI Layer"
        Dashboard["Dashboard Page"]:::ui
        Login["Login Page"]:::ui
        Logs["Logs Page"]:::ui
        Blacklist["Blacklist Page"]:::ui
        Rules["Rules Page"]:::ui
        UserManagement["User Management Page"]:::ui
        Index["Index Page"]:::ui
        LoginRedirect["Login Redirect Component"]:::ui
        NavMenu["Nav Menu Component"]:::ui
        Switch["Switch Component"]:::ui
        MainLayout["Main Layout"]:::ui
        Host["Host Page"]:::ui
        Assets["Static Assets (CSS/JS)"]:::ui
    end

    subgraph "Controllers & API Layer"
        LoginController["Login Controller"]:::controller
        LogController["Log Controller"]:::controller
    end

    subgraph "Business Logic / Services Layer"
        LogService["Log Service"]:::service
        WAFMiddleware["WAF Middleware"]:::service
        WAFMiddlewareService["WAF Middleware Service"]:::service
    end

    subgraph "Data Access / Persistence Layer"
        WAFContext["WAF Context"]:::database
        Migrations["Migrations"]:::database
        LogEntry["Log Entry Model"]:::database
    end

    subgraph "Configuration & Startup"
        Program["Program"]:::config
        AppSettings["App Settings"]:::config
        Projects["Project Files"]:::config
        DotnetTools["Dotnet Tools"]:::config
        LaunchSettings["Launch Settings"]:::config
    end

    WebGoat["WebGoat Server"]:::external

    %% External Requests
    Browser -->|"HTTP_request"| Index

    %% UI to Controllers
    Login -->|"submit"| LoginController
    Logs -->|"request_logs"| LogController

    %% Controllers to Services
    LoginController -->|"calls_service"| LogService
    LogController -->|"calls_service"| LogService

    %% Services to Data Access
    LogService -->|"read/write"| WAFContext
    WAFMiddleware -->|"filters"| WAFContext

    %% Service Interaction Internal
    WAFMiddlewareService -->|"controls"| WAFMiddleware

    %% External Integration
    WAFMiddlewareService -.->|"integrates"| WebGoat

    %% Configuration influences
    Program -->|"initializes"| LoginController
    Program -->|"initializes"| LogController
    AppSettings -->|"configures"| LoginController
    AppSettings -->|"configures"| LogController
    AppSettings -->|"configures"| LogService
    AppSettings -->|"configures"| WAFMiddleware
    AppSettings -->|"configures"| WAFMiddlewareService
    LaunchSettings --> Program
    Projects --> Program
    DotnetTools --> Program

    %% Class Definitions
    classDef ui fill:#AED6F1,stroke:#1B4F72,stroke-width:2px;
    classDef controller fill:#F9E79F,stroke:#B7950B,stroke-width:2px;
    classDef service fill:#A9DFBF,stroke:#1D8348,stroke-width:2px;
    classDef database fill:#F5B7B1,stroke:#922B21,stroke-width:2px;
    classDef config fill:#D2B4DE,stroke:#6C3483,stroke-width:2px;
    classDef external fill:#FAD7A0,stroke:#D35400,stroke-width:2px;

    %% Click Events for Frontend/UI Layer
    click Dashboard "https://github.com/da2minutenoodle/maxsecuritywaf/blob/main/Pages/Dashboard.razor"
    click Login "https://github.com/da2minutenoodle/maxsecuritywaf/blob/main/Pages/Login.razor"
    click Logs "https://github.com/da2minutenoodle/maxsecuritywaf/blob/main/Pages/Logs.razor"
    click Blacklist "https://github.com/da2minutenoodle/maxsecuritywaf/blob/main/Pages/Blacklist.razor"
    click Rules "https://github.com/da2minutenoodle/maxsecuritywaf/blob/main/Pages/Rules.razor"
    click UserManagement "https://github.com/da2minutenoodle/maxsecuritywaf/blob/main/Pages/UserManagement.razor"
    click Index "https://github.com/da2minutenoodle/maxsecuritywaf/blob/main/Pages/Index.razor"
    click LoginRedirect "https://github.com/da2minutenoodle/maxsecuritywaf/blob/main/Pages/Components/LoginRedirect.razor"
    click NavMenu "https://github.com/da2minutenoodle/maxsecuritywaf/blob/main/Pages/Components/NavMenu.razor"
    click Switch "https://github.com/da2minutenoodle/maxsecuritywaf/blob/main/Pages/Components/Switch.razor"
    click MainLayout "https://github.com/da2minutenoodle/maxsecuritywaf/blob/main/Pages/MainLayout.razor"
    click Assets "https://github.com/da2minutenoodle/maxsecuritywaf/tree/main/wwwroot"
    click Host "https://github.com/da2minutenoodle/maxsecuritywaf/blob/main/Pages/_Host.cshtml"

    %% Click Events for Controllers & API Layer
    click LoginController "https://github.com/da2minutenoodle/maxsecuritywaf/blob/main/Controllers/LoginController.cs"
    click LogController "https://github.com/da2minutenoodle/maxsecuritywaf/blob/main/Controllers/LogController.cs"

    %% Click Events for Business Logic / Services Layer
    click LogService "https://github.com/da2minutenoodle/maxsecuritywaf/blob/main/Services/LogService.cs"
    click WAFMiddleware "https://github.com/da2minutenoodle/maxsecuritywaf/blob/main/Services/WAFMiddleware.cs"
    click WAFMiddlewareService "https://github.com/da2minutenoodle/maxsecuritywaf/blob/main/Services/WAFMiddlewareService.cs"

    %% Click Events for Data Access / Persistence Layer
    click WAFContext "https://github.com/da2minutenoodle/maxsecuritywaf/blob/main/WAFContext.cs"
    click Migrations "https://github.com/da2minutenoodle/maxsecuritywaf/tree/main/Migrations"
    click LogEntry "https://github.com/da2minutenoodle/maxsecuritywaf/blob/main/LogEntry.cs"

    %% Click Events for Configuration & Startup
    click Program "https://github.com/da2minutenoodle/maxsecuritywaf/blob/main/Program.cs"
    click AppSettings "https://github.com/da2minutenoodle/maxsecuritywaf/blob/main/appsettings.json"
    click Projects "https://github.com/da2minutenoodle/maxsecuritywaf/blob/main/MaxSecurityWAF.csproj"
    click DotnetTools "https://github.com/da2minutenoodle/maxsecuritywaf/blob/main/.config/dotnet-tools.json"
    click LaunchSettings "https://github.com/da2minutenoodle/maxsecuritywaf/blob/main/Properties/launchSettings.json"
```
