# mario-deluna/php-glfw architecture

> Architecture diagram of the GitHub repository mario-deluna/php-glfw, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2025-05-20). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/mario-deluna/php-glfw
- Repository: https://github.com/mario-deluna/php-glfw

## Overview

##### Project type and purpose
- PHP-GLFW is a native PHP extension (written in C) that binds OpenGL, GLFW, Vector Graphics, Math, Buffer, Texture, and Geometry functionality into PHP.
- It also includes a “generator” tool (PHP CLI) that parses OpenGL/GLFW specs to produce much of the extension’s C code and API documentation.
- Supplementary components: example applications, automated tests, documentation site, and CI/CD pipelines.

##### File structure
- Top‐level directories:
- **src** (implicit in root C files: phpglfw.c, phpglfw_math.c, etc.) – extension implementation modules
- **generator/** – code generator for extension stubs & docs
- **docs/** – MkDocs documentation site (API, user guide, examples)
- **examples/** – sample PHP programs demonstrating the extension
- **tests/** & **generator/tests/** – PHPUnit and PHP test suites
- **.github/workflows/**, **.travis.yml**, **mkdocs.yml** – continuous integration, build & deploy scripts
- Configuration/build artifacts: composer.json, config.m4, config.w32, phpglfw_*.h/c, phpize, makefiles, installer scripts.

##### README for insights
- Architectural sections: describes Extension Features (OpenGL, GLFW, Vector API, Math, Buffers, Textures, Geometry).
- “How are the bindings achieved?” explains the use of generator to parse specs into C code.
- References to continuous build badges (CI pipelines build extension on various platforms).

## Diagram (Mermaid)

```mermaid
graph TB

  subgraph "Specification Input"
    GLXML["gl.xml"]:::external
    click GLXML "https://github.com/mario-deluna/php-glfw/blob/master/generator/data/gl.xml"
    GLREF["glrefs.json"]:::external
    click GLREF "https://github.com/mario-deluna/php-glfw/blob/master/generator/data/glrefs.json"
  end

  subgraph "Generator Tool (PHP CLI)" 
    direction TB
    ExtParser["ExtDocParser"]:::codegen
    click ExtParser "https://github.com/mario-deluna/php-glfw/blob/master/generator/src/ExtDocParser.php"
    GLSpecReader["GLSpecReader"]:::codegen
    click GLSpecReader "https://github.com/mario-deluna/php-glfw/blob/master/generator/src/GLSpecReader.php"
    GLFWParser["GLFWHeaderParser"]:::codegen
    click GLFWParser "https://github.com/mario-deluna/php-glfw/blob/master/generator/src/GLFWHeaderParser.php"
    Adjustments["PHPGlfwAdjustments"]:::codegen
    click Adjustments "https://github.com/mario-deluna/php-glfw/tree/master/generator/src/PHPGlfwAdjustments/"
    Templates["Templates"]:::codegen
    click Templates "https://github.com/mario-deluna/php-glfw/tree/master/generator/templates/"
    GenTests["Generator Tests"]:::build
    click GenTests "https://github.com/mario-deluna/php-glfw/tree/master/generator/tests/"
    ComposerGen["composer.json"]:::build
    click ComposerGen "https://github.com/mario-deluna/php-glfw/blob/master/generator/composer.json"
  end

  subgraph "Extension Build" 
    direction TB
    Entry["phpglfw.c/.h"]:::build
    click Entry "https://github.com/mario-deluna/php-glfw/blob/master/phpglfw.c"
    Arginfo["phpglfw_arginfo.h"]:::build
    click Arginfo "https://github.com/mario-deluna/php-glfw/blob/master/phpglfw_arginfo.h"
    Buffer["Buffer Module"]:::build
    click Buffer "https://github.com/mario-deluna/php-glfw/blob/master/phpglfw_buffer.c"
    Constants["Constants Module"]:::build
    click Constants "https://github.com/mario-deluna/php-glfw/blob/master/phpglfw_constants.c"
    Functions["Functions Module"]:::build
    click Functions "https://github.com/mario-deluna/php-glfw/blob/master/phpglfw_functions.c"
    Math["Math Module"]:::build
    click Math "https://github.com/mario-deluna/php-glfw/blob/master/phpglfw_math.c"
    Geometry["Geometry Module"]:::build
    click Geometry "https://github.com/mario-deluna/php-glfw/blob/master/phpglfw_objparser.c"
    Texture["Texture Module"]:::build
    click Texture "https://github.com/mario-deluna/php-glfw/blob/master/phpglfw_texture.c"
    VG["VG Module"]:::build
    click VG "https://github.com/mario-deluna/php-glfw/blob/master/phpglfw_vg.c"
    Configs["Build Configs & Scripts"]:::build
    Installer["Installer Scripts"]:::build
    click Installer "https://github.com/mario-deluna/php-glfw/blob/master/install/macos-installer.php"
    ComposerRoot["composer.json"]:::build
    click ComposerRoot "https://github.com/mario-deluna/php-glfw/blob/master/composer.json"
  end

  So["glfw.so"]:::runtime

  subgraph "Runtime Environment"
    direction TB
    PHPInterp["PHP Interpreter"]:::runtime
    ExternalLibs["OpenGL/GLFW Libs"]:::external
    Examples["Examples"]:::runtime
    click Examples "https://github.com/mario-deluna/php-glfw/tree/master/examples/"
    DocsExamples["Docs Examples"]:::docs
    click DocsExamples "https://github.com/mario-deluna/php-glfw/tree/master/docs/examples/"
    Stubs["PHP Stub Files"]:::build
    click Stubs "https://github.com/mario-deluna/php-glfw/blob/master/phpglfw.stub.php"
    StubsDir["Stubs Dir"]:::build
    click StubsDir "https://github.com/mario-deluna/php-glfw/blob/master/stubs/phpglfw.php"
  end

  subgraph "Documentation Site"
    direction TB
    MkConfig["mkdocs.yml"]:::docs
    click MkConfig "https://github.com/mario-deluna/php-glfw/blob/master/mkdocs.yml"
    MkOverrides["docs/overrides"]:::docs
    click MkOverrides "https://github.com/mario-deluna/php-glfw/tree/master/docs/overrides"
    DocsSrc["docs/"]:::docs
    click DocsSrc "https://github.com/mario-deluna/php-glfw/tree/master/docs/"
    APIDocs["API Docs"]:::docs
    click APIDocs "https://github.com/mario-deluna/php-glfw/tree/master/docs/API/"
  end

  subgraph "Tests & CI Pipelines"
    direction TB
    TestsExt["Post-build Tests"]:::build
    click TestsExt "https://github.com/mario-deluna/php-glfw/tree/master/tests/"
    CIConfig["CI/CD Workflows"]:::ci
    Github[".github/workflows"]:::ci
    click Github "https://github.com/mario-deluna/php-glfw/blob/master/.github/workflows/build.yml"
    Travis[".travis.yml"]:::ci
    click Travis "https://github.com/mario-deluna/php-glfw/blob/master/.travis.yml"
  end

  %% Relationships
  GLXML -->|reads| ExtParser
  GLREF -->|reads| ExtParser
  ExtParser --> Templates
  GLSpecReader --> Templates
  GLFWParser --> Templates
  Adjustments --> Templates
  Templates -->|generates C & docs & stubs| Entry
  Templates --> Buffer
  Templates --> Constants
  Templates --> Functions
  Templates --> Math
  Templates --> Geometry
  Templates --> Texture
  Templates --> VG
  Templates --> Arginfo

  Entry -->|compiled alongside| Buffer
  Entry --> Constants
  Entry --> Functions
  Entry --> Math
  Entry --> Geometry
  Entry --> Texture
  Entry --> VG
  Entry --> Arginfo
  Configs -->|build via phpize→configure→make| So
  Buffer --> So
  Constants --> So
  Functions --> So
  Math --> So
  Geometry --> So
  Texture --> So
  VG --> So

  So -->|"links runtime"| ExternalLibs
  So --> PHPInterp
  PHPInterp --> Examples
  PHPInterp --> DocsExamples
  PHPInterp --> TestsExt
  PHPInterp --> Stubs
  PHPInterp --> StubsDir

  DocsSrc --> MkConfig
  APIDocs --> MkConfig

  CIConfig --> GenTests
  CIConfig --> Templates
  CIConfig --> Configs
  CIConfig --> So
  CIConfig --> TestsExt
  CIConfig --> MkConfig

  %% Styles
  classDef build fill:#bbdefb,stroke:#0d47a1
  classDef runtime fill:#c8e6c9,stroke:#1b5e20
  classDef external fill:#e0e0e0,stroke:#424242
  classDef codegen fill:#fff9c4,stroke:#f57f17
  classDef docs fill:#ffe0b2,stroke:#e65100
  classDef ci fill:#f3e5f5,stroke:#6a1b9a
```
