# ramantehlan/mateix architecture

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

- Interactive diagram: https://gitdiagram.com/ramantehlan/mateix
- Repository: https://github.com/ramantehlan/mateix

## Overview

##### Main Components

a) Client Components:
- Mateix CLI Tool
- MateixWatch Service
- inotify-tools (File System Monitor)
- Configuration Files
- Local File System

b) Server Components:
- TCP Server
- File Handler
- Checksum Validator

##### Architecture Overview
The system should be represented as a bi-directional synchronization system with the following key aspects:

**[System Design Layout]**

**Device A                                    Device B**

- MateixWatch    |  |                 | |   MateixWatch    |  |
- (inotify-tools)  |  |                 | | (inotify-tools)  |  |

- v---------+  |    TCP/1248     | +--------v---------+  |
- Mateix CLI     |<-+---------------->| |   Mateix CLI     |  |

- File Handler  | |  |                 | | |File Handler  | |  |

- Checksum Gen. | |  |                 | | |Checksum Gen. | |  |

- v---------+  |                 | +--------v---------+  |
- Config Files    |  |                 | |  Config Files    |  |
- /.mateix/config  |  |                 | | /.mateix/config  |  |
- /etc/.mateix/   |  |                 | | /etc/.mateix/   |  |

- v---------+  |                 | +--------v---------+  |
- Watched Files   |  |                 | |  Watched Files   |  |
- (data file)   |  |                 | |    (data file)   |  |

##### Important Elements to Highlight

a) Service Flow:
- How MateixWatch service starts at boot
- Continuous monitoring of specified directories
- TCP communication path between devices

b) Configuration:
- Location of config files (/etc/.mateix/)
- Relationship between watched directories and config

c) File Handling:
- Demonstrate checksum generation and comparison
- Bi-directional update flow

##### Additional Notes

- Port number (1248) for TCP communication
- File paths for important configuration files
- System service integration points
- Notes about checksum-based synchronization

##### Key Processes to Illustrate

a) Initialization Flow:
**[Install] -> [Create Config] -> [Enable Service] -> [Start Monitoring]**

b) Synchronization Flow:
**[File Change] -> [Detect] -> [Generate Checksum] -> [Compare] -> [Sync]**

##### Implementation Details
- Relationship between the Go packages
- Error handling flow (packages/e)
- Command execution path (packages/command)

## Diagram (Mermaid)

```mermaid
graph TB
    subgraph Device_A
        direction TB
        A_Watch["MateixWatch Service"]:::monitor
        A_Inotify["inotify-tools"]:::monitor
        A_CLI["Mateix CLI"]:::core
        A_FileHandler["File Handler"]:::core
        A_Checksum["Checksum Generator"]:::core
        A_Config["Configuration Files"]:::config
        A_Files["Watched Files"]:::files
        
        A_Watch --> A_CLI
        A_Inotify --> A_Watch
        A_CLI --> A_FileHandler
        A_FileHandler --> A_Checksum
        A_CLI --> A_Config
        A_Config --> A_Files
    end

    subgraph Device_B
        direction TB
        B_Watch["MateixWatch Service"]:::monitor
        B_Inotify["inotify-tools"]:::monitor
        B_CLI["Mateix CLI"]:::core
        B_FileHandler["File Handler"]:::core
        B_Checksum["Checksum Generator"]:::core
        B_Config["Configuration Files"]:::config
        B_Files["Watched Files"]:::files
        
        B_Watch --> B_CLI
        B_Inotify --> B_Watch
        B_CLI --> B_FileHandler
        B_FileHandler --> B_Checksum
        B_CLI --> B_Config
        B_Config --> B_Files
    end

    TCP{{"TCP Server<br>(Port 1248)"}}:::communication
    A_CLI <--> |Bi-directional Sync| TCP
    B_CLI <--> |Bi-directional Sync| TCP

    subgraph Core_Components["Core Components"]
        direction TB
        Init["Service Initialization"]:::core
        Install["Installation Manager"]:::core
        Update["Update Manager"]:::core
        Uninstall["Uninstallation Manager"]:::core
        CmdHandler["Command Handler"]:::core
        ErrHandler["Error Handler"]:::core
    end

    click A_CLI "https://github.com/ramantehlan/Mateix/blob/master/main.go"
    click TCP "https://github.com/ramantehlan/Mateix/blob/master/server.go"
    click A_Watch "https://github.com/ramantehlan/Mateix/blob/master/service/mateix-watch.service"
    click CmdHandler "https://github.com/ramantehlan/Mateix/blob/master/packages/command/command.go"
    click ErrHandler "https://github.com/ramantehlan/Mateix/blob/master/packages/e/e.go"
    click Init "https://github.com/ramantehlan/Mateix/blob/master/init.go"
    click Install "https://github.com/ramantehlan/Mateix/tree/master/install"
    click Update "https://github.com/ramantehlan/Mateix/blob/master/update.go"
    click Uninstall "https://github.com/ramantehlan/Mateix/blob/master/uninstall.go"
    click B_Watch "https://github.com/ramantehlan/Mateix/tree/master/service/mateixWatch"

    classDef monitor fill:#3498db,stroke:#2980b9,color:white
    classDef core fill:#2ecc71,stroke:#27ae60,color:white
    classDef config fill:#f1c40f,stroke:#f39c12,color:black
    classDef files fill:#95a5a6,stroke:#7f8c8d,color:white
    classDef communication fill:#e74c3c,stroke:#c0392b,color:white

    subgraph Legend
        L_Monitor["Monitoring Component"]:::monitor
        L_Core["Core Component"]:::core
        L_Config["Configuration"]:::config
        L_Files["File System"]:::files
        L_Comm["Communication"]:::communication
    end
```
