# ranon-rat/frensmatria architecture

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

- Interactive diagram: https://gitdiagram.com/ranon-rat/frensmatria
- Repository: https://github.com/ranon-rat/frensmatria

## Overview

##### Project Type and Purpose
- The FRENSMATRIA project is a peer-to-peer (P2P) service designed for numerical hyperflows, gematria calculations, and collaborative node communication. It uses Go for backend logic and includes a web interface for interactive features.
- Its core functionality revolves around enabling nodes to communicate (using an SDP relay system), manage real-time events, and perform gematria computations while integrating with a local database.

##### File Structure
- Key Directories:
- “nodes”: Contains the bulk of the P2P node logic.
▪ “nodes/src”: This folder is subdivided into components representing various operational layers:
- “SDPConn”: Implements the SDP relay system (functions like “GetICE.go”, “setup.go”, etc.) enabling negotiation of P2P connections.
- “connections”: Manages connection events (onOpen, onMessage, onClose, etc.) indicating middleware for handling messaging between nodes.
- “controllers”: Organizes web-related logic (chat, templates, pagination, upload, websockets) to handle HTTP endpoints and view rendering.
- “core”: Contains central logic elements (channels, core functions, types, and variables) required by many modules.
- “db”: Contains database connection logic and gematria-specific queries, which underpin persistent storage.
- “common”: Contains shared functions, types, and variables that are likely used across multiple nodes or different parts of the system.
- “relay”: A separate directory with its own main.go file that launches the relay for P2P communication. This component is critical for node connection establishment.
- “images” and “nodes/static”/“nodes/templates”: These hold the assets (media and HTML/CSS/JS for the web interface).
- “nodes/db”: Stores the actual database file and SQL initialization script.
- Configuration and Dependency Files: Files like go.mod, go.sum, and various config files suggest a managed dependency environment typical for a Go-based application.

##### Components, Relationships, and Design Patterns
a. Main Components:
- P2P Node (located in “nodes”):
- Handles core business logic, node communication, and local processing.
- Divided into several layers: controllers (web interface/API), core functionalities, connection management (for real-time events), and SDP connection management.
- Integrates with a local database to store gematria results.
- Relay Service (found in “relay”):
- Acts as an intermediary for establishing P2P connections by handling SDP descriptors.
- Nodes connect to this relay based on user command line parameters.
- Database:
- Managed via the “nodes/db” package for persistent storage of gematria calculations and possibly other node-related data.
- Web Interface:
- Built with HTML templates (in “nodes/templates”) and static assets (in “nodes/static”) to support interactive features like chat and gematria calculators.
- Common Library:
- Shared routines and data structures located in “common” that assist across different modules.
b. Relationships/Interactions:
- Data and Message Flow:
- P2P Nodes communicate directly with each other using the SDP Relay System (modules in “nodes/src/SDPConn”).
- The nodes use connection management modules (“nodes/src/connections”) to handle open/close and messaging events.
- Both the relay service and nodes pass information such as SDP descriptors for establishing peer-to-peer channels.
- Controllers in the node handle HTTP requests and serve the interactive web interface.
- The database integration interacts with the node’s business logic for storing and retrieving gematria-related data.
- Key Architectural Patterns:
- Likely loosely coupled, modularized architecture separating concerns between networking (SDP, connection management), web controllers, and data persistence.
- The use of shared “common” libraries implies adherence to DRY principles.
- The clear separation between the relay (a standalone service) and the nodes demonstrates a distributed or service-oriented design.

## Diagram (Mermaid)

```mermaid
graph TD
    %% P2P Node Subgraph
    subgraph "P2P Node"
        P0["P2P Node"]:::p2pModule
        A1["SDP Connection Module"]:::p2pModule
        A2["Connection Management Module"]:::p2pModule
        A3["Controllers/Web Interface"]:::p2pModule
        A4["Database Integration Layer (Logic)"]:::p2pModule
        A5["Core Functions"]:::p2pModule
        
        %% Internal composition
        P0 --> A1
        P0 --> A2
        P0 --> A3
        P0 --> A4
        P0 --> A5
    end

    %% External Components
    B["Relay Service"]:::relay
    C(("Database (Storage)")):::database
    D["Common Library/Utils"]:::common

    %% Inter-component Connections
    A1 -->|"SDP_negotiation"| B
    A3 -->|"HTTP_req"| A4
    A4 -->|"DB_query"| C
    A2 -->|"triggers"| A5
    A3 -->|"integrates"| A5
    A5 -->|"uses"| D

    %% Click Events
    click P0 "https://github.com/ranon-rat/frensmatria/tree/main/nodes"
    click A1 "https://github.com/ranon-rat/frensmatria/tree/main/nodes/src/SDPConn"
    click A2 "https://github.com/ranon-rat/frensmatria/tree/main/nodes/src/connections"
    click A3 "https://github.com/ranon-rat/frensmatria/tree/main/nodes/src/controllers"
    click A4 "https://github.com/ranon-rat/frensmatria/tree/main/nodes/src/db"
    click C "https://github.com/ranon-rat/frensmatria/tree/main/nodes/db"
    click D "https://github.com/ranon-rat/frensmatria/tree/main/common"
    click B "https://github.com/ranon-rat/frensmatria/blob/main/relay/main.go"

    %% Styles
    classDef p2pModule fill:#ADD8E6,stroke:#333,stroke-width:2px;
    classDef relay fill:#90EE90,stroke:#333,stroke-width:2px;
    classDef database fill:#FFB6C1,stroke:#333,stroke-width:2px;
    classDef common fill:#FFFF99,stroke:#333,stroke-width:2px;
```
