# crazyokd/lol architecture

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

- Interactive diagram: https://gitdiagram.com/crazyokd/lol
- Repository: https://github.com/crazyokd/lol

## Overview

##### Project type and purpose
- From the README and file tree, this is a small C‐based logging library (“LOL”) plus example and test executables. It exposes a clean C API (lol_init*, lol_xxx, lol_add_domain, etc.) for emitting log messages at various severity levels, routing them to one or more sinks (console, file). Build is driven by a Makefile or Meson.

##### File structure
- Top level:
- lol.c, lol.h        ← core library implementation & header
- example.c           ← example client that links against the library
- test.c, test2.c     ← test clients
- format.sh           ← wrapper to invoke Meson formatting targets
- Makefile, meson.build ← two build‐system entry points
- README.md           ← project description & usage
- No separate src/ or include/ directories—everything is at project root.
- Build outputs (not shown) will be binaries (lol-example, test, etc.) and installable library.

##### README for additional insights
- Usage shows two init styles (lol_init vs. lol_init2), domain support, three API families (xxx, xxx2, xxx3) optimized in steps, and a final lol_fini.
- TODO calls out log‐file support (done) and write‐call optimization.
- There is no external service dependency apart from the C standard library (libc_write).

a. Main components:
- Clients: example.c, test.c/test2.c
- Logging Library: lol.c/h
– Initialization & teardown
– Domain manager
– Severity filter
– Sink manager (console sink, file sink)
- Build System: Makefile & Meson scripts
- Outputs: stdout/stderr console, log file on disk
- External dependency: OS filesystems & libc write()
b. Relationships and interactions:
1. Client code calls logging API →
2. Library routes message through domain & level filters →
3. Sink manager fans out to console and/or file sink →
4. Sink invokes libc write() → OS writes to terminal or log file
5. Build system compiles client + library into executables
c. Architectural patterns & design principles:
- Modular layering: API surface layer → core engine → sink implementations
- Domain-based filtering: pluggable domains with independent severity thresholds
- Pluggable sinks: can be extended with new output backends
- Separation of build from source: support for both Makefile and Meson
d. Key technologies & libraries:
- Pure C99 code, no external dependencies beyond libc
- Meson (meson.build) and Make (Makefile) for building, muon-fmt for formatting

##### Detail without over‐splitting
- Data/control flow: initialization, logging call path, and teardown.
- Build step distinctly to show how the library and clients get assembled.

## Diagram (Mermaid)

```mermaid
flowchart TB
    %% Clients
    subgraph "Client Applications"
        direction TB
        ExampleApp["Example Application"]:::clients
        TestApp1["Test Application 1"]:::clients
        TestApp2["Test Application 2"]:::clients
    end

    %% Library Internals
    subgraph "Logging Library Internals"
        direction TB
        API["API Surface"]:::library
        CoreImpl["Core Implementation"]:::library
        DomainFilter["Domain & Level Filter"]:::library
        SinkManager["Sink Manager"]:::library
    end

    %% Sinks
    subgraph "Sink Implementations"
        direction TB
        ConsoleSink["Console Sink"]:::library
        FileSink["File Sink"]:::library
    end

    %% External
    subgraph "External OS"
        direction TB
        LibC["libc write()"]:::external
        OS["OS Filesystem / Terminal"]:::external
    end

    %% Build System
    subgraph "Build System"
        direction TB
        MakefileNode["Makefile"]:::build
        MesonNode["meson.build"]:::build
        FormatScript["format.sh"]:::build
        Compilation["Compilation"]:::build
        Binaries["Binaries & Library"]:::build
        README["README.md"]:::build
    end

    %% Client to Library
    ExampleApp -->|"calls API"| API
    TestApp1 -->|"calls API"| API
    TestApp2 -->|"calls API"| API

    %% Library flow
    API --> CoreImpl
    CoreImpl --> DomainFilter
    DomainFilter --> SinkManager
    SinkManager --> ConsoleSink
    SinkManager --> FileSink

    %% Sink to OS
    ConsoleSink --> LibC
    FileSink --> LibC
    LibC --> OS

    %% Build flow
    MakefileNode --> Compilation
    MesonNode --> Compilation
    FormatScript --> Compilation
    Compilation --> Binaries
    Binaries --> ExampleApp
    Binaries --> TestApp1
    Binaries --> TestApp2

    %% Documentation
    README --> Compilation

    %% Click Events
    click ExampleApp "https://github.com/crazyokd/lol/blob/main/example.c"
    click TestApp1 "https://github.com/crazyokd/lol/blob/main/test.c"
    click TestApp2 "https://github.com/crazyokd/lol/blob/main/test2.c"
    click API "https://github.com/crazyokd/lol/blob/main/lol.h"
    click CoreImpl "https://github.com/crazyokd/lol/blob/main/lol.c"
    click MakefileNode "https://github.com/crazyokd/lol/tree/main/Makefile"
    click MesonNode "https://github.com/crazyokd/lol/blob/main/meson.build"
    click FormatScript "https://github.com/crazyokd/lol/blob/main/format.sh"
    click README "https://github.com/crazyokd/lol/blob/main/README.md"

    %% Styles
    classDef clients fill:#E8F5E9,stroke:#2E7D32,color:#2E7D32;
    classDef library fill:#E0F7FA,stroke:#0277BD,color:#01579B;
    classDef build fill:#FFF3E0,stroke:#EF6C00,color:#E65100;
    classDef external fill:#ECEFF1,stroke:#546E7A,color:#37474F;
```
