# tx7do/kratos-cms architecture

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

- Interactive diagram: https://gitdiagram.com/tx7do/kratos-cms
- Repository: https://github.com/tx7do/kratos-cms

## Overview

##### Project type and purpose
- This is a full-stack blog/CMS system called “Kratos-Blog.”
- Backend is written in Go, using the Kratos microservice framework, Bazel for builds, Docker for containerization.
- Frontend is a Vue-3 + TypeScript SPA (“admin” panel). There is also a visitor-facing frontend (not shown here).

##### High-level file-structure analysis
- Top-level:
- backend/ – Go microservices and shared code
- frontend/admin/ – Vue3 SPA for administrators
- Docker, CI/CD, and Bazel config files in root and .github/
- backend/app/ has three sub-services under app/:
- admin/service – Admin API service
- core/service  – Core blog logic (posts, categories, ent ORM, DB access)
- front/service – Public (“view”) API service
- backend/api/protos & backend/api/gen – Protobuf definitions and generated Go stubs for gRPC + HTTP gateway
- backend/pkg – Shared utilities (cache, middleware, util packages)
- frontend/admin/src – Vue app split into modules: api (HTTP clients), store, router, components, views

##### Key insights from README
- The system provides CRUD for posts, comments, categories, tags, attachments, pages, subscriptions, etc.
- Backend services communicate via gRPC (with HTTP gateway for REST) and use registry/tracing/config from go-kratos.
- Frontend admin communicates over HTTP to the Admin service.

##### Main components
a. External actors:
- Admin user (browser)
- Public visitor (browser or RSS client)
b. Entry points / API layer:
- Frontend Admin SPA (served by web server or CDN)
- Admin API Gateway (HTTP → gRPC) – implemented in admin/service
- Public API Gateway (HTTP → gRPC) – implemented in front/service
c. Microservices mesh:
- admin/service
- core/service
- front/service
- (optionally comment, file, user domain services if separated, though in this project they’re packaged as modules under core or admin)
d. Shared infrastructure:
- Service Registry (Consul/Eureka/Zookeeper as configured)
- Configuration Service (remote.yaml in configs)
- Tracing/Logging backends (Jaeger, Prometheus)
e. Data stores:
- Relational DB (MySQL/PostgreSQL) – used by core/service via ent ORM
- Object Storage (MinIO or OSS) – for attachments/files
- Cache (Redis) – for tokens, sessions
f. CI/CD & Deployment:
- Docker images (frontend, each service)
- Bazel build pipelines (BUILD.bazel in each service, .github workflows)

##### Relationships & data-flow
- Admin SPA → HTTP (Axios) → admin/service (REST endpoint)
- admin/service → gRPC → core/service, comment module, file module, user module
- front/service mirrors admin flows for public endpoints
- core/service → MySQL + MinIO + Redis
- All services ↔ Service Registry & Config Service
- CI/CD pipeline builds Docker images & deploys to cluster

##### Architectural patterns / design principles
- Microservices (each bounded context as a separate service)
- API gateway pattern (HTTP → gRPC translation)
- Domain-driven modules (admin, core, front, file, comment, user)
- Code-generation from Protobuf for gRPC + REST
- Ent ORM for type-safe data access
- Centralized config, registry, tracing

##### Technologies / frameworks
- Go, go-kratos, Bazel, Docker
- gRPC, HTTP gateway, Protobuf, buf
- Ent ORM
- MySQL, MinIO, Redis, Prometheus, Jaeger
- Vue3, TypeScript, Vite, Axios, Pinia/Vuex, Vue-Router

## Diagram (Mermaid)

