# piwimau/scunit architecture

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

- Interactive diagram: https://gitdiagram.com/piwimau/scunit
- Repository: https://github.com/piwimau/scunit

## Overview

##### Project type and purpose
- SCUnit is an open-source, pure C23 unit‐testing framework (an XUnit‐style library) that you build and link into your own test executables.

##### File structure
- Top level:
- /SCUnit/… : public headers defining the API (scunit.h, suite.h, assert.h, etc.)
- src/…           : implementation modules (scunit.c, context.c, suite.c, print.c, random.c, timer.c)
- resources/      : SCUnit logo
- Makefile        : build targets to produce static/shared libraries in bin/
- Documentation: README.md, CHANGELOG.md, CONTRIBUTING.md, LICENSE
- Patterns:
- Modular design: each concern in its own .c / .h pair (context, suite registration, printing, RNG, timing)
- API layer (headers) → Core engine (scunit.c) → utility modules
- Build system drives compilation, linking into libscunit(.so/.a)

##### README for additional insights
- Dependencies: C standard library, compiler attributes (constructor/destructor), POSIX clock_gettime(), getopt_long()
- Build outputs: bin/{debug,release}/{static,shared}/libscunit(.so|.a)
- Usage model: include <SCUnit/scunit.h>, write SCUNIT_SUITE / SCUNIT_TEST macros, link library.

##### Detail
- How the Makefile target names map to bin/<type>/<libname>

- Accurately reflects SCUnit’s layered, modular architecture
- Highlights its extension and integration points
- Clearly shows data/control flow from test executable through the API into core and utility modules
- And makes explicit the build process and external dependencies

## Diagram (Mermaid)

```mermaid
flowchart TD
    classDef api fill:#cce5ff,stroke:#004085
    classDef core fill:#d4edda,stroke:#155724
    classDef util fill:#fff3cd,stroke:#856404
    classDef infra fill:#e2e3e5,stroke:#6c757d
    classDef test fill:#d1ecf1,stroke:#0c5460

    %% Test Executable
    TestExe["Test Executable"]:::test

    %% Public API Layer
    subgraph "Public API Layer"
        scunit_h["scunit.h"]:::api
        assert_h["assert.h"]:::api
        suite_h["suite.h"]:::api
        context_h["context.h"]:::api
        error_h["error.h"]:::api
        print_h["print.h"]:::api
        random_h["random.h"]:::api
        timer_h["timer.h"]:::api
        memory_h["memory.h"]:::api
    end

    %% Core Engine
    subgraph "Core Engine"
        scunit_c["scunit.c"]:::core
        context_c["context.c"]:::core
        suite_c["suite.c"]:::core
    end

    %% Utility Modules
    subgraph "Utility Modules"
        print_c["print.c"]:::util
        random_c["random.c"]:::util
        timer_c["timer.c"]:::util
        memory_override["memory overrides"]:::util
    end

    %% Build System & Resources
    subgraph "Build System & Resources"
        Makefile["Makefile"]:::infra
        resources["resources/"]:::infra
        lib["libscunit(.so/.a)"]:::infra
    end

    %% External Dependencies
    subgraph "External Dependencies"
        compiler["C23 Compiler (GCC/Clang)"]:::infra
        posix["POSIX (clock_gettime)"]:::infra
        getopt["getopt_long()"]:::infra
    end

    %% Relationships
    TestExe -->|"#include"| scunit_h
    TestExe -->|"link"| lib

    scunit_h -->|"function call"| scunit_c
    assert_h -->|"function call"| scunit_c
    suite_h -->|"function call"| scunit_c
    context_h -->|"function call"| scunit_c
    error_h -->|"function call"| scunit_c
    print_h -->|"function call"| scunit_c
    random_h -->|"function call"| scunit_c
    timer_h -->|"function call"| scunit_c
    memory_h -->|"function call"| scunit_c

    scunit_c -->|"context management"| context_c
    scunit_c -->|"test dispatch"| suite_c
    scunit_c -->|"formatted output"| print_c
    scunit_c -->|"timing API"| timer_c
    scunit_c -->|"PRNG"| random_c
    scunit_c -->|"alloc overrides"| memory_override

    Makefile -->|"compile"| scunit_c
    Makefile -->|"compile"| context_c
    Makefile -->|"compile"| suite_c
    Makefile -->|"compile"| print_c
    Makefile -->|"compile"| random_c
    Makefile -->|"compile"| timer_c
    Makefile -->|"link"| lib
    resources --> lib

    compiler -->|"compiles"| scunit_c
    posix -->|"provides"| timer_c
    getopt -->|"provides"| scunit_c

    TestExe -->|"uses API"| scunit_h
    TestExe -->|"runs against"| lib

    %% Click Events
    click scunit_h "https://github.com/piwimau/scunit/blob/main/include/SCUnit/scunit.h"
    click assert_h "https://github.com/piwimau/scunit/blob/main/include/SCUnit/assert.h"
    click suite_h "https://github.com/piwimau/scunit/blob/main/include/SCUnit/suite.h"
    click context_h "https://github.com/piwimau/scunit/blob/main/include/SCUnit/context.h"
    click error_h "https://github.com/piwimau/scunit/blob/main/include/SCUnit/error.h"
    click print_h "https://github.com/piwimau/scunit/blob/main/include/SCUnit/print.h"
    click random_h "https://github.com/piwimau/scunit/blob/main/include/SCUnit/random.h"
    click timer_h "https://github.com/piwimau/scunit/blob/main/include/SCUnit/timer.h"
    click memory_h "https://github.com/piwimau/scunit/blob/main/include/SCUnit/memory.h"
    click scunit_c "https://github.com/piwimau/scunit/blob/main/src/scunit.c"
    click context_c "https://github.com/piwimau/scunit/blob/main/src/context.c"
    click suite_c "https://github.com/piwimau/scunit/blob/main/src/suite.c"
    click print_c "https://github.com/piwimau/scunit/blob/main/src/print.c"
    click random_c "https://github.com/piwimau/scunit/blob/main/src/random.c"
    click timer_c "https://github.com/piwimau/scunit/blob/main/src/timer.c"
    click Makefile "https://github.com/piwimau/scunit/tree/main/Makefile"
    click resources "https://github.com/piwimau/scunit/tree/main/resources/"
    
    %% Styles
    class TestExe test
    class scunit_h,assert_h,suite_h,context_h,error_h,print_h,random_h,timer_h,memory_h api
    class scunit_c,context_c,suite_c core
    class print_c,random_c,timer_c,memory_override util
    class Makefile,resources,lib,compiler,posix,getopt infra
```
