# zemasterkrom/zmkr-cloudflare-turnstile-bundle architecture

> Architecture diagram of the GitHub repository zemasterkrom/zmkr-cloudflare-turnstile-bundle, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2025-01-08). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/zemasterkrom/zmkr-cloudflare-turnstile-bundle
- Repository: https://github.com/zemasterkrom/zmkr-cloudflare-turnstile-bundle

## Overview

##### Project Type and Purpose
This is a Symfony bundle (PHP library) that integrates Cloudflare Turnstile captcha service into Symfony applications. It's primarily a middleware/integration component that connects Symfony forms with Cloudflare's captcha service.

##### Main Components

a. Core Components:
- Form Integration Layer (CloudflareTurnstileType)
- Client Layer (CloudflareTurnstileClient)
- Validation Layer (CloudflareTurnstileCaptchaValidator)
- Configuration Layer (DependencyInjection)
- Frontend Integration (JavaScript Handler)
- Translation System

b. External Systems:
- Cloudflare Turnstile API
- Host Symfony Application
- Client Browser

##### Top Layer (Client Side)
- JavaScript widget handler
- Turnstile widget UI element

##### Middle Layer (Bundle Core)
- Form Integration Component
- Validation Component
- Client Component
- Configuration Management
- Error Management
- Properties Management

##### Bottom Layer (External Services)
- Cloudflare Turnstile API
- Host Symfony Application

##### Key Relationships

- Data flow from browser → form component → validator
- API calls from client component → Cloudflare API
- Configuration flow from DI container → components
- JavaScript widget initialization flow
- Validation response flow

##### Important Elements to Highlight

a. Integration Points:
- Form Type Integration
- Cloudflare API Communication
- JavaScript Widget Integration
- Symfony Form Component Integration

b. Configuration Flow:
- Environment Variables
- Bundle Configuration
- Service Container Integration

##### Additional Details

Notes or callouts for:
- Supported languages (show translation system)
- Configuration options
- Validation flow
- Error handling paths

##### The validation and error handling flow

- How the bundle integrates with their Symfony application
- The flow of captcha validation
- Configuration points and customization options
- The interaction between client-side and server-side components

Keep the abstraction level high enough to be understandable but detailed enough to show the bundle's key architectural decisions and integration points.

## Diagram (Mermaid)

```mermaid
graph TB
    subgraph Client["Client Layer"]
        Browser["Browser/Client"]
        Widget["Turnstile Widget"]:::widget
        JSHandler["JavaScript Widget Handler"]:::frontend
    end

    subgraph Bundle["Bundle Core"]
        direction TB
        FormType["Form Integration Layer"]:::core
        Validator["Validation Layer"]:::core
        Client["Client Layer"]:::core
        ErrorMgr["Error Manager"]:::core
        PropMgr["Properties Manager"]:::core
        
        subgraph Config["Configuration Layer"]
            direction TB
            DI["Dependency Injection"]:::config
            Config["Configuration"]:::config
        end
        
        subgraph Resources["Resource Layer"]
            direction TB
            Trans["Translation System"]:::resource
            Views["View Templates"]:::resource
        end
    end

    subgraph External["External Services"]
        CloudflareAPI["Cloudflare Turnstile API"]:::external
        SymfonyApp["Host Symfony Application"]:::external
    end

    %% Relationships
    Browser --> Widget
    Widget --> JSHandler
    JSHandler --> FormType
    FormType --> Validator
    Validator --> Client
    Client --> CloudflareAPI
    ErrorMgr --> FormType
    PropMgr --> FormType
    DI --> FormType
    DI --> Client
    DI --> Validator
    Config --> DI
    Trans --> FormType
    Views --> Widget
    SymfonyApp --> Bundle

    %% Click Events
    click FormType "https://github.com/Zemasterkrom/zmkr-cloudflare-turnstile-bundle/blob/main/src/Form/Type/CloudflareTurnstileType.php"
    click Client "https://github.com/Zemasterkrom/zmkr-cloudflare-turnstile-bundle/blob/main/src/Client/CloudflareTurnstileClient.php"
    click Validator "https://github.com/Zemasterkrom/zmkr-cloudflare-turnstile-bundle/blob/main/src/Validator/CloudflareTurnstileCaptchaValidator.php"
    click Config "https://github.com/Zemasterkrom/zmkr-cloudflare-turnstile-bundle/blob/main/src/DependencyInjection/Configuration.php"
    click DI "https://github.com/Zemasterkrom/zmkr-cloudflare-turnstile-bundle/blob/main/src/DependencyInjection/ZmkrCloudflareTurnstileExtension.php"
    click JSHandler "https://github.com/Zemasterkrom/zmkr-cloudflare-turnstile-bundle/blob/main/src/Resources/public/js/zmkr_cloudflare_turnstile_widget_handler.v1.0.js"
    click Views "https://github.com/Zemasterkrom/zmkr-cloudflare-turnstile-bundle/blob/main/src/Resources/views/zmkr_cloudflare_turnstile_widget.html.twig"
    click Trans "https://github.com/Zemasterkrom/zmkr-cloudflare-turnstile-bundle/tree/main/src/Resources/translations"
    click ErrorMgr "https://github.com/Zemasterkrom/zmkr-cloudflare-turnstile-bundle/blob/main/src/Manager/CloudflareTurnstileErrorManager.php"
    click PropMgr "https://github.com/Zemasterkrom/zmkr-cloudflare-turnstile-bundle/blob/main/src/Manager/CloudflareTurnstilePropertiesManager.php"
    click Bundle "https://github.com/Zemasterkrom/zmkr-cloudflare-turnstile-bundle/blob/main/src/ZmkrCloudflareTurnstileBundle.php"

    %% Styles
    classDef core fill:#2196F3,stroke:#1565C0,color:white
    classDef config fill:#757575,stroke:#424242,color:white
    classDef resource fill:#9C27B0,stroke:#6A1B9A,color:white
    classDef external fill:#4CAF50,stroke:#2E7D32,color:white
    classDef frontend fill:#FF9800,stroke:#EF6C00,color:white
    classDef widget fill:#FFC107,stroke:#FFA000,color:black
```
