# gravitl/netmaker architecture

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

- Interactive diagram: https://gitdiagram.com/gravitl/netmaker
- Repository: https://github.com/gravitl/netmaker

## Overview

##### Main System Components

a) Server Components (Core):
- Authentication Service (/auth)
- API Controllers (/controllers)
- Database Layer (/database)
- Message Queue System (/mq)
- Business Logic Layer (/logic)
- Server Configuration (/servercfg)

b) Client Components:
- Netclient (/netclient)
- CLI Interface (/cli)

c) External Integrations:
- DNS Management
- Authentication Providers (OAuth)
- MQTT Brokers (EMQX)

##### Architectural Patterns to Highlight

**┌─ Client Layer ─────────────────────┐**
- CLI Interface                    │
- Netclient                       │
- ┬────────────────┘

**┌─ API Layer ──────▼────────────────┐**
- REST Controllers                 │
- Authentication                   │
- Middleware                       │
- ┬────────────────┘

**┌─ Business Layer ─▼────────────────┐**
- Network Logic                    │
- Node Management                  │
- Access Control                   │
- User Management                  │
- ┬────────────────┘

**┌─ Data Layer ─────▼────────────────┐**
- Database (SQLite/PostgreSQL)     │
- Message Queue                    │
- Configuration Store              │
- ┘

##### Key Interactions

- Client-Server Communication (REST API)
- WireGuard Peer Connections
- Database Operations
- Message Queue Publishing/Subscribing
- DNS Updates

##### Deployment Context

Deployment options:
- Docker Container Deployment
- Kubernetes Deployment
- Cloud Provider Integration
- On-premises Installation

##### Additional Details

- Scalability points
- Security boundaries
- Data flow directions
- Component dependencies
- Extension points

Remember to:
- Clear boundaries between components
- Both control and data flows
- Security measures
- Monitoring points

This system design should reflect Netmaker's architecture as a WireGuard automation platform while showing both the open-source core and professional features in a clear, hierarchical structure.

## Diagram (Mermaid)

```mermaid
graph TB
    subgraph Client
        CLI["CLI Interface"]
        NC["Netclient"]
        CLI --> NC
    end

    subgraph "API Layer"
        API["API Controllers"]
        Auth["Authentication Service"]
        Mid["Middleware"]
        API --> Auth
        API --> Mid
    end

    subgraph "Business Layer"
        NL["Network Logic"]
        NM["Node Management"]
        AC["Access Control"]
        UM["User Management"]
        Log["Logging System"]
    end

    subgraph "Data Layer"
        DB[("Database")]
        MQ["Message Queue"]
        Cfg["Configuration Store"]
    end

    subgraph "External Services"
        DNS["DNS Management"]
        OAuth["OAuth Providers"]
        MQTT["MQTT Broker"]
    end

    subgraph "Pro Features"
        HA["High Availability"]
        EA["Enterprise Auth"]
        Mon["Monitoring"]
    end

    %% Client Layer Connections
    CLI --> API
    NC --> API
    NC --> MQ

    %% API Layer Connections
    API --> NL
    API --> NM
    Auth --> AC
    Mid --> Log

    %% Business Layer Connections
    NL --> DB
    NM --> DB
    AC --> DB
    UM --> DB
    NL --> MQ
    NM --> MQ

    %% Data Layer Connections
    MQ --> MQTT
    DB --> Cfg

    %% External Connections
    NL --> DNS
    Auth --> OAuth
    EA --> OAuth

    %% Pro Feature Connections
    HA --> DB
    HA --> MQ
    EA --> Auth
    Mon --> Log

    %% Component Mappings
    click Auth "https://github.com/gravitl/netmaker/blob/master/auth/auth.go"
    click API "https://github.com/gravitl/netmaker/blob/master/controllers/controller.go"
    click DB "https://github.com/gravitl/netmaker/blob/master/database/database.go"
    click MQ "https://github.com/gravitl/netmaker/blob/master/mq/mq.go"
    click NL "https://github.com/gravitl/netmaker/blob/master/logic/networks.go"
    click Cfg "https://github.com/gravitl/netmaker/blob/master/servercfg/serverconf.go"
    click NC "https://github.com/gravitl/netmaker/blob/master/netclient/ncutils/netclientutils.go"
    click CLI "https://github.com/gravitl/netmaker/blob/master/cli/main.go"
    click Log "https://github.com/gravitl/netmaker/blob/master/logger/logger.go"
    click EA "https://github.com/gravitl/netmaker/blob/master/pro/auth/auth.go"
    click HA "https://github.com/gravitl/netmaker/blob/master/pro/initialize.go"

    classDef default fill:#f9f9f9,stroke:#333,stroke-width:2px
    classDef client fill:#90EE90,stroke:#333,stroke-width:2px
    classDef api fill:#87CEEB,stroke:#333,stroke-width:2px
    classDef business fill:#FFB6C1,stroke:#333,stroke-width:2px
    classDef data fill:#DDA0DD,stroke:#333,stroke-width:2px
    classDef external fill:#F0E68C,stroke:#333,stroke-width:2px
    classDef pro fill:#FFA07A,stroke:#333,stroke-width:2px

    class CLI,NC client
    class API,Auth,Mid api
    class NL,NM,AC,UM,Log business
    class DB,MQ,Cfg data
    class DNS,OAuth,MQTT external
    class HA,EA,Mon pro
```
