# panino/bladecaptcha architecture

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

- Interactive diagram: https://gitdiagram.com/panino/bladecaptcha
- Repository: https://github.com/panino/bladecaptcha

## Overview

##### Project type and purpose
- BladeCAPTCHA is an open-source JavaScript/CSS/HTML library plus optional PHP backend that you embed in your web forms to generate and verify CAPTCHAs.
- The README points to examples in public/examples and PHP scripts under public/php, indicating both client-side and server-side components.

##### File structure
Top-level:
- config/ – stores the sample PHP configuration (config.sample.php).
- public/ – all static assets and PHP endpoints you deploy.
– css/ & js/ – styling and core JS logic (including web workers).
– examples/ – demo HTML pages showing integration patterns.
– php/ – server-side scripts (captcha-lib.php, captcha.php for challenge issuance, cors.php for cross-origin, procesar-formulario.php for form processing).
Others:
- package.json & package-lock.json – hint at using NPM for packaging or build tasks.
- README files in multiple languages – documentation.

##### README for additional insights
- The PHP library (captcha-lib.php) encapsulates challenge generation and validation.

## Diagram (Mermaid)

```mermaid
flowchart TD
    %% Client Layer
    subgraph "Client (Browser)" 
        direction TB
        BrowserUI["Browser UI\n(Demo Pages)"]:::client
        CSS["captcha.css"]:::client
        JS["captcha.js"]:::client
        WorkerPOW["pow-worker.js"]:::client
        WorkerBench["benchmark-worker.js"]:::client
    end

    %% Static Assets Server
    subgraph "Web Server (Static Assets)"
        direction TB
        CSS
        JS
    end

    %% Build Tools
    subgraph "Build Tooling"
        direction TB
        NPM["package.json\npackage-lock.json"]:::build
    end

    %% PHP Backend
    subgraph "PHP Backend"
        direction TB
        CORS["cors.php"]:::backend
        CaptchaAPI["captcha.php\n(Challenge API)"]:::backend
        VerifyAPI["procesar-formulario.php\n(Verification API)"]:::backend
        Lib["captcha-lib.php\n(Core Logic)"]:::backend
        Config["config.sample.php"]:::config
    end

    %% Connections
    BrowserUI -->|"loads"| CSS
    BrowserUI -->|"loads"| JS
    JS -->|"spawns"| WorkerPOW
    JS -->|"spawns"| WorkerBench
    JS -->|"GET /captcha.php"| CORS
    CORS -->|"forwards"| CaptchaAPI
    CaptchaAPI -->|"uses"| Lib
    CaptchaAPI -->|"reads"| Config
    JS -->|"POST /procesar-formulario.php"| CORS
    CORS -->|"forwards"| VerifyAPI
    VerifyAPI -->|"uses"| Lib
    VerifyAPI -->|"reads"| Config

    %% Click Events
    click BrowserUI "https://github.com/panino/bladecaptcha/blob/master/public/examples/dual-forms.html"
    click CSS "https://github.com/panino/bladecaptcha/blob/master/public/css/captcha.css"
    click JS "https://github.com/panino/bladecaptcha/blob/master/public/js/captcha.js"
    click WorkerPOW "https://github.com/panino/bladecaptcha/blob/master/public/js/workers/pow-worker.js"
    click WorkerBench "https://github.com/panino/bladecaptcha/blob/master/public/js/workers/benchmark-worker.js"
    click CaptchaAPI "https://github.com/panino/bladecaptcha/blob/master/public/php/captcha.php"
    click VerifyAPI "https://github.com/panino/bladecaptcha/blob/master/public/php/procesar-formulario.php"
    click CORS "https://github.com/panino/bladecaptcha/blob/master/public/php/cors.php"
    click Lib "https://github.com/panino/bladecaptcha/blob/master/public/php/captcha-lib.php"
    click Config "https://github.com/panino/bladecaptcha/blob/master/config/config.sample.php"
    click NPM "https://github.com/panino/bladecaptcha/blob/master/package.json"

    %% Styles
    classDef client fill:#cce5ff,stroke:#004085,color:#004085
    classDef backend fill:#fff3cd,stroke:#856404,color:#856404
    classDef build fill:#e2e3e5,stroke:#bcbec0,color:#6c757d
    classDef config fill:#d1ecf1,stroke:#0c5460,color:#0c5460
```
