# mihaibojin/waf-downloader architecture

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

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

## Overview

##### Main Components
- Application Core (Cloudflare WAF Downloader Library):
- Core functionality within the “src/waf_logs” directory.
- This module handles communication with Cloudflare’s APIs, applies database schemas (notably from “src/waf_logs/resources/db”), processes the log data, and manages configuration such as schema application.
- CLI Interface:
- Shown as a separate component “src/waf_logs_cli” that utilizes the core library to provide a user-friendly command-line interface.
- Docker Container and Deployment Artifacts:
- Dockerfile(s) and the development environment definitions (in the .devcontainer directory) to represent the containerized builds.
- Incorporate Helm charts (found in the “charts/waf-downloader” directory) as an additional deployment mechanism in Kubernetes.
- Scripts and Task Automation:
- A block for the “scripts” and “Taskfile.yml” components, which contain helper scripts for building, testing, and deploying the project using both Docker and GitHub Actions.
- Database Interaction (Optional):
- External Services:
- Cloudflare: Represent Cloudflare’s API as an external system from which logs are downloaded.
- (Optionally) External CI/CD services indicated by GitHub Actions and pre-commit hooks.

##### Relationships and Data Flow
- If a DB connection is configured, the Application Core writes or updates log data in the Database. Otherwise, logs are sent to stdout.
- That build/deploy automation scripts trigger tasks that assemble these components, such as building the Docker image (“scripts/build-docker-image.bash”) and managing versioning.

##### Architectural Patterns and Design Principles
- Separation of Concerns:
- The project clearly separates the core functionality (downloading and processing logs) from the CLI interface and deployment configurations (Docker and Helm templates).
- Containerization:
- Usage of Docker for both development and production, with specific folders (.devcontainer, Dockerfile) to support a consistent environment.
- Automation and CI/CD:
- Optional Persistence:
- The database integration is optional, so clearly indicate an alternative path in the data flow (printing to stdout when no DB is configured).

##### Relevant Technologies and Frameworks
- Python and its dependencies are managed via “pyproject.toml” and “requirements*.txt” files.
- Container orchestration using Docker (and Helm for Kubernetes deployments).
- Continuous Integration with GitHub Actions and pre-commit hooks for code quality.

## Diagram (Mermaid)

```mermaid
flowchart TD
    %% Application Layer
    subgraph "Application Layer"
        CLI["CLI Interface"]:::cli
        Core["Cloudflare WAF Downloader Library"]:::core
        API["Cloudflare API"]:::external
        DB["Database (Optional)"]:::db
        Stdout["Standard Output"]:::external
    end

    %% Containerization & Deployment Layer
    subgraph "Containerization & Deployment"
        subgraph "Containerization Artifacts"
            DF["Dockerfile (root)"]:::deploy
            Dev["Dev Container Config"]:::deploy
        end
        Docker["Docker Container & Dev Environment"]:::deploy
        Helm["Kubernetes/Helm Deployment"]:::deploy
    end

    %% Automation & CI/CD Layer
    subgraph "Automation & CI/CD"
        Scripts["Scripts & Task Automation"]:::automation
        Taskfile["Taskfile.yml"]:::automation
        CICD["CI/CD Workflow"]:::automation
        PreCommit["Pre-commit Hooks"]:::automation
    end

    %% Connections in Application Layer
    CLI -->|"uses"| Core
    Core -->|"download_logs"| API
    Core -->|"persist_logs"| DB
    Core -->|"or_print"| Stdout

    %% Connections from Deployment Layer to Application Layer
    Docker -->|"runs"| CLI
    Docker -->|"runs"| Core
    Helm -->|"deploys"| Docker

    %% Connections in Automation & CI/CD Layer
    CICD -->|"triggers"| Scripts
    PreCommit -->|"enforces"| Scripts
    Scripts -->|"builds"| Docker
    Scripts -->|"includes"| Taskfile

    %% Class definitions for styling with colors
    classDef core fill:#F7C8E0,stroke:#333,stroke-width:2px;
    classDef cli fill:#BDE0FE,stroke:#333,stroke-width:2px;
    classDef deploy fill:#C9E4C5,stroke:#333,stroke-width:2px;
    classDef automation fill:#FFEDB2,stroke:#333,stroke-width:2px;
    classDef external fill:#E1E1E1,stroke:#333,stroke-width:2px;
    classDef db fill:#FDCFDF,stroke:#333,stroke-width:2px;

    %% Click Events
    click Core "https://github.com/mihaibojin/waf-downloader/tree/main/src/waf_logs"
    click CLI "https://github.com/mihaibojin/waf-downloader/tree/main/src/waf_logs_cli"
    click DF "https://github.com/mihaibojin/waf-downloader/tree/main/Dockerfile"
    click Dev "https://github.com/mihaibojin/waf-downloader/blob/main/.devcontainer"
    click Helm "https://github.com/mihaibojin/waf-downloader/tree/main/charts/waf-downloader"
    click Scripts "https://github.com/mihaibojin/waf-downloader/tree/main/scripts"
    click Taskfile "https://github.com/mihaibojin/waf-downloader/blob/main/Taskfile.yml"
    click CICD "https://github.com/mihaibojin/waf-downloader/blob/main/.github/workflows/cicd.yml"
    click PreCommit "https://github.com/mihaibojin/waf-downloader/blob/main/.pre-commit-config.yaml"
```
