# guoflight/openfly architecture

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

- Interactive diagram: https://gitdiagram.com/guoflight/openfly
- Repository: https://github.com/guoflight/openfly

## Overview

##### Project Type and Purpose
- Project Type: A backend service (with potential front-end collaboration, as invited) that exposes HTTP APIs to manage nginx configurations.
- Purpose: openfly manages nginx’s Layer 4 proxy settings (load balancing, health checks, etc.) by dynamically generating configuration files stored in etcd. It uses a RESTful API to receive configuration commands (with JWT authentication) and interacts with external systems (nginx and etcd).

##### File Structure
- Top-Level Directories:
- api: Contains the HTTP server entry point (httpServer.go) and versioned API code (v1/handle.go, v1/jwt.go, etc.). This is your API layer.
- common: Consolidates shared functionalities (e.g., etcd interactions, data structures, nginx logic) so that key operations (like generating nginx configuration snippets) are centralized.
- conf: Houses configuration and constant definitions used throughout the service.
- logger: Provides logging facilities.
- flag, utils: Utility functions and command-line parsing that support the main logic.
- cicd: Contains deployment and build scripts used to build and deploy openfly.
- docs: Versioned documentation (including API specs) that can be referenced for integration.
- main.go: The application entry point that assembles these components.
- Architectural Patterns:
- A clean layering approach where the HTTP API routes (managed in the api package) delegate core operations to modules in common and conf.
- Reuse of common libraries (for etcd operations and nginx configuration generation) that abstract interactions with external systems.

## Diagram (Mermaid)

```mermaid
graph TD
    A["Client/Admin"]:::client

    subgraph "API Layer"
        B1["HTTP API (api/httpServer.go)"]:::api
        B2["API v1 Endpoints (api/v1)"]:::api
        C["JWT Verification (api/v1/jwt.go)"]:::api
    end

    subgraph "Business Logic Layer"
        D["Common Services (common)"]:::logic
        E["Configuration & Constants (conf)"]:::logic
        F["Logging (logger)"]:::logic
        G["Command-line Parsing (flag/flag.go)"]:::utility
        H["Utility Functions (utils/utils.go)"]:::utility
    end

    subgraph "External Systems"
        I["Etcd Storage"]:::external
        J["NGINX Server"]:::external
    end

    subgraph "CI/CD Pipeline"
        K["CI/CD Pipeline (cicd)"]:::cicd
    end

    A -->|"REST_Call"| B1
    B1 -->|"calls"| C
    C -->|"routes_to"| B2
    B2 -->|"triggers"| D
    D -->|"uses"| E
    D -->|"logs_with"| F
    D -->|"parsing_by"| G
    D -->|"utility"| H
    D -->|"stores_in"| I
    D -->|"generates_for"| J
    K -->|"deploys"| B1
    K -->|"deploys"| D

    classDef client fill:#ffdd99,stroke:#333,stroke-width:2px
    classDef api fill:#cce5ff,stroke:#333,stroke-width:2px
    classDef logic fill:#d4edda,stroke:#333,stroke-width:2px
    classDef utility fill:#fff2cc,stroke:#333,stroke-width:2px
    classDef external fill:#f8d7da,stroke:#333,stroke-width:2px
    classDef cicd fill:#d1ecf1,stroke:#333,stroke-width:2px

    click B1 "https://github.com/guoflight/openfly/blob/main/api/httpServer.go"
    click B2 "https://github.com/guoflight/openfly/tree/main/api/v1/"
    click C "https://github.com/guoflight/openfly/blob/main/api/v1/jwt.go"
    click D "https://github.com/guoflight/openfly/tree/main/common/"
    click E "https://github.com/guoflight/openfly/tree/main/conf/"
    click F "https://github.com/guoflight/openfly/blob/main/logger/log.go"
    click G "https://github.com/guoflight/openfly/blob/main/flag/flag.go"
    click H "https://github.com/guoflight/openfly/blob/main/utils/utils.go"
    click K "https://github.com/guoflight/openfly/tree/main/cicd/"
```
