# kdudkov/goatak architecture

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

- Interactive diagram: https://gitdiagram.com/kdudkov/goatak
- Repository: https://github.com/kdudkov/goatak

## Overview

##### Project Type and Purpose
- GoATAK is a hybrid server–client application written in Go. Its main functions are to serve as a TAK server (supporting both XML and protobuf CoT protocols) and as a client that connects via SSL for situational awareness.
- The README gives insight into key features like certificate enrollment, mission package management, video feeds, and user “visibility scopes”, while providing both a traditional ATAK desktop client and a web-based UI.

##### Analyzing the File Structure
- Top-level Directories:
– “cmd”: Contains multiple subdirectories (like goatak_server, mm, takreplay, userctl, webclient) which indicate several executables that serve different functionalities (server, client, CLI tools).
– “pkg”: Contains core libraries that deal with CoT messaging, protobuf conversions, coordinate conversions, TLS utilities, logging, and models, all of which are essential to the core functionality.
– “internal”: Houses more specialized logic such as client handlers, repository interfaces, and WebSocket handling.
– “protobuf”: Stores the .proto files used for generating the protocol buffers needed for v2 CoT messages.
– “cert”: Contains scripts for generating certificates, highlighting SSL and certificate management aspects.
– “staticfiles” and “doc”: Serve the web assets (CSS, JS, HTML templates) and documentation—which reinforces the web client’s role.
- Configuration & CI:
– Files like Dockerfile, Makefile, GitHub workflows, and goreleaser configuration indicate the build, deployment, and CI/CD integrations.

##### Key Architectural Components
- Server Component (goatak_server): Handles API endpoints (admin, authentication, certificate APIs, mission and metrics endpoints), establishes TCP/UDP servers, and processes CoT messages.
- Database Layer: Implemented via the “database” subpackage under goatak_server for managing queries related to missions, invites, and subscriptions.
- Web Client Component: Found under cmd/webclient has its own server code and templates. This part uses static assets (possibly also mentioning third-party libraries like Leaflet and Milsymbol) to provide mapping UI.
- Messaging / CoT Handling: Managed mostly via “pkg/cot”, “pkg/cotproto”, and “protobuf” with both XML and protobuf functionalities.
- Auxiliary Tools: Other executables (mm, takreplay, userctl) support mission management, data replay or export, and command-line user operations.
- Certificate Management: The “cert” scripts and APIs in the goatak_server allow handling of secure connections and client enrollment.

##### Relationships and Data Flow
- The server processes incoming CoT messages (using either XML or protobuf) via its API modules, interacting with the database layer for persistent operations.
- The server also utilizes helper libraries (from pkg, internal) for tasks like logging, TLS management, message conversion, etc.
- Web clients obtain static files and templates from the “staticfiles” directory, with the server rendering pages that incorporate mapping libraries (Leaflet, Milsymbol).
- Certificate management flows should be depicted, showing the enrollment API interacting with the certificate scripts and TLS utilities.
- CI/CD pipelines (GitHub workflows, Dockerfile, Makefile) can be drawn as a side component indicating the build and deployment processes.

##### Architectural Patterns and Design Principles
- Modular Design: Separation of concerns is clear with distinct directories handling API logic, client handling, message processing, and auxiliary functionalities.
- Layered Architecture: Logical layering exists between the presentation (web client), business logic (server API and processing), and data access (database queries, repository interfaces).
- Protocol Support: Dual CoT protocol support is achieved via well-isolated components handling XML vs. protobuf messaging.
- Security: Emphasis on SSL and certificate management plays into design decisions for secure communication.

## Diagram (Mermaid)

