# zacharyvmm/logic-expression-simplifier architecture

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

- Interactive diagram: https://gitdiagram.com/zacharyvmm/logic-expression-simplifier
- Repository: https://github.com/zacharyvmm/logic-expression-simplifier

## Overview

##### Project Type and Purpose
- This is a C-based command-line tool (not a full-stack web app) whose sole purpose is to simplify propositional logic expressions. It acts as a small “compiler-style” pipeline: it lexes the input, parses it into an AST (binary expression tree), applies simplification rules, then pretty-prints the result.

##### High-Level File Structure Analysis
- Top-level files:
- README.md, Report.pdf (documentation)
- src/Makefile (build automation)
- src/*.c, src/*.h (modular C code)
- Core modules:
- main.c       – orchestrates the entire flow
- parser.c/h  – tokenizes input and builds the AST
- node.c/h    – defines and manipulates tree-node data structures
- solve.c/h   – walks the AST and applies logical simplification rules
- .c/h – serializes the simplified AST back to a string and outputs it

##### Key Components
a. CLI Frontend
- User’s console input → main.c
b. Lexer & Parser
- lexer (embedded in parser.c) tokenizes the string into ENUM tokens
- parser builds a binary expression tree (AST)
c. AST Representation
- node.c/h structures (internal tree nodes with operator/value, left/right pointers)
d. Simplifier (Solver)
- solve.c/h applies logical laws in a greedy traversal over the AST
e. Output Formatter (Display)
- .c/h traverses the simplified AST, generates a string, and prints to stdout
f. Build & Deployment
- Makefile invokes GCC to compile modules and link the executable

##### Relationships and Data Flows
- main.c calls “Parser” → produces AST
- AST passed to “Solver” → returns simplified AST
- simplified AST passed to “Display” → outputs string to console
- Node utilities are used by both Parser and Solver (depicted as a shared library or component)
- Makefile sits “outside” at build time but is not part of runtime flow

##### Architectural Patterns & Design Principles
- Pipeline pattern: data transformation in sequential stages (Lex → Parse → Simplify → Render)
- Modular C design: each .c/.h pair encapsulates one concern
- Single responsibility: parser only builds AST, solver only applies rules, display only prints
- Extensibility point: new logical laws could be added to solve.c

## Diagram (Mermaid)

```mermaid
flowchart TB
    %% Pipeline Flow
    UserCLI["User CLI Input"]:::infra
    Main["main.c\nOrchestrator"]:::runtime
    Parser["Lexer/Parser\n(parser.c/h)"]:::runtime
    AST["AST (Expression Tree)"]:::data
    Solver["Solver\n(solve.c/h)"]:::runtime
    Display["Display\n(display.c/h)"]:::runtime
    Output["Simplified Output\n(Console)"]:::infra

    %% Documentation & Build
    subgraph "Documentation"
        README["README.md"]:::infra
        Report["Report.pdf"]:::infra
    end

    Makefile["Makefile"]:::infra

    %% Data Flow
    UserCLI --> Main
    Main --> Parser
    Parser --> AST
    AST --> Solver
    Solver --> AST
    AST --> Display
    Display --> Output

    %% Dependencies
    Parser -.-> NodeLib
    Solver -.-> NodeLib

    %% Supporting Modules
    NodeLib["Node Module\n(node.c/h)"]:::data

    %% Click Events
    click Main "https://github.com/zacharyvmm/logic-expression-simplifier/blob/main/src/main.c"
    click Parser "https://github.com/zacharyvmm/logic-expression-simplifier/blob/main/src/parser.c"
    click Solver "https://github.com/zacharyvmm/logic-expression-simplifier/blob/main/src/solve.c"
    click Display "https://github.com/zacharyvmm/logic-expression-simplifier/blob/main/src/display.c"
    click NodeLib "https://github.com/zacharyvmm/logic-expression-simplifier/blob/main/src/node.c"
    click Makefile "https://github.com/zacharyvmm/logic-expression-simplifier/tree/main/src/Makefile"
    click README "https://github.com/zacharyvmm/logic-expression-simplifier/blob/main/README.md"
    click Report "https://github.com/zacharyvmm/logic-expression-simplifier/blob/main/Report.pdf"

    %% Styling
    classDef runtime fill:#ADD8E6,stroke:#333,stroke-width:1px;
    classDef data fill:#90EE90,stroke:#333,stroke-width:1px;
    classDef infra fill:#D3D3D3,stroke:#333,stroke-width:1px;
```
