# kmously/glars architecture

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

- Interactive diagram: https://gitdiagram.com/kmously/glars
- Repository: https://github.com/kmously/glars

## Overview

##### Main Components

a) Network Interfaces Layer:
- External Interface (WAN)
- Internal Interface (LAN)

b) Core GLARS Components:
- Main Script Engine
- Rules Processing System
- API Functions Layer
- Hook System (pre_glars, setup_rules_and_policies, post_glars)

c) Underlying Linux Components:
- iptables (Firewall)
- ipset (IP Set Management)
- tc (Traffic Control)

**[Network Interfaces Layer]**
- ↕
**[GLARS Core Layer]**
- ↕
**[Linux System Layer]**

##### Specific Elements

a) Network Traffic Flow:
- NAT translation point
- Default trust zones (LAN trusted, WAN untrusted)

b) GLARS Core Functions:
- Port Management (open, forward, lock, duplicate)
- Access Control (no_internet, safe zones)
- Rate Limiting
- Connection Management

c) Configuration Components:
- Rules File Processing
- Hook System Integration
- API Function Calls

##### Detailed Component Relationships

How the following interact:
- Rules file → Hook System → Core Functions
- API Functions → iptables/ipset/tc
- Network Interfaces ↔ Core Router Logic
- Safe Zones ↔ Access Control

## Diagram (Mermaid)

```mermaid
graph TB
    %% Style Definitions
    classDef wan fill:#ff9999,stroke:#333,stroke-width:2px
    classDef lan fill:#99ff99,stroke:#333,stroke-width:2px
    classDef core fill:#9999ff,stroke:#333,stroke-width:2px
    classDef system fill:#ffff99,stroke:#333,stroke-width:2px
    classDef api fill:#ff99ff,stroke:#333,stroke-width:2px

    %% Network Interface Layer
    subgraph Network
        WAN["External Interface (WAN)"]:::wan
        LAN["Internal Interface (LAN)"]:::lan
    end

    %% GLARS Core Layer
    subgraph GLARS
        MainScript["Main Script Engine"]:::core
        RulesSystem["Rules Processing System"]:::core
        APILayer["API Functions Layer"]:::api
        HookSystem["Hook System"]:::core
    end

    %% Linux System Layer
    subgraph System
        IPTables["iptables"]:::system
        IPSet["ipset"]:::system
        TC["Traffic Control (tc)"]:::system
    end

    %% Hook Components
    PreHook["pre_glars"]:::core
    SetupHook["setup_rules_and_policies"]:::core
    PostHook["post_glars"]:::core

    %% Core Functions
    PortMgmt["Port Management"]:::core
    AccessCtrl["Access Control"]:::core
    RateLimit["Rate Limiting"]:::core
    ConnMgmt["Connection Management"]:::core

    %% Relationships
    WAN <--> MainScript
    LAN <--> MainScript
    MainScript --> RulesSystem
    RulesSystem --> HookSystem
    HookSystem --> PreHook
    HookSystem --> SetupHook
    HookSystem --> PostHook
    
    MainScript --> APILayer
    APILayer --> PortMgmt
    APILayer --> AccessCtrl
    APILayer --> RateLimit
    APILayer --> ConnMgmt
    
    PortMgmt --> IPTables
    AccessCtrl --> IPTables
    RateLimit --> TC
    ConnMgmt --> IPSet

    %% Click Events
    click MainScript "https://github.com/kmously/glars/blob/master/glars.sh"
    click RulesSystem "https://github.com/kmously/glars/tree/master/rules-template"
    click RateLimit "https://github.com/kmously/glars/blob/master/tests/test-rate-limiting.sh"

    %% Legend
    subgraph Legend
        L1["WAN Interface"]:::wan
        L2["LAN Interface"]:::lan
        L3["Core Components"]:::core
        L4["System Components"]:::system
        L5["API Functions"]:::api
    end
```
