# 0x1ceking/mywebstorewithmodsecurity architecture

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

- Interactive diagram: https://gitdiagram.com/0x1ceking/mywebstorewithmodsecurity
- Repository: https://github.com/0x1ceking/mywebstorewithmodsecurity

## Overview

##### Main Components
- Frontend Web Client: This is represented by the static web pages and views (HTML, CSS, JS) housed under the src/main/webapp directory. There are separate views for admin and user interfaces.
- Java Spring Boot Backend: The primary application logic is implemented here. Look at packages like com/web/controller, com/web/service, com/web/repository, and the main application entry point (WebstoreApplication.java). This component contains the business logic for user authentication, product management, payment processing (with MoMo integration), and more.
- MySQL Database: Acts as the persistent storage for entities such as User, Product, Invoice, and others. The pom.xml indicates the use of frameworks that handle persistence (JPA/Hibernate).
- Nginx Proxy with ModSecurity: Located in the “NginxProxy_ModSecurityWaf” directory. This container is configured to use ModSecurity firewall rules (OWASP CRS, modsecurity.conf and related files) and serves as the first line of defense against malicious traffic.
- Docker & Docker Compose Environment: The Dockerfile at the project root and the docker-compose.yml file show the system is containerized, allowing each major component (Spring Boot app, MySQL, PhpMyAdmin, and Nginx ModSecurity proxy) to run in separate containers.

##### Interactions and Relationships
- The Frontend Web Client sends HTTP requests (both for page views and API calls) to the Java Spring Boot application.
- The Spring Boot backend handles these requests through various controllers. It then processes business logic, accesses the MySQL database (via JPA repositories), and communicates results back to the client.
- For administrative tasks or user activities (e.g., login, checkout, etc.), backend services (especially security and payment services) are invoked.
- Any external payment interactions (as indicated by the MoMo services and related models/processors) connect the backend with external payment gateways.
- The Nginx container sits at the network edge, acting as a reverse proxy. It checks incoming traffic with ModSecurity rules before passing requests to the backend application. This ensures that malicious requests are filtered out.
- Docker Compose orchestrates the overall deployment, defining network connections and service dependencies (so the Nginx container routes to the Spring Boot service, which in turn connects to the MySQL container).

##### Important Architectural Patterns and Design Principles
- Modular Separation: The project clearly separates concerns into frontend (presentation), backend (business logic), database (data persistence), and security components.
- Containerization: Emphasis on Docker and Docker Compose enables scalability, simplified deployment, and isolation between components.
- Security Integration: The addition of ModSecurity via an Nginx proxy demonstrates an external layered approach for web security.
- MVC Pattern: The Spring Boot architecture uses controllers, models, and views reflecting an MVC style in both the admin and user modules.

##### Relevant Technologies, Frameworks, and Libraries
- Java Spring Boot for server-side logic.
- Docker and Docker Compose for containerization.
- MySQL as the relational database, with PhpMyAdmin for administration.
- Nginx with ModSecurity for web application firewall capabilities.
- Maven for dependency management and build processes.
- Additional libraries for mail sending, cloud configurations, and payment processing (e.g., integration with MoMo).

## Diagram (Mermaid)

```mermaid
flowchart TB
    %% External Client and Payment Gateway
    Client["Client (Web Browser)"]:::client
    Payment["Payment Gateway"]:::external

    %% Docker Compose Environment boundary
    subgraph "Docker Compose Environment"
        direction TB
        DF["Dockerfile"]:::orchestration
        DC["Docker Compose"]:::orchestration

        Proxy["Nginx Proxy with ModSecurity"]:::proxy

        %% Java Spring Boot Application subgraph
        subgraph "Java Spring Boot Application"
            direction TB
            FE["Frontend Web Client"]:::frontend
            BE["Backend Service"]:::backend
        end

        DB["MySQL Database"]:::database
        PM["PhpMyAdmin"]:::admin
    end

    %% Flow Connections
    Client -->|"HTTPRequest"| Proxy
    Proxy -->|"RouteRequest"| BE
    BE -->|"DBQuery"| DB
    BE -->|"PaymentProcessing"| Payment
    PM ---|"DBAdmin"| DB

    %% Click Events
    click FE "https://github.com/0x1ceking/mywebstorewithmodsecurity/tree/main/src/main/webapp"
    click BE "https://github.com/0x1ceking/mywebstorewithmodsecurity/tree/main/src/main/java/com/web"
    click DB "https://github.com/0x1ceking/mywebstorewithmodsecurity/blob/main/webstore.sql"
    click Proxy "https://github.com/0x1ceking/mywebstorewithmodsecurity/tree/main/NginxProxy_ModSecurityWaf"
    click DF "https://github.com/0x1ceking/mywebstorewithmodsecurity/tree/main/Dockerfile"
    click DC "https://github.com/0x1ceking/mywebstorewithmodsecurity/blob/main/docker-compose.yml"

    %% Styles
    classDef client fill:#cfe2f3,stroke:#333,stroke-width:2px;
    classDef external fill:#f9cb9c,stroke:#333,stroke-width:2px;
    classDef proxy fill:#fff2cc,stroke:#333,stroke-width:2px;
    classDef backend fill:#d9ead3,stroke:#333,stroke-width:2px;
    classDef frontend fill:#c9daf8,stroke:#333,stroke-width:2px;
    classDef database fill:#f4cccc,stroke:#333,stroke-width:2px,stroke-dasharray: 5 5;
    classDef admin fill:#ead1dc,stroke:#333,stroke-width:2px,stroke-dasharray: 5 5;
    classDef orchestration fill:#d0e0e3,stroke:#333,stroke-width:2px,stroke-dasharray: 3 3;
```
