# amritxyz/libgfx architecture

> Architecture diagram of the GitHub repository amritxyz/libgfx, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2026-10-01). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/amritxyz/libgfx
- Repository: https://github.com/amritxyz/libgfx

## Overview

Libgfx is a small C graphics library for creating an OpenGL-backed window, drawing basic shapes, presenting frames, and handling keyboard input. An application uses the public API to initialize a context, issue drawing and input calls, and terminate it. The implementation combines window/context setup, shader and geometry setup, drawing, and input handling in one source file; the separate renderer header exposes shader and mesh declarations, but its implementation is not shown. Relationships below are limited to the README, header declarations, and source excerpts/index references provided.

Main entry points: [`include/libgfx.h`](https://github.com/amritxyz/libgfx/blob/main/include/libgfx.h) (Libgfx API), [`src/libgfx.c`](https://github.com/amritxyz/libgfx/blob/main/src/libgfx.c) (Context Lifecycle), [`glad/src/gl.c`](https://github.com/amritxyz/libgfx/blob/main/glad/src/gl.c) (GLAD Loader), [`include/renderer.h`](https://github.com/amritxyz/libgfx/blob/main/include/renderer.h) (Renderer API)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_api["Public API"]
  node_libgfx_api["Libgfx API<br/>[libgfx.h]"]
  node_renderer_api["Renderer API<br/>[renderer.h]"]
end

subgraph group_runtime["Graphics Runtime"]
  node_context["Context Lifecycle<br/>[libgfx.c]"]
  node_input["Keyboard Input<br/>[libgfx.c]"]
end

subgraph group_render["Rendering Support"]
  node_shape_drawing["Shape Drawing<br/>[libgfx.c]"]
  node_shader_setup["Shader Setup<br/>[libgfx.c]"]
end

subgraph group_deps["Graphics Dependencies"]
  node_glad_loader["GLAD Loader<br/>[gl.c]"]
  node_glad_header["GLAD Declarations<br/>[gl.h]"]
  node_glfw["GLFW"]
  node_opengl["OpenGL"]
end

node_application(("Application"))

node_application -->|"uses"| node_libgfx_api
node_libgfx_api -->|"initializes"| node_context
node_libgfx_api -->|"draws shapes"| node_shape_drawing
node_libgfx_api -->|"queries input"| node_input
node_renderer_api -->|"includes"| node_libgfx_api
node_context -->|"creates window"| node_glfw
node_context -->|"loads functions"| node_glad_loader
node_context -->|"configures shaders"| node_shader_setup
node_shader_setup -->|"compiles shaders"| node_opengl
node_shape_drawing -->|"issues draw calls"| node_opengl
node_input -->|"polls keys"| node_glfw
node_glad_loader -.->|"implements"| node_glad_header

click node_libgfx_api "https://github.com/amritxyz/libgfx/blob/main/include/libgfx.h"
click node_renderer_api "https://github.com/amritxyz/libgfx/blob/main/include/renderer.h"
click node_context "https://github.com/amritxyz/libgfx/blob/main/src/libgfx.c"
click node_input "https://github.com/amritxyz/libgfx/blob/main/src/libgfx.c"
click node_shape_drawing "https://github.com/amritxyz/libgfx/blob/main/src/libgfx.c"
click node_shader_setup "https://github.com/amritxyz/libgfx/blob/main/src/libgfx.c"
click node_glad_loader "https://github.com/amritxyz/libgfx/blob/main/glad/src/gl.c"
click node_glad_header "https://github.com/amritxyz/libgfx/blob/main/glad/include/glad/gl.h"

classDef toneNeutral fill:#f8fafc,stroke:#334155,stroke-width:1.5px,color:#0f172a
classDef toneBlue fill:#dbeafe,stroke:#2563eb,stroke-width:1.5px,color:#172554
classDef toneAmber fill:#fef3c7,stroke:#d97706,stroke-width:1.5px,color:#78350f
classDef toneMint fill:#dcfce7,stroke:#16a34a,stroke-width:1.5px,color:#14532d
classDef toneRose fill:#ffe4e6,stroke:#e11d48,stroke-width:1.5px,color:#881337
classDef toneIndigo fill:#e0e7ff,stroke:#4f46e5,stroke-width:1.5px,color:#312e81
classDef toneTeal fill:#ccfbf1,stroke:#0f766e,stroke-width:1.5px,color:#134e4a
class node_libgfx_api,node_renderer_api toneBlue
class node_context,node_input toneAmber
class node_shape_drawing,node_shader_setup toneMint
class node_glad_loader,node_glad_header,node_glfw,node_opengl toneRose
class node_application toneIndigo
```

## Components

### Public API

- [Libgfx API](https://github.com/amritxyz/libgfx/blob/main/include/libgfx.h): `include/libgfx.h`
- [Renderer API](https://github.com/amritxyz/libgfx/blob/main/include/renderer.h): `include/renderer.h`

### Graphics Runtime

- [Context Lifecycle](https://github.com/amritxyz/libgfx/blob/main/src/libgfx.c): `src/libgfx.c`
- [Keyboard Input](https://github.com/amritxyz/libgfx/blob/main/src/libgfx.c): `src/libgfx.c`

### Rendering Support

- [Shape Drawing](https://github.com/amritxyz/libgfx/blob/main/src/libgfx.c): `src/libgfx.c`
- [Shader Setup](https://github.com/amritxyz/libgfx/blob/main/src/libgfx.c): `src/libgfx.c`

### Graphics Dependencies

- [GLAD Loader](https://github.com/amritxyz/libgfx/blob/main/glad/src/gl.c): `glad/src/gl.c`
- [GLAD Declarations](https://github.com/amritxyz/libgfx/blob/main/glad/include/glad/gl.h): `glad/include/glad/gl.h`
- **GLFW**
- **OpenGL**

### Other components

- **Application**

## Connections

- Application → Libgfx API: uses (evidence: `include/libgfx.h`)
- Libgfx API → Context Lifecycle: initializes (evidence: `src/libgfx.c`)
- Libgfx API → Shape Drawing: draws shapes (evidence: `src/libgfx.c`)
- Libgfx API → Keyboard Input: queries input (evidence: `src/libgfx.c`)
- Renderer API → Libgfx API: includes (evidence: `include/renderer.h`)
- Context Lifecycle → GLFW: creates window (evidence: `src/libgfx.c`)
- Context Lifecycle → GLAD Loader: loads functions (evidence: `src/libgfx.c`)
- Context Lifecycle → Shader Setup: configures shaders (evidence: `src/libgfx.c`)
- Shader Setup → OpenGL: compiles shaders (evidence: `src/libgfx.c`)
- Shape Drawing → OpenGL: issues draw calls (evidence: `src/libgfx.c`)
- Keyboard Input → GLFW: polls keys (evidence: `src/libgfx.c`)
- GLAD Loader → GLAD Declarations: implements
