# suyuan32/simple-admin-core architecture

> Architecture diagram of the GitHub repository suyuan32/simple-admin-core, 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/suyuan32/simple-admin-core
- Repository: https://github.com/suyuan32/simple-admin-core

## Overview

##### Main Components
- API Service:
– Located in the “api” directory, it includes a “core.go” entry point, a collection of API descriptions, configuration files (e.g., “core.yaml”), and a well-defined layered structure comprising the “internal/handler” (controller layer) and “internal/logic” (business logic layer).
– Also includes middleware (e.g., authority_middleware) and internationalization (i18n) support.
- RPC Service:
– Found under the “rpc” directory. It contains similar layered subdirectories (logic, internal/server, internal/svc) that expose functionalities through protocol buffers (e.g., “core.proto”, “api.proto”, etc.).
– The RPC service leverages Ent for database operations as seen in the “rpc/ent” directory.
- Database:
– The project deploys databases (MySQL, PostgreSQL, MongoDB in some deploy directories) using containers and Kubernetes configurations.
– Database schema management is handled via Ent (schema definitions in “rpc/ent/schema” and similar files in “api/etc”).
- External Integrations & Tools:
– Casbin for RBAC and permission control
– Code generation utilities are integrated to produce consistent CRUD APIs across different modules.
– Docker and Kubernetes artifacts (docker-compose files in “deploy” and Kubernetes YAMLs in “deploy/k8s”) indicate containerized deployments with service discovery among the modules.
- Service Deployment and Monitoring:
– Several Dockerfiles (Dockerfile-api and Dockerfile-rpc) and deployment configurations are included, suggesting separate containerized services with built-in logging, tracing (jaeger deployment), and monitoring (Prometheus integration).

##### Relationships and Interactions
- The business logic layers in both API and RPC services communicate with the underlying Ent-based database layer.
- On the RPC side, show the use of protocol buffers and the connection to external systems or services (if, for example, a microservices architecture is used to decouple parts of the system).
- Deployment orchestration components to show that Docker Compose and Kubernetes are used to manage containers and service discovery.

##### Architectural Patterns and Design Principles
- Layered Architecture: Clearly reflect multiple layers – for API: routes → handlers → logic → data access; for RPC: similar breakdown with gRPC endpoints elaborated.
- Separation of Concerns: API endpoints and RPC calls each have their own packages (handlers, logic, internal service context) to enforce modularity.
- Microservice/Service-Oriented Approach: The clear separation of API and RPC into different Docker containers (as indicated by separate Dockerfiles and deployment directories) suggests loosely-coupled services.
- Use of modern frameworks (Go-Zero, Casbin) which themselves dictate patterns such as dependency injection and centralized error-handling.

## Diagram (Mermaid)

```mermaid
flowchart TD 
    %% External Client
    UI["UI/External Client"]:::client

    %% API Service Subgraph
    subgraph "API Service"
        API_Entry["API Entry Point"]:::service
        API_Config["API Config"]:::config
        API_Middleware["Authority Middleware"]:::middleware
        API_Handler["API Handlers"]:::handler
        API_Logic["API Business Logic"]:::logic
    end

    %% RPC Service Subgraph
    subgraph "RPC Service"
        RPC_Entry["RPC Entry Point"]:::service
        RPC_Proto["RPC Proto Definitions"]:::proto
        RPC_Logic["RPC Business Logic"]:::logic
        RPC_Server["RPC Server & SVC"]:::service
        RPC_Ent["RPC Ent ORM"]:::orm
    end

    %% Database Component
    DB(("Database (Ent ORM)")):::db

    %% External Integration (Casbin)
    Casbin["Casbin (Access Control)"]:::middleware

    %% Deployment & Monitoring Subgraph
    subgraph "Deployment & Monitoring"
        DockerAPI["Dockerfile-api"]:::deployment
        DockerRPC["Dockerfile-rpc"]:::deployment
        DeployCluster["Deploy (docker-compose & k8s)"]:::deployment
    end

    %% Connections for API Service Flow
    UI -->|"HTTP_Request"| API_Entry
    API_Entry --> API_Config
    API_Config --> API_Middleware
    API_Middleware --> API_Handler
    API_Handler --> API_Logic
    API_Logic -->|"DB_Query"| DB
    API_Middleware -->|"Uses"| Casbin

    %% Connections for RPC Service Flow
    UI -->|"gRPC_Request"| RPC_Entry
    RPC_Entry --> RPC_Proto
    RPC_Proto --> RPC_Logic
    RPC_Logic --> RPC_Server
    RPC_Server --> RPC_Ent
    RPC_Ent -->|"ORM_Operations"| DB

    %% Deployment Container Associations
    DockerAPI --- API_Entry
    DockerRPC --- RPC_Entry
    DeployCluster --- DockerAPI
    DeployCluster --- DockerRPC

    %% Styling Classes Definition
    classDef client fill:#ffd700,stroke:#b8860b,stroke-width:2px;
    classDef service fill:#add8e6,stroke:#00008b,stroke-width:2px;
    classDef config fill:#e6e6fa,stroke:#483d8b,stroke-width:2px;
    classDef middleware fill:#ffa07a,stroke:#cd5c5c,stroke-width:2px;
    classDef handler fill:#98fb98,stroke:#2e8b57,stroke-width:2px;
    classDef logic fill:#f0e68c,stroke:#bdb76b,stroke-width:2px;
    classDef proto fill:#d8bfd8,stroke:#9932cc,stroke-width:2px;
    classDef orm fill:#ffdab9,stroke:#cd853f,stroke-width:2px;
    classDef db fill:#ffdead,stroke:#8b4513,stroke-width:2px;
    classDef deployment fill:#87cefa,stroke:#4682b4,stroke-width:2px;

    %% Click Events for API Service Components
    click API_Entry "https://github.com/suyuan32/simple-admin-core/blob/main/api/core.go"
    click API_Config "https://github.com/suyuan32/simple-admin-core/blob/main/api/etc/core.yaml"
    click API_Handler "https://github.com/suyuan32/simple-admin-core/tree/main/api/internal/handler"
    click API_Logic "https://github.com/suyuan32/simple-admin-core/tree/main/api/internal/logic"
    click API_Middleware "https://github.com/suyuan32/simple-admin-core/blob/main/api/internal/middleware/authority_middleware.go"

    %% Click Events for RPC Service Components
    click RPC_Entry "https://github.com/suyuan32/simple-admin-core/blob/main/rpc/core.go"
    click RPC_Proto "https://github.com/suyuan32/simple-admin-core/blob/main/rpc/core.proto"
    click RPC_Logic "https://github.com/suyuan32/simple-admin-core/tree/main/rpc/internal/logic"
    click RPC_Server "https://github.com/suyuan32/simple-admin-core/tree/main/rpc/internal/svc"
    click RPC_Ent "https://github.com/suyuan32/simple-admin-core/tree/main/rpc/ent"

    %% Click Event for Database Schema
    click DB "https://github.com/suyuan32/simple-admin-core/tree/main/rpc/ent/schema"

    %% Click Events for Deployment Components
    click DockerAPI "https://github.com/suyuan32/simple-admin-core/tree/main/Dockerfile-api"
    click DockerRPC "https://github.com/suyuan32/simple-admin-core/tree/main/Dockerfile-rpc"
    click DeployCluster "https://github.com/suyuan32/simple-admin-core/tree/main/deploy"
```
