# mopires/pretty-markup architecture

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

- Interactive diagram: https://gitdiagram.com/mopires/pretty-markup
- Repository: https://github.com/mopires/pretty-markup

## Overview

##### Main Components
- Input / Preprocessor CLI: Represent where users provide their Pretty Markup (.pm) files. This entry point is triggered either via the command line (using “pm” or “npx pm”) or through programmatic imports.
- File Manager Module: (src/modules/FileManager.ts) This component deals with reading files from the ./src directory where the .pm files live.
- Tokenizer Module: (src/modules/Tokenizer.ts) The first stage in “compiling” the input where the raw text is broken down into tokens.
- Lexical Analyzer Module: (src/modules/LexicalAnalizer.ts) Likely performs additional processing on tokens – such as validating or refining token sequences.
- Parser Module: (src/modules/Parser.ts) Converts the token stream into an Abstract Syntax Tree (AST) or other structured intermediate representation that can later be rendered as HTML.
- Stream Submodule: (src/modules/stream/index.ts) This helper module is probably used by the processing components for handling data streams (e.g., sequential reading or buffered input).
- Configuration: (src/config directory and files like build.ts, dev.ts, env.json) These contain different environment and build settings influencing how the compiler runs under various conditions.
- Interface Definitions: (src/interface folder) Serve to strictly define the types and expected structure for build settings, elements, and files that flow between modules.
- Main Entry Point: (src/Main.ts and src/index.ts) These files act as the application’s bootstrap where modules are assembled to perform the compilation from Pretty Markup to HTML.

##### Relationships and Data Flow
- Next, represent the File Manager reading this content from a file system (as indicated by the instructions in the README).
- From the Tokenizer, show a subsequent flow into the Lexical Analyzer, indicating additional processing/refinement.
- Finally, illustrate that the output of the Parser is used to generate standard HTML code. This generated HTML might be displayed on a console or written to an output file.
- Also, highlight the use of TypeScript interfaces (displayed as a layer that underpins the modules) showing contract-based interactions between components.

##### Architectural Patterns and Design Principles
- Modularity: Each core functionality (e.g., file management, tokenization, parsing) is encapsulated in distinct modules.
- Pipeline / Staged Compilation: The sequential processing steps (from raw input to tokens to an AST and then HTML output) reflect classic compiler pipelines.
- Separation of Configuration: The environment-specific and build configurations are segregated from the main code logic.
- Type Safety: The use of explicit interfaces enforces contracts between different layers and modules.

## Diagram (Mermaid)

```mermaid
flowchart TD
    A["User Input\n(Provide .pm file)"]:::input
    B["Preprocessor CLI\n(src/Main.ts / src/index.ts)"]:::cli
    C["FileManager.ts\nRead & Manage .pm Files"]:::module
    D["Tokenizer.ts\nTokenize Input"]:::module
    E["LexicalAnalizer.ts\nRefine Tokens"]:::module
    F["Parser.ts\nBuild AST & Convert to HTML"]:::module
    G["HTML Output"]:::output

    H["Stream Submodule\n(Helper for data streaming)"]:::helper
    I["Configuration\n(build.ts, dev.ts, env.json)"]:::config
    J["Interface Definitions\n(Build.ts, Element.ts, File.ts)"]:::interface

    %% Main processing pipeline
    A -->|"provides input"| B
    B -->|"invokes file reading"| C
    C -->|"reads file content"| D
    D -->|"produces token stream"| E
    E -->|"generates refined tokens"| F
    F -->|"outputs HTML"| G

    %% Supporting dependency arrows
    I -->|"configures"| B
    I -->|"configures"| C

    J -->|"defines contracts"| C
    J -->|"defines contracts"| D
    J -->|"defines contracts"| E
    J -->|"defines contracts"| F

    %% Helper module usage (dashed to indicate support)
    D -.->|"stream handling"| H
    E -.->|"stream handling"| H

    %% Click events
    click B "https://github.com/mopires/pretty-markup/blob/main/src/Main.ts"
    click B "https://github.com/mopires/pretty-markup/blob/main/src/index.ts"
    click C "https://github.com/mopires/pretty-markup/blob/main/src/modules/FileManager.ts"
    click D "https://github.com/mopires/pretty-markup/blob/main/src/modules/Tokenizer.ts"
    click E "https://github.com/mopires/pretty-markup/blob/main/src/modules/LexicalAnalizer.ts"
    click F "https://github.com/mopires/pretty-markup/blob/main/src/modules/Parser.ts"
    click H "https://github.com/mopires/pretty-markup/blob/main/src/modules/stream/index.ts"
    click I "https://github.com/mopires/pretty-markup/tree/main/src/config"
    click J "https://github.com/mopires/pretty-markup/tree/main/src/interface"

    %% Styles
    classDef input fill:#FAD7A0,stroke:#333,stroke-width:2px;
    classDef cli fill:#AED6F1,stroke:#333,stroke-width:2px;
    classDef module fill:#D5F5E3,stroke:#333,stroke-width:2px;
    classDef output fill:#F9E79F,stroke:#333,stroke-width:2px;
    classDef helper fill:#F5B7B1,stroke:#333,stroke-width:2px;
    classDef config fill:#D2B4DE,stroke:#333,stroke-width:2px;
    classDef interface fill:#F0B27A,stroke:#333,stroke-width:2px;
```
