# ronkok/hurmet architecture

> Architecture diagram of the GitHub repository ronkok/hurmet, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2024-12-28). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/ronkok/hurmet
- Repository: https://github.com/ronkok/hurmet

## Overview

##### Main Components

a) Frontend Layer:
- Rich Text Editor Interface (based on ProseMirror, evident from prosemirror.js)
- Calculation Engine
- Document Renderer
- Progressive Web App (PWA) Infrastructure

b) Core Processing Components:
- Parser System (parser.js, lexer.js)
- Calculation Engine (calculate.js, evaluate.js)
- Markdown Processing (md2ast.js, md2html.js)
- Mathematical Processing (complex.js, matrix.js, rational.js)

c) Specialized Modules:
- Beam Analysis System (beam/ directory)
- Unit Handling System (units.js)
- Spreadsheet Functionality (spreadsheet.js)

##### Component Relationships

- User Input → Rich Text Editor → Parser → Calculation Engine → Document Renderer
- Document Storage ↔ PWA Cache System
- Mathematical Expressions → TeX Parser → Calculation Engine

##### Architectural Patterns to Highlight

- Module-based architecture (evident from src/ structure)
- Component-based frontend (nodeviews.js, schema.js)
- Service Worker architecture (sw.js) for PWA functionality

**User Interface (Editor)**

**Parser System --- Calculation Engine --- Document Renderer**

**Storage System --- Mathematical Modules --- Specialized Tools**

##### Important Implementation Details to Note

- PWA caching mechanism
- Separation between editing and calculation
- Beam analysis subsystem
- Integration with TeX parsing (texToCalc.js)

##### Key Integration Points

- Document how the editor interfaces with the calculation engine
- How the PWA system enables offline functionality
- Mathematical expression parsing flow

This architecture should emphasize Hurmet's primary goal of maintaining readability while performing complex calculations, as highlighted in the README.

## Diagram (Mermaid)

```mermaid
graph TB
    subgraph UI
        Editor["Rich Text Editor Interface"]
        DocRender["Document Renderer"]
    end

    subgraph Core
        Parser["Parser System"]
        CalcEngine["Calculation Engine"]
        MarkdownProc["Markdown Processing"]
    end

    subgraph Math
        MathProc["Mathematical Processing"]
        TeXParser["TeX Parser"]
        Units["Unit Handling"]
    end

    subgraph Storage
        PWA["PWA Infrastructure"]
        Cache[(Cache)]
    end

    subgraph Specialized
        Beam["Beam Analysis"]
        Spreadsheet["Spreadsheet System"]
    end

    %% Main Flow
    Editor --> Parser
    Parser --> CalcEngine
    CalcEngine --> DocRender
    Editor --> MarkdownProc
    MarkdownProc --> DocRender

    %% Math Processing Flow
    Editor --> TeXParser
    TeXParser --> MathProc
    MathProc --> CalcEngine
    Units --> CalcEngine

    %% Specialized Tools
    CalcEngine --> Beam
    CalcEngine --> Spreadsheet

    %% Storage Flow
    Editor -.-> PWA
    PWA -.-> Cache

    %% Styling
    classDef core fill:#2374ab
    classDef math fill:#ff7f50
    classDef storage fill:#8a2be2
    classDef specialized fill:#808080
    classDef ui fill:#4CAF50

    class Editor,DocRender ui
    class Parser,CalcEngine,MarkdownProc core
    class MathProc,TeXParser,Units math
    class PWA,Cache storage
    class Beam,Spreadsheet specialized

    %% Click Events
    click Editor "https://github.com/ronkok/Hurmet/blob/master/preview/prosemirror.js"
    click DocRender "https://github.com/ronkok/Hurmet/blob/master/src/renderMD.js"
    click PWA "https://github.com/ronkok/Hurmet/blob/master/site/sw.js"
    click Parser "https://github.com/ronkok/Hurmet/blob/master/src/parser.js"
    click CalcEngine "https://github.com/ronkok/Hurmet/blob/master/src/calculate.js"
    click MarkdownProc "https://github.com/ronkok/Hurmet/blob/master/src/md2ast.js"
    click MathProc "https://github.com/ronkok/Hurmet/blob/master/src/complex.js"
    click Beam "https://github.com/ronkok/Hurmet/tree/master/src/beam/"
    click Units "https://github.com/ronkok/Hurmet/blob/master/src/units.js"
    click Spreadsheet "https://github.com/ronkok/Hurmet/blob/master/src/spreadsheet.js"
    click TeXParser "https://github.com/ronkok/Hurmet/blob/master/src/texToCalc.js"
```
