# xquartz/xorg-server architecture

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

- Interactive diagram: https://gitdiagram.com/xquartz/xorg-server
- Repository: https://github.com/xquartz/xorg-server

## Overview

##### Main Components
- Core Server ("dix" folder): Represents the central dispatch and event-handling loop. This is where client requests are received, parsed, and routed.
- Extensions and Protocols: Directories such as Xext, Xi, composite, damageext, dbe, dri3, glx, randr, render, xfixes, miext, etc. Each module implements a specific extension or protocol. They act as pluggable components that extend the basic X functionalities.
- Hardware Abstraction (hw directory): Contains different device drivers and hardware support components for various platforms and graphical backends (for example, hw/xfree86, hw/kdrive, hw/xwayland, hw/xwin). These provide the bridge between the abstract server operations and the underlying system hardware.
- Supporting Libraries and Common Code: Components like “mi”, “os”, and “include” contain the architecture-independent code, operating system interface abstractions, and API definitions used throughout the server.
- Build and Configuration: Files such as meson.build, meson_options.txt, configuration scripts under "config" that coordinate the build process and manage various system quirks.

##### Relationships and Interactions
- Hardware Communication: The “Hardware Abstraction” modules (inside the hw directory) interact with driver code to “push” the final rendered output to the graphics devices. Indicate control flows between the core/extension subsystems and these hardware drivers.
- OS and Platform Specific Support: The “os” directory supplements the core with platform-dependent implementations such as input, logging, and memory management.

##### Design Patterns and Principles
- Modular Design: The project is clearly modular. Each extension or subsystem (like Xext, Xi, RandR, etc.) is a separate module, indicated by its folder.
- Plug-in Architecture: Many functionalities are implemented as loadable modules (e.g., hardware drivers, extensions) that can be added or updated independently.
- Layered Architecture: There is a separation between the protocol handling, internal core processing (in “dix”), extension implementations, and hardware interfacing (in “hw”).
- Event-Driven Processing: The central event loop in the core “dix” module gathers events from client sockets and OS inputs, then dispatches them, which is vital to the architectural approach.

##### Relevant Technologies and Tools
- Languages and Build System: The code is written in C; the project uses the Meson build system (meson.build and meson_options.txt) indicating the build process.
- Integration Points: There are integration points for D-Bus (dbus-core.c), maybe PCI and other OS-specific interfaces within the "hw" sections.

## Diagram (Mermaid)

```mermaid
flowchart TD
    %% Client Layer
    subgraph "Client Layer"
        client["Client Applications"]:::client
    end

    %% Core Server
    subgraph "Core Server"
        dix["DIX (Core Server)"]:::core
    end

    %% Extensions
    subgraph "Extensions"
        Xext["Xext"]:::extension
        Xi["Xi"]:::extension
        composite["Composite"]:::extension
        damageext["Damage Extension"]:::extension
        dbe["DBE"]:::extension
        dri3["DRI3"]:::extension
        glx["GLX"]:::extension
        randr["RandR"]:::extension
        record["Record"]:::extension
        render["Render"]:::extension
        xfixes["XFixes"]:::extension
        miext["MI Extensions"]:::extension
    end

    %% Supporting Libraries
    subgraph "Supporting Libraries"
        mi["MI"]:::library
        os["OS Abstractions"]:::library
        include["Common API Definitions"]:::library
    end

    %% Hardware Abstraction
    subgraph "Hardware Abstraction"
        hw["Hardware Abstraction"]:::hardware
    end

    %% Build and Configuration
    subgraph "Build and Configuration"
        mesonbuild["meson.build"]:::build
        mesonoptions["meson_options.txt"]:::build
        config["Configuration Scripts"]:::build
    end

    %% Connections
    client -->|"sends_X_protocol_requests"| dix

    dix -->|"dispatches"| Xext
    dix -->|"dispatches"| Xi
    dix -->|"dispatches"| composite
    dix -->|"dispatches"| damageext
    dix -->|"dispatches"| dbe
    dix -->|"dispatches"| dri3
    dix -->|"dispatches"| glx
    dix -->|"dispatches"| randr
    dix -->|"dispatches"| record
    dix -->|"dispatches"| render
    dix -->|"dispatches"| xfixes
    dix -->|"dispatches"| miext

    %% Extensions to Hardware Abstraction
    Xext -->|"outputs_to"| hw
    Xi -->|"outputs_to"| hw
    composite -->|"outputs_to"| hw
    damageext -->|"outputs_to"| hw
    dbe -->|"outputs_to"| hw
    dri3 -->|"outputs_to"| hw
    glx -->|"outputs_to"| hw
    randr -->|"outputs_to"| hw
    record -->|"outputs_to"| hw
    render -->|"outputs_to"| hw
    xfixes -->|"outputs_to"| hw
    miext -->|"outputs_to"| hw

    %% Supporting Libraries support Core
    os -- "supports" --> dix
    mi -- "supports" --> dix
    include -- "defines_API_for" --> dix

    %% Build and Configuration guides integration
    mesonbuild -. "build_config" .-> dix
    mesonoptions -. "build_config" .-> dix
    config -. "build_config" .-> dix

    %% Extension Interactions (examples)
    composite -->|"triggers_damage"| damageext
    randr -->|"affects_render"| render

    %% Click Events
    click dix "https://github.com/xquartz/xorg-server/tree/master/dix"
    click Xext "https://github.com/xquartz/xorg-server/tree/master/Xext"
    click Xi "https://github.com/xquartz/xorg-server/tree/master/Xi"
    click composite "https://github.com/xquartz/xorg-server/tree/master/composite"
    click damageext "https://github.com/xquartz/xorg-server/tree/master/damageext"
    click dbe "https://github.com/xquartz/xorg-server/tree/master/dbe"
    click dri3 "https://github.com/xquartz/xorg-server/tree/master/dri3"
    click glx "https://github.com/xquartz/xorg-server/tree/master/glx"
    click randr "https://github.com/xquartz/xorg-server/tree/master/randr"
    click record "https://github.com/xquartz/xorg-server/tree/master/record"
    click render "https://github.com/xquartz/xorg-server/tree/master/render"
    click xfixes "https://github.com/xquartz/xorg-server/tree/master/xfixes"
    click miext "https://github.com/xquartz/xorg-server/tree/master/miext"
    click hw "https://github.com/xquartz/xorg-server/tree/master/hw"
    click mi "https://github.com/xquartz/xorg-server/tree/master/mi"
    click os "https://github.com/xquartz/xorg-server/tree/master/os"
    click include "https://github.com/xquartz/xorg-server/tree/master/include"
    click mesonbuild "https://github.com/xquartz/xorg-server/blob/master/meson.build"
    click mesonoptions "https://github.com/xquartz/xorg-server/blob/master/meson_options.txt"
    click config "https://github.com/xquartz/xorg-server/tree/master/config"

    %% Styles
    classDef client fill:#FDEBD0,stroke:#D35400,stroke-width:2px
    classDef core fill:#AED6F1,stroke:#2471A3,stroke-width:2px
    classDef extension fill:#A9DFBF,stroke:#229954,stroke-width:2px
    classDef hardware fill:#F9E79F,stroke:#B7950B,stroke-width:2px
    classDef library fill:#F5CBA7,stroke:#BA4A00,stroke-width:2px
    classDef build fill:#D7BDE2,stroke:#8E44AD,stroke-width:2px
```
