# rustyrussell/ccan architecture

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

- Interactive diagram: https://gitdiagram.com/rustyrussell/ccan
- Repository: https://github.com/rustyrussell/ccan

## Overview

##### High-Level Components
a. CCAN Modules – The heart of the project is the “ccan” directory. Each subdirectory under “ccan” is an independent C module (for example, a_star, alignof, daemonize, io, json, tal, etc.). These modules are designed to be self-contained libraries with their own source, header, test, license, and information files.
c. Documentation & Web Content – Documentation is available in “doc” and “web” directories. “doc” contains manuals and formatted documentation while “web” houses the assets for the CCAN website (CSS, HTML, PHP scripts), which offer static content and search capabilities.
d. Licensing and Other Metadata – The “licenses” folder contains various open-source licenses (Apache, BSD, GPL, etc.), and there are also supporting configuration files (like .travis.yml, Makefiles, appveyor.yml) which highlight how CI and build processes are arranged.
e. Junkcode – A “junkcode” folder exists that gathers miscellaneous or experimental code from various contributors. This can be represented as an auxiliary component showcasing sample implementations or legacy code that is not part of the core libraries.

- Central “CCAN Modules” block enclosing many independent modules. Use a container or a logical grouping to indicate that each module is self-contained and follows a uniform structure (source, header, tests).
- That continuous integration (CI) files (.travis.yml, appveyor.yml, etc.) interact with both the modules and the tools for automated building, testing, and linting.
- “Documentation & Web” block to the “CCAN Modules” and “Tools” blocks to show that user documentation and online resources help consumers understand how to integrate and use the modules.

##### Architectural Patterns and Design Principles
- Modularity: Each CCAN module is independent and self-contained, which supports plug-and-play integration in third-party projects.
- Separation of concerns: The core library modules are separate from the tooling (build utilities, testers, code analysis) and from the documentation; this clear separation helps in managing and evolving the repository.
- Extensibility: The recommended approach is to add one module per subdirectory within “ccan” (as noted in the README), which encourages a tree-like expansion of functionalities.
- Uniform structure and testing: Nearly every module comes with its own “test” subdirectory, ensuring that each is verifiable and conforms to similar API standards.

## Diagram (Mermaid)

```mermaid
flowchart TD
    %% Documentation & Web
    subgraph "Documentation & Web"
        DOCBLOCK["Documentation & Web"]:::doc
        DOC1["doc (manuals)"]:::doc
        WEB1["web (assets)"]:::doc
        DOCBLOCK --> DOC1
        DOCBLOCK --> WEB1
    end

    %% Helper Tools
    subgraph "Helper Tools"
        TOOLS["Helper Tools"]:::tools
        CL["ccanlint"]:::tools
        TREE["create-ccan-tree"]:::tools
        TOOLS --> CL
        TOOLS --> TREE
    end

    %% CCAN Modules
    subgraph "CCAN Modules"
        CCAN["CCAN Modules"]:::core
        ASTAR["a_star"]:::sub
        IO["io"]:::sub
        TAL["tal"]:::sub
        CCAN --> ASTAR
        CCAN --> IO
        CCAN --> TAL
    end

    %% Licensing & CI
    subgraph "Licensing & CI"
        LIC["Licensing & CI"]:::lic
        TRAVIS[".travis.yml"]:::lic
        APPVEYOR["appveyor.yml"]:::lic
        MAKEFILE["Makefile"]:::lic
        MAKEFILE_WEB["Makefile-web"]:::lic
        LIC --> TRAVIS
        LIC --> APPVEYOR
        LIC --> MAKEFILE
        LIC --> MAKEFILE_WEB
    end

    %% Junkcode
    subgraph "Junkcode"
        JUNK["Junkcode"]:::junk
    end

    %% Interactions
    DOCBLOCK -->|"references"| TOOLS
    DOCBLOCK -->|"references"| CCAN
    TOOLS -->|"updates"| CCAN
    LIC -->|"triggers"| TOOLS
    LIC -->|"triggers"| CCAN

    %% Styles
    classDef core fill:#ADD8E6,stroke:#000,stroke-width:2px;
    classDef tools fill:#90EE90,stroke:#000,stroke-width:2px;
    classDef doc fill:#DDA0DD,stroke:#000,stroke-width:2px;
    classDef lic fill:#FFD700,stroke:#000,stroke-width:2px;
    classDef junk fill:#F08080,stroke:#000,stroke-width:2px;
    classDef sub fill:#E0FFFF,stroke:#000,stroke-width:2px;

    %% Click Events
    click CCAN "https://github.com/rustyrussell/ccan/tree/master/ccan"
    click ASTAR "https://github.com/rustyrussell/ccan/tree/master/ccan/a_star"
    click IO "https://github.com/rustyrussell/ccan/tree/master/ccan/io"
    click TAL "https://github.com/rustyrussell/ccan/tree/master/ccan/tal"
    click TOOLS "https://github.com/rustyrussell/ccan/tree/master/tools"
    click CL "https://github.com/rustyrussell/ccan/tree/master/tools/ccanlint"
    click TREE "https://github.com/rustyrussell/ccan/tree/master/tools/create-ccan-tree"
    click DOC1 "https://github.com/rustyrussell/ccan/tree/master/doc"
    click WEB1 "https://github.com/rustyrussell/ccan/tree/master/web"
    click LIC "https://github.com/rustyrussell/ccan/tree/master/licenses"
    click TRAVIS "https://github.com/rustyrussell/ccan/blob/master/.travis.yml"
    click APPVEYOR "https://github.com/rustyrussell/ccan/blob/master/appveyor.yml"
    click MAKEFILE "https://github.com/rustyrussell/ccan/tree/master/Makefile"
    click MAKEFILE_WEB "https://github.com/rustyrussell/ccan/tree/master/Makefile-web"
    click JUNK "https://github.com/rustyrussell/ccan/tree/master/junkcode"
```