```mermaid
flowchart TD
    subgraph "Clients"
        AdminBrowser["Admin Browser"]:::clients
        PublicBrowser["Public Browser / RSS"]:::clients
    end

    subgraph "API Layer"
        StaticHost["Static File Server / CDN"]:::infra
        AdminAPI["Admin API Gateway (HTTP→gRPC)"]:::services
        FrontAPI["Public API Gateway (HTTP→gRPC)"]:::services
    end

    subgraph "Microservices"
        CoreService["Core Service (gRPC)"]:::services
    end

    subgraph "Code & Config"
        SharedUtil["Shared Utilities / pkg"]:::pkg
        Protos["Protobuf Definitions"]:::pkg
        Gen["Generated gRPC & HTTP Gateway Code"]:::pkg
        DockerCfg["Docker & Compose"]:::infra
        BazelCfg["Bazel Build Config"]:::infra
        CICD["CI/CD & Scripts"]:::infra
    end

    subgraph "Infrastructure"
        Registry["Service Registry (Consul/Eureka)"]:::infra
        ConfigSvc["Config Service"]:::infra
        Tracing["Tracing / Metrics (Jaeger, Prometheus)"]:::infra
        Redis["Cache (Redis)"]:::datastore
        MySQL["Relational DB (MySQL/PostgreSQL)"]:::datastore
        MinIO["Object Storage (MinIO)"]:::datastore
    end

    %% Connections - Clients to API Layer
    AdminBrowser -->|"Fetch SPA"| StaticHost
    StaticHost -->|"HTTP (Axios)"| AdminAPI
    AdminBrowser -->|"HTTP (Axios)"| AdminAPI
    PublicBrowser -->|"HTTP / RSS"| FrontAPI

    %% API Layer to Microservices
    AdminAPI -->|"gRPC"| CoreService
    FrontAPI -->|"gRPC"| CoreService

    %% Microservices to Infra
    CoreService --> MySQL
    CoreService --> MinIO
    CoreService --> Redis

    AdminAPI --> Registry
    FrontAPI --> Registry
    CoreService --> Registry

    AdminAPI --> ConfigSvc
    FrontAPI --> ConfigSvc
    CoreService --> ConfigSvc

    AdminAPI --> Tracing
    FrontAPI --> Tracing
    CoreService --> Tracing

    %% Code & Config Relationships
    Protos --> Gen
    SharedUtil --> AdminAPI
    SharedUtil --> FrontAPI
    SharedUtil --> CoreService

    DockerCfg --> AdminAPI
    DockerCfg --> FrontAPI
    DockerCfg --> CoreService

    BazelCfg --> AdminAPI
    BazelCfg --> FrontAPI
    BazelCfg --> CoreService

    CICD --> BazelCfg

    %% Click Events
    click StaticHost "https://github.com/tx7do/kratos-cms/tree/main/frontend/admin/"
    click AdminAPI "https://github.com/tx7do/kratos-cms/blob/main/backend/app/admin/service/cmd/server/main.go"
    click AdminREST "https://github.com/tx7do/kratos-cms/blob/main/backend/app/admin/service/internal/server/rest.go"
    click AdminLogic "https://github.com/tx7do/kratos-cms/tree/main/backend/app/admin/service/internal/service/"
    click AdminConfigs "https://github.com/tx7do/kratos-cms/tree/main/backend/app/admin/service/configs/"
    click FrontAPI "https://github.com/tx7do/kratos-cms/blob/main/backend/app/front/service/cmd/server/main.go"
    click FrontREST "https://github.com/tx7do/kratos-cms/blob/main/backend/app/front/service/internal/server/rest.go"
    click FrontLogic "https://github.com/tx7do/kratos-cms/tree/main/backend/app/front/service/internal/service/"
    click FrontConfigs "https://github.com/tx7do/kratos-cms/tree/main/backend/app/front/service/configs/"
    click CoreService "https://github.com/tx7do/kratos-cms/blob/main/backend/app/core/service/cmd/server/main.go"
    click CoreGRPC "https://github.com/tx7do/kratos-cms/blob/main/backend/app/core/service/internal/server/grpc.go"
    click CoreLogic "https://github.com/tx7do/kratos-cms/tree/main/backend/app/core/service/internal/service/"
    click CoreDataEnt "https://github.com/tx7do/kratos-cms/tree/main/backend/app/core/service/internal/data/ent/"
    click CoreDataAdapter "https://github.com/tx7do/kratos-cms/tree/main/backend/app/core/service/internal/data/"
    click CoreConfigs "https://github.com/tx7do/kratos-cms/tree/main/backend/app/core/service/configs/"
    click SharedUtil "https://github.com/tx7do/kratos-cms/tree/main/backend/pkg/"
    click Protos "https://github.com/tx7do/kratos-cms/tree/main/backend/api/protos/"
    click Gen "https://github.com/tx7do/kratos-cms/tree/main/backend/api/gen/go/"
    click DockerCfg "https://github.com/tx7do/kratos-cms/tree/main/backend/.docker/"
    click BazelCfg "https://github.com/tx7do/kratos-cms/blob/main/backend/BUILD.bazel"
    click CICD "https://github.com/tx7do/kratos-cms/blob/main/.github/workflows/go.yml"

    %% Styles
    classDef clients fill:#cccccc,stroke:#333,stroke-width:1px
    classDef services fill:#ADD8E6,stroke:#333,stroke-width:1px
    classDef pkg fill:#FFB6C1,stroke:#333,stroke-width:1px
    classDef infra fill:#FFD700,stroke:#333,stroke-width:1px
    classDef datastore fill:#90EE90,stroke:#333,stroke-width:1px
```
