# labhansh2/models-of-computation architecture

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

- Interactive diagram: https://gitdiagram.com/labhansh2/models-of-computation
- Repository: https://github.com/labhansh2/models-of-computation

## Overview

##### Project type and purpose
- This is a C++ “Models of Computation” library and demo application.
- It simulates theoretical automata (DFA, NFA, PDA, etc.) according to their formal definitions.
- The primary consumer is `main.cpp`, which exercises the library, and the library itself is structured under `include/` (interfaces) and `moc/` (implementations).

##### File structure
- Top‑level:
- Makefile – build instructions for compiling the code
- `main.cpp` – CLI or demo harness that drives the automata simulations
- / – public headers (`dfa.h`, `nfa.h`, `pda.h`) defining each automaton’s interface
- moc/ – source files (`dfa.cpp`, `nfa.cpp`, `pda.cpp`) implementing each automaton
- public/ – static assets (e.g., `Automaton.png`) for documentation/visuals
- Tooling/config: `.clang-format`, `.gitignore`, `.vscode` settings

##### README for additional insights
- Confirms the goal: faithful implementations of theoretical models
- Shows a dependency graph of automata types (via the Automaton.png)
- Lists future MOCs to add, implying the library is extensible

##### Main components
a. Library Layer (“Core MOC Modules”):
- DFA Module
- NFA Module
- PDA Module
- (Future: DPDA, NTM, etc.)
b. Interface Layer (Headers):
- Expose API to construct, configure, and run each automaton
c. Application Layer:
- `main.cpp` – user entry point; parses input, invokes library, displays results
d. Build & Configuration:
- Makefile orchestrates compilation of moc/*.cpp + main.cpp
- .clang-format/.vscode control formatting and editor behavior
e. Documentation Assets:
- public/Automaton.png used in README

##### Relationships and data flow
- main.cpp → includes header → invokes methods on MOC classes → MOC classes hold state/transitions → produce acceptance/rejection results → main.cpp prints output
- Makefile → compiles sources → links object files → produces executable

##### Important architectural patterns & design principles
- Separation of interface (headers) and implementation (source)
- Modular design: each MOC lives in its own namespace/file pair
- Extensibility: new automaton modules drop in under include/ + moc/ and get built automatically
- Single‑responsibility: main.cpp only drives the library; library does not handle I/O

## Diagram (Mermaid)

```mermaid
flowchart TD
    %% Application Layer
    subgraph "Application Layer"
        direction TB
        Main["main.cpp\n(Demo CLI)"]:::application
    end

    %% Interface Layer
    subgraph "Interface Layer"
        direction TB
        dfa_h["dfa.h\n(include/dfa.h)"]:::library
        nfa_h["nfa.h\n(include/nfa.h)"]:::library
        pda_h["pda.h\n(include/pda.h)"]:::library
    end

    %% Core MOC Modules
    subgraph "Core MOC Modules"
        direction TB
        dfa_cpp["dfa.cpp\n(moc/dfa.cpp)"]:::library
        nfa_cpp["nfa.cpp\n(moc/nfa.cpp)"]:::library
        pda_cpp["pda.cpp\n(moc/pda.cpp)"]:::library
        Future["+ Future MOCs"]:::library
    end

    %% Build & Configuration
    subgraph "Build & Configuration"
        direction TB
        Makefile["Makefile"]:::build
        ClangFmt[".clang-format"]:::build
        VSCode[".vscode/"]:::build
    end

    %% Documentation Assets
    subgraph "Documentation Assets"
        direction TB
        PublicPNG["Automaton.png\n(public/)"]:::docs
    end

    %% Executable
    Exec["Executable\n(via Makefile)"]:::build
    class Exec dashed

    %% Connections
    Main -->|#include| dfa_h
    Main -->|#include| nfa_h
    Main -->|#include| pda_h

    dfa_h -->|implements| dfa_cpp
    nfa_h -->|implements| nfa_cpp
    pda_h -->|implements| pda_cpp

    Makefile -->|compiles| Main
    Makefile -->|compiles| dfa_cpp
    Makefile -->|compiles| nfa_cpp
    Makefile -->|compiles| pda_cpp
    Makefile -->|links| Exec

    %% Click Events
    click dfa_h "https://github.com/labhansh2/models-of-computation/blob/main/include/dfa.h"
    click nfa_h "https://github.com/labhansh2/models-of-computation/blob/main/include/nfa.h"
    click pda_h "https://github.com/labhansh2/models-of-computation/blob/main/include/pda.h"
    click dfa_cpp "https://github.com/labhansh2/models-of-computation/blob/main/moc/dfa.cpp"
    click nfa_cpp "https://github.com/labhansh2/models-of-computation/blob/main/moc/nfa.cpp"
    click pda_cpp "https://github.com/labhansh2/models-of-computation/blob/main/moc/pda.cpp"
    click Main "https://github.com/labhansh2/models-of-computation/blob/main/main.cpp"
    click Makefile "https://github.com/labhansh2/models-of-computation/tree/main/Makefile"
    click ClangFmt "https://github.com/labhansh2/models-of-computation/blob/main/.clang-format"
    click VSCode "https://github.com/labhansh2/models-of-computation/tree/main/.vscode/"
    click PublicPNG "https://github.com/labhansh2/models-of-computation/tree/main/public/"

    %% Styles
    classDef library fill:#add8e6,stroke:#000,stroke-width:1px
    classDef application fill:#c2f0c2,stroke:#000,stroke-width:1px
    classDef build fill:#ffd8b1,stroke:#000,stroke-width:1px
    classDef docs fill:#d3d3d3,stroke:#000,stroke-width:1px
    classDef dashed stroke-dasharray: 5 5,stroke:#000,stroke-width:1px
```
