# rushteam/beauty architecture

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

- Interactive diagram: https://gitdiagram.com/rushteam/beauty
- Repository: https://github.com/rushteam/beauty

## Overview

##### Project Overview – Identify Major Architectural Blocks
- Core Application: The framework’s central build (starting with beauty.go) and its factory functions (e.g., beauty.New) that wire together various services.
- Service Types: Mark distinct service entries for HTTP servers (web server), gRPC servers (gRPC Server), and Cron jobs.
- Infrastructure Modules: Identify supporting modules such as configuration (pkg/conf), logging (pkg/logger), tracing (pkg/tracing), and unique utilities (pkg/xgo, pkg/uuid, pkg/libs).
- Discovery & Registry: Include registry/discovery components that support etcd (pkg/discover/etcdv3) and nacos (pkg/discover/nacos) integrations.
- Tools and CLI: Represent the CLI tool (tools/cmd/beauty) and supporting parser/template utilities. They are used for creating new projects and scaffolding code.

- Application Entry Point: Start with a “Beauty Application Bootstrap” component. Indicate that it initializes lifecycle hooks and service registrations.
- Service Layer(s): Create separate nodes for each type of service:
- HTTP Server: This node uses an underlying router (e.g., using chi or gin in example usage) and is configured via YAML files.
- gRPC Server: Display a node with API components including the Protocol Buffers generated files (service.pb.go, service_grpc.pb.go, etc.) showing how service definitions are turned into server implementations.
- Cron Services: Include the cron job execution component (pkg/service/cron) with scheduling patterns.
- Supporting Infrastructure:
- Configuration: A node for YAML configuration files (config/config.yaml) and related loaders (pkg/conf/nacos_loader.go).
- Discovery & Registry: Nodes for etcdv3 and nacos-based service discovery modules.
- Tracing & Metrics: A block representing OpenTelemetry/Prometheus integration and the dedicated tracer (pkg/tracing).
- Logging: Represent logging frameworks from pkg/logger.
- Utility and Client Modules: Add components for auxiliary functions such as UUID generation, address handling, and load balancing for gRPC (pkg/client/grpcclient).

##### Relationships and Interactions
- That configuration data flows from YAML files into the configuration modules which in turn influence runtime behavior.
- Demonstrate that the discovery modules (etcd, nacos) interact with the service components to register and discover service endpoints.
- Tracing and logging as cross-cutting concerns that pipe into each service component.
- For the CLI and toolchain, show them feeding into new project creation processes; they generate configurations and scaffolding (e.g., templates in tools/tpls).

##### Architectural Patterns and Technologies
- Microservices Pattern: Emphasize how the framework enables running different service types (HTTP, gRPC, Cron) under a unified process.
- Dependency Injection: Illustrate that initialization options (e.g., beauty.WithWebServer, beauty.WithRegistry) are used to wire dependencies.
- Extensibility: Mark extension points such as lifecycle hooks and differentiation between core functionalities and infrastructure (for example, signal handling and graceful shutdown via pkg/signals).
- Key Technologies and Libraries: Note the use of Go’s native modules (go.mod, go.sum), buf for Protocol Buffers, third-party routers (chi, gin), grpc and grpc-gateway, and OpenTelemetry for metrics/tracing.

## Diagram (Mermaid)

