# hnthap/rrcal architecture

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

- Interactive diagram: https://gitdiagram.com/hnthap/rrcal
- Repository: https://github.com/hnthap/rrcal

## Overview

##### Project type and purpose
- This is a standalone command-line tool (“rrcal”) written in C99 that computes all rational roots of an integer-coefficient polynomial using the Rational Root Theorem.
- It is a small, monolithic, open-source C project with no dynamic memory, organized as separate compilation units and headers.

##### File structure
- Top-level:
- Makefile & build artifacts → build process
- README.md → documentation
- / → public headers that define interfaces (argparse, polynomial representation, math utilities, macros, types)
- source/ → implementation of each module (argparse.c, polynomial.c, rational.c, moremath.c, checkvalue.c, roottest.c, main.c)

##### README
- Confirms the tool’s purpose and usage: “rrcal -6 -1 1”
- References static memory, C99, and locations of settings in include/macros.h
- No external services or databases—pure CPU computation and CLI I/O

a. Main components
1. User / CLI Interface
2. Argument Parser (argparse)
3. Polynomial Data Model (polynomial, types)
4. Math Utilities (moremath, macros)
5. Rational Root Hunter (rational, roottest, checkvalue)
6. Output Renderer (to stdout)
7. Build System (Makefile → gcc → rrcal executable)
b. Relationships & interactions
- User invokes rrcal executable → CLI Interface
- CLI → Argument Parser → produces array of coefficients
- Coefficients → Polynomial Data Model → normalized representation
- Polynomial + Math Utilities → generate candidate p/q pairs
- For each candidate → Root Tester + Checkvalue → filter valid roots
- Valid roots → Output Renderer → stdout
- Build System orchestrates compilation of each module and links into one binary
c. Architectural patterns / design principles
- Modular monolith: separate header + source per logical unit
- Single responsibility: each module (argparse, polynomial, rational, roottest, moremath, checkvalue) has a well-defined function
- Static memory / predictable footprint: no heap, everything stack or static
- Interface layering: include/ defines public APIs, source/ contains private implementations
d. Relevant technologies
- Language: C99
- Build: GNU Make + gcc
- Static analysis / documentation: Doxygen-style comments in headers

##### Detailed capture of architectural elements
- That macros.h and types.h are foundational and imported by nearly every module
- Makefile invoking gcc on all source files and producing build/bin/rrcal

## Diagram (Mermaid)

```mermaid
flowchart TD
    %% Public API Layer
    subgraph "Public API Layer"
        argparse_h["argparse.h"]:::api
        polynomial_h["polynomial.h"]:::api
        types_h["types.h"]:::api
        moremath_h["moremath.h"]:::api
        macros_h["macros.h"]:::api
        rational_h["rational.h"]:::api
        roottest_h["roottest.h"]:::api
        checkvalue_h["checkvalue.h"]:::api
    end

    %% Source Implementation Layer
    subgraph "Source Implementation Layer"
        CLI["CLI Interface"]:::io
        argparse_c["argparse.c"]:::core
        polynomial_c["polynomial.c"]:::core
        moremath_c["moremath.c"]:::util
        rational_c["rational.c"]:::core
        roottest_c["roottest.c"]:::core
        checkvalue_c["checkvalue.c"]:::core
        main_c["main.c (Output Renderer)"]:::io
    end

    %% Tooling and Documentation
    Makefile["Makefile/Build"]:::build
    README["README.md"]:::doc

    %% Data Flow
    User["User"]:::io --> CLI
    CLI --> argparse_c
    argparse_c --> polynomial_c
    polynomial_c --> rational_c
    moremath_c --> rational_c
    rational_c --> roottest_c
    roottest_c --> checkvalue_c
    checkvalue_c --> main_c
    main_c -->|"stdout"| User

    %% Build Relationships
    Makefile --> argparse_c
    Makefile --> polynomial_c
    Makefile --> moremath_c
    Makefile --> rational_c
    Makefile --> roottest_c
    Makefile --> checkvalue_c
    Makefile --> main_c

    %% Documentation link
    README -.-> Makefile

    %% Click Events
    click CLI "https://github.com/hnthap/rrcal/blob/main/source/main.c"
    click argparse_h "https://github.com/hnthap/rrcal/blob/main/include/argparse.h"
    click argparse_c "https://github.com/hnthap/rrcal/blob/main/source/argparse.c"
    click polynomial_h "https://github.com/hnthap/rrcal/blob/main/include/polynomial.h"
    click types_h "https://github.com/hnthap/rrcal/blob/main/include/types.h"
    click polynomial_c "https://github.com/hnthap/rrcal/blob/main/source/polynomial.c"
    click moremath_h "https://github.com/hnthap/rrcal/blob/main/include/moremath.h"
    click macros_h "https://github.com/hnthap/rrcal/blob/main/include/macros.h"
    click moremath_c "https://github.com/hnthap/rrcal/blob/main/source/moremath.c"
    click rational_h "https://github.com/hnthap/rrcal/blob/main/include/rational.h"
    click rational_c "https://github.com/hnthap/rrcal/blob/main/source/rational.c"
    click roottest_h "https://github.com/hnthap/rrcal/blob/main/include/roottest.h"
    click roottest_c "https://github.com/hnthap/rrcal/blob/main/source/roottest.c"
    click checkvalue_h "https://github.com/hnthap/rrcal/blob/main/include/checkvalue.h"
    click checkvalue_c "https://github.com/hnthap/rrcal/blob/main/source/checkvalue.c"
    click Makefile "https://github.com/hnthap/rrcal/tree/main/Makefile"
    click README "https://github.com/hnthap/rrcal/blob/main/README.md"

    %% Styles
    classDef io fill:#AED6F1,stroke:#21618C,color:#1B2631;
    classDef core fill:#ABEBC6,stroke:#196F3D,color:#1B2631;
    classDef util fill:#F9E79F,stroke:#B7950B,color:#1B2631;
    classDef build fill:#D5D8DC,stroke:#85929E,color:#1B2631;
    classDef api fill:#D6EAF8,stroke:#2471A3,color:#1B2631;
    classDef doc fill:#E8DAEF,stroke:#6C3483,color:#1B2631;
```