```mermaid
flowchart TD

    %% External Clients
    subgraph "External Clients"
        AATAK["ATAK Client"]:::client
        ABrowser["Web Browser"]:::client
    end

    %% Backend Services
    subgraph "Backend Services"
        TS["TAK Server"]:::backend
        WCS["Web Client Server"]:::backend
    end

    %% Common Services
    subgraph "Common Services"
        DB["Database"]:::database
        CTXML["CoT XML (pkg/cot)"]:::messaging
        CTPB["CoT Protobuf (pkg/cotproto)"]:::messaging
        PB["Protocol Buffers (protobuf)"]:::messaging
        CERT["Certificate Management"]:::security
        TLS["TLS Utilities"]:::security
        LOG["Logging"]:::core
        ST["Server Templates"]:::assets
        SA["Static Assets"]:::assets
        WCT["Web Client Templates"]:::assets
    end

    %% Auxiliary Tools
    subgraph "Auxiliary Tools"
        MM["Mission Management (mm)"]:::tools
        TR["TakReplay"]:::tools
        UC["UserCTL"]:::tools
    end

    %% CI/CD and Deployment
    subgraph "CI/CD"
        DF["Dockerfile"]:::ci
        MF["Makefile"]:::ci
        GH["GitHub Workflows"]:::ci
    end

    %% External Clients connections
    AATAK -->|"connects_via_SSL"| TS
    ABrowser -->|"accesses_UI"| WCS

    %% Backend Service connections
    TS -->|"handles_CoT_messages"| CTXML
    TS -->|"handles_CoT_messages"| CTPB
    TS -->|"handles_CoT_messages"| PB
    TS -->|"certificate_enrollment"| CERT
    TS -->|"uses_TLS"| TLS
    TS -->|"logs_activity"| LOG
    TS -->|"data_persistence"| DB
    TS -->|"renders_pages"| ST

    WCS -->|"renders_UI"| WCT
    WCS -->|"serves_static_content"| SA
    WCS -->|"communicates_with"| TS

    %% Auxiliary Tools interactions
    MM -->|"manages_missions"| TS
    TR -->|"replays_data"| TS
    UC -->|"user_operations"| TS

    %% CI/CD relationships (interconnected pipelines)
    DF --- MF
    DF --- GH
    MF --- GH

    %% Messaging protocols convergence
    CTXML --- CTPB
    CTXML --- PB

    %% Click Events
    click TS "https://github.com/kdudkov/goatak/tree/master/cmd/goatak_server"
    click DB "https://github.com/kdudkov/goatak/tree/master/cmd/goatak_server/database"
    click WCS "https://github.com/kdudkov/goatak/tree/master/cmd/webclient"
    click CTXML "https://github.com/kdudkov/goatak/tree/master/pkg/cot"
    click CTPB "https://github.com/kdudkov/goatak/tree/master/pkg/cotproto"
    click PB "https://github.com/kdudkov/goatak/tree/master/protobuf"
    click MM "https://github.com/kdudkov/goatak/tree/master/cmd/mm"
    click TR "https://github.com/kdudkov/goatak/tree/master/cmd/takreplay"
    click UC "https://github.com/kdudkov/goatak/tree/master/cmd/userctl"
    click CERT "https://github.com/kdudkov/goatak/tree/master/cert"
    click TLS "https://github.com/kdudkov/goatak/tree/master/pkg/tlsutil"
    click LOG "https://github.com/kdudkov/goatak/tree/master/pkg/log"
    click ST "https://github.com/kdudkov/goatak/tree/master/cmd/goatak_server/templates"
    click SA "https://github.com/kdudkov/goatak/tree/master/staticfiles"
    click WCT "https://github.com/kdudkov/goatak/tree/master/cmd/webclient/templates"
    click DF "https://github.com/kdudkov/goatak/tree/master/Dockerfile"
    click MF "https://github.com/kdudkov/goatak/tree/master/Makefile"
    click GH "https://github.com/kdudkov/goatak/tree/master/.github/workflows"

    %% Styles
    classDef backend fill:#f9e79f,stroke:#b7950b,stroke-width:2px;
    classDef client fill:#d5f5e3,stroke:#1d8348,stroke-width:2px;
    classDef database fill:#aed6f1,stroke:#2471a3,stroke-width:2px;
    classDef messaging fill:#fadbd8,stroke:#de4c4a,stroke-width:2px;
    classDef security fill:#ffe6e6,stroke:#ff0000,stroke-width:2px;
    classDef core fill:#d6eaf8,stroke:#1b4f72,stroke-width:2px;
    classDef assets fill:#f6ddcc,stroke:#b9770e,stroke-width:2px;
    classDef tools fill:#d7bde2,stroke:#8e44ad,stroke-width:2px;
    classDef ci fill:#f9e79f,stroke:#a569bd,stroke-width:2px;
```