```mermaid
flowchart TD
    subgraph "Application Entry Point"
        BA("Beauty Application Bootstrap"):::entry
    end

    subgraph "Core Application"
        Core("Beauty Application Core"):::core
    end

    subgraph "Service Layers"
        HTTP("HTTP Server Module"):::service
        GRPC("gRPC Server Module"):::service
        Cron("Cron Job Module"):::service
    end

    subgraph "Infrastructure Modules"
        Config("Configuration Loader"):::infra
        DiscoveryEtcd("Service Discovery (etcd)"):::infra
        DiscoveryNacos("Service Discovery (nacos)"):::infra
        Tracing("Tracing & Metrics"):::infra
        Logging("Logging"):::infra
    end

    subgraph "Clients & Utilities"
        GRPCClient("gRPC Client Integration"):::client
        NacosClient("Nacos Client Integration"):::client
        RESTClient("REST Client Integration"):::client
    end

    subgraph "Tools & CLI"
        Tools("CLI Tool & Project Scaffolding"):::tools
    end

    %% Connections from Bootstrap to Core
    BA -->|"initializes"| Core

    %% Core wires to service layers
    Core -->|"WithWebServer"| HTTP
    Core -->|"WithGrpcServer"| GRPC
    Core -->|"WithCrontab"| Cron

    %% Infrastructure Interactions
    Config -->|"loads config for"| HTTP
    Config -->|"loads config for"| GRPC
    Config -->|"loads config for"| Cron

    HTTP -->|"registers with"| DiscoveryEtcd
    HTTP -->|"registers with"| DiscoveryNacos
    GRPC -->|"registers with"| DiscoveryEtcd
    GRPC -->|"registers with"| DiscoveryNacos
    Cron -->|"registers with"| DiscoveryEtcd
    Cron -->|"registers with"| DiscoveryNacos

    HTTP -->|"sends metrics to"| Tracing
    GRPC -->|"sends metrics to"| Tracing
    Cron -->|"sends metrics to"| Tracing

    HTTP -->|"logs to"| Logging
    GRPC -->|"logs to"| Logging
    Cron -->|"logs to"| Logging

    %% Clients interactions (used by Core or services)
    Core -->|"integrates"| GRPCClient
    Core -->|"integrates"| NacosClient
    Core -->|"integrates"| RESTClient

    %% Tools influence the application scaffolding
    Tools -->|"generates scaffolding for"| Core

    %% Click Events for Component Mappings
    click Core "https://github.com/rushteam/beauty/blob/main/beauty.go"
    click Core "https://github.com/rushteam/beauty/blob/main/pkg/core/component.go"
    click HTTP "https://github.com/rushteam/beauty/blob/main/pkg/service/webserver/server.go"
    click GRPC "https://github.com/rushteam/beauty/blob/main/pkg/service/grpcserver/server.go"
    click GRPC "https://github.com/rushteam/beauty/blob/main/example/example/api/v1/service_grpc.pb.go"
    click Cron "https://github.com/rushteam/beauty/tree/main/pkg/service/cron"
    click Config "https://github.com/rushteam/beauty/tree/main/pkg/conf"
    click DiscoveryEtcd "https://github.com/rushteam/beauty/tree/main/pkg/discover/etcdv3"
    click DiscoveryNacos "https://github.com/rushteam/beauty/tree/main/pkg/discover/nacos"
    click Tracing "https://github.com/rushteam/beauty/tree/main/pkg/tracing"
    click Logging "https://github.com/rushteam/beauty/blob/main/pkg/logger/logger.go"
    click GRPCClient "https://github.com/rushteam/beauty/tree/main/pkg/client/grpcclient"
    click NacosClient "https://github.com/rushteam/beauty/tree/main/pkg/client/nacos"
    click RESTClient "https://github.com/rushteam/beauty/blob/main/pkg/client/resty/resty.go"
    click Tools "https://github.com/rushteam/beauty/tree/main/tools/cmd/beauty"
    click Tools "https://github.com/rushteam/beauty/tree/main/tools/tpls"

    %% Class Definitions for Colors and Styles
    classDef entry fill:#FFEE88,stroke:#333,stroke-width:2px;
    classDef core fill:#88FF88,stroke:#333,stroke-width:2px;
    classDef service fill:#8888FF,stroke:#333,stroke-width:2px;
    classDef infra fill:#FF8888,stroke:#333,stroke-width:2px;
    classDef client fill:#88FFFF,stroke:#333,stroke-width:2px;
    classDef tools fill:#FFD488,stroke:#333,stroke-width:2px;
```
