# seriawei/zkeacms architecture

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

- Interactive diagram: https://gitdiagram.com/seriawei/zkeacms
- Repository: https://github.com/seriawei/zkeacms

## Overview

##### Main Components
- Web Host Layer: At the front, the “ZKEACMS.WebHost” project is the entry point. It functions as the MVC presentation layer (controllers, views, assets, CSS/JavaScript) and handles user requests. It also contains the Dockerfile and deployment scripts.
- CMS Core/Framework: The “ZKEACMS” directory and the “EasyFrameWork” repository provide the core libraries. This part includes core CMS services such as routing, authentication, context management, dependency injection, layout rendering, and the integration of plugins.
- Plugin and Modules Ecosystem: There are multiple modules (e.g., ZKEACMS.Article, ZKEACMS.Product, ZKEACMS.EventAction, ZKEACMS.FormGenerator, etc.) that extend the CMS functionality. They typically implement widget functionality, domain-specific services, and event handling. Also, plugins under tools and the “zkea.plugin” markers indicate that a plugin-based architecture is used.
- Widget, Layout, and Theme System: The system emphasizes WYSIWYG page design, layout design (leveraging the Bootstrap grid), theme customization (LESS-based themes included in ZKEACMS.Theme and various widget view folders) and a widget engine (widget base classes and widget activators in the “Widget” and “WidgetTemplate” folders).
- API Layer: There is an “Api” folder (and ApiControllers within ZKEACMS.Api and the web host) that likely exposes REST API endpoints for content management.
- Data Layer: The “Database” directory (with multiple database types and migration scripts) and the use of Entity Framework (see CMSDbContext, EasyDbContext, etc.) show that the data layer is abstracted; it provides persistence and supports multiple SQL providers.
- Infrastructure & Utilities: Additional components include caching mechanisms, logging, encryption services, notification handlers, and even a rule engine (found in ZKEACMS.RuleEngine) that provide support functions across the system.
- Build, Publish, and Deployment: Scripts like Build.cmd/sh, Publish.cmd/sh, and Docker-related files indicate dedicated build and deployment support.

##### Out the Relationships and Data Flow
- Present front-end requests flowing into the WebHost layer – these requests hit MVC Controllers and API endpoints.
- WebHost interacts with the CMS Core layer, which in turn calls into various services: the routing provider, authentication/authorization (possibly via JWT in the API), caching, event handling, etc.
- The core and module services invoke business logic in the plugin modules. They further interact with the data layer (the EF-based repositories/DbContext) to store and retrieve persistent content.
- The widget, layout, and theme components collaborate – the layout engine pulls grid and template information while widget services supply renderable content.
- Administration, publishing (via the ZKEACMS.Publisher NuGet tool), and API integrations form an external boundary for deploying content to production.
- Development tools (such as PluginTemplate and LanguageScriptGen under the tools/ folder) support extensibility and operational tooling for customizations.

##### Architectural Patterns & Design Principles
- Modularity and Plugin Architecture: Each module is self-contained (with its own controllers, models, views, and even event handlers) and is discovered/activated at runtime.
- MVC Pattern: The separation between controllers, models, and views is evident in the WebHost layer. This separation supports both administrative UI and front-end rendering.
- Repository / Unit-of-Work Pattern: The structure of the “DbContext” files and “EntityFrameWorkModelCreating” classes shows a clear separation of data access concerns.
- Dependency Injection & IoC: The use of “ServiceCollectionExtend.cs” and clear provider classes illustrates that components are wired using DI best practices.
- Event-Driven Architecture: Several “EventHandler” directories indicate that events (such as cache removals on page changes) are used to decouple components.
- Multi-Database & Cross-Platform Support: Script files under the Database folder support different SQL providers, and Docker scripts underline containerized deployment.

##### Relevant Technologies
- .NET 8 & C#
- ASP.NET Core MVC for the WebHost
- Entity Framework for data access with providers for MSSQL, MySQL, and SQLite
- Bootstrap and LESS for responsive layout and theming
- GitHub Actions workflows for CI/CD
- Docker for containerized deployment
- NuGet packaging and command-line publisher tool

- Be very detailed: capture not only the high-level layers but also sub-components like API endpoints, event handlers, and even the build/deployment pipeline.
- External dependencies explicitly (databases, external publishing tools, Docker, and cloud deployment).

## Diagram (Mermaid)

```mermaid
flowchart TD
    %% External Client
    Client("Client Browser (HTTP)"):::presentation

    %% Presentation Layer
    subgraph "Presentation Layer"
        WebHost("ZKEACMS.WebHost (MVC, Assets, Docker)"):::presentation
    end

    %% CMS Core / Framework Layer
    subgraph "CMS Core / Framework"
        CoreEF("EasyFrameWork (Core Library)"):::core
        ZKCore("ZKEACMS Core (CMS Services, DI, Routing)"):::core
    end

    %% Modules & Plugins
    subgraph "Modules & Plugins"
        Article("ZKEACMS.Article"):::module
        Product("ZKEACMS.Product"):::module
        EventAction("ZKEACMS.EventAction"):::module
        FormGenerator("ZKEACMS.FormGenerator"):::module
    end

    %% Widget, Layout & Theme System
    subgraph "Widget, Layout & Theme System"
        WidgetEngine("Widget Engine"):::widget
        WidgetTemplate("Widget Template"):::widget
        Themes("Themes & Layouts"):::widget
    end

    %% API Layer
    subgraph "API Layer"
        API("API (ZKEACMS.Api)"):::api
        APIControllers("API Controllers"):::api
    end

    %% Data Layer
    subgraph "Data Layer"
        Database("Database Scripts/Migrations"):::data
        EasyContext("EasyDbContext"):::data
        CMSContext("CMSDbContext"):::data
    end

    %% Infrastructure & Utilities
    subgraph "Infrastructure & Utilities"
        Infra("Infrastructure Services (Cache, Logging, IoC)"):::infra
    end

    %% Build, Publish & Deployment
    subgraph "Build, Publish & Deployment"
        BuildScripts("Build & Publish Scripts"):::build
        Docker("Docker Deployment"):::build
    end

    %% Relationships

    %% Client to Presentation
    Client -->|"HTTP_Request"| WebHost

    %% Presentation to CMS Core
    WebHost -->|"Controller_Action"| ZKCore
    WebHost -->|"API_Call"| API

    %% CMS Core Internal Communication
    CoreEF -->|"Service_Provision"| ZKCore

    %% CMS Core to Modules (Plugin Discovery)
    ZKCore -->|"Plugin_Discovery"| Article
    ZKCore -->|"Plugin_Discovery"| Product
    ZKCore -->|"Plugin_Discovery"| EventAction
    ZKCore -->|"Plugin_Discovery"| FormGenerator

    %% Modules event notification back to CMS Core
    Article -->|"Event_Notify"| ZKCore
    Product -->|"Event_Notify"| ZKCore
    EventAction -->|"Event_Notify"| ZKCore
    FormGenerator -->|"Event_Notify"| ZKCore

    %% CMS Core to Data Layer
    ZKCore -->|"Data_Query"| Database
    ZKCore -->|"Repository"| EasyContext
    ZKCore -->|"Repository"| CMSContext

    %% API Layer interactions
    API -->|"APICall_Core"| ZKCore
    APIControllers -->|"APICall_Core"| ZKCore
    APIControllers -->|"Data_Query"| CMSContext

    %% Widget & Layout interactions
    ZKCore -->|"Layout_Rendering"| WidgetEngine
    WidgetEngine -->|"Template_Service"| WidgetTemplate
    WidgetTemplate -->|"Style_Provider"| Themes

    %% Infrastructure usage
    ZKCore -->|"Utilize_Infrastructure"| Infra

    %% Build & Deployment interactions
    BuildScripts -->|"Build/Publish"| WebHost
    BuildScripts -->|"Build/Publish"| ZKCore
    Docker -->|"Container_Deploy"| WebHost

    %% Client API Requests direct to API Layer
    Client -->|"API_Request"| API

    %% Data Layer interactions from CMS Core (additional)
    ZKCore -->|"Repository_Pattern"| EasyContext
    ZKCore -->|"Repository_Pattern"| CMSContext

    %% Click Events
    click WebHost "https://github.com/seriawei/zkeacms/blob/master/src/ZKEACMS.WebHost"
    click CoreEF "https://github.com/seriawei/zkeacms/tree/master/src/EasyFrameWork"
    click ZKCore "https://github.com/seriawei/zkeacms/tree/master/src/ZKEACMS"
    click Article "https://github.com/seriawei/zkeacms/blob/master/src/ZKEACMS.Article"
    click Product "https://github.com/seriawei/zkeacms/blob/master/src/ZKEACMS.Product"
    click EventAction "https://github.com/seriawei/zkeacms/blob/master/src/ZKEACMS.EventAction"
    click FormGenerator "https://github.com/seriawei/zkeacms/blob/master/src/ZKEACMS.FormGenerator"
    click WidgetEngine "https://github.com/seriawei/zkeacms/blob/master/src/ZKEACMS.Widget"
    click WidgetTemplate "https://github.com/seriawei/zkeacms/blob/master/src/ZKEACMS.WidgetTemplate"
    click Themes "https://github.com/seriawei/zkeacms/tree/master/src/ZKEACMS.WebHost/wwwroot/themes"
    click API "https://github.com/seriawei/zkeacms/tree/master/src/ZKEACMS/Api"
    click APIControllers "https://github.com/seriawei/zkeacms/tree/master/src/ZKEACMS/ApiControllers"
    click EasyContext "https://github.com/seriawei/zkeacms/blob/master/src/EasyFrameWork/EasyDbContext.cs"
    click CMSContext "https://github.com/seriawei/zkeacms/blob/master/src/ZKEACMS/CMSDbContext.cs"
    click Database "https://github.com/seriawei/zkeacms/tree/master/Database"
    click Infra "https://github.com/seriawei/zkeacms/tree/master/src/EasyFrameWork"
    click Docker "https://github.com/seriawei/zkeacms/tree/master/src/ZKEACMS.WebHost/Dockerfile"

    %% Class Styles
    classDef presentation fill:#f9e79f,stroke:#b9770e,stroke-width:2px;
    classDef core fill:#aed6f1,stroke:#2471a3,stroke-width:2px;
    classDef module fill:#d2b4de,stroke:#7d3c98,stroke-width:2px;
    classDef widget fill:#fcf3cf,stroke:#b7950b,stroke-width:2px;
    classDef api fill:#fadbd8,stroke:#c0392b,stroke-width:2px;
    classDef data fill:#d5f5e3,stroke:#28b463,stroke-width:2px;
    classDef infra fill:#f5cba7,stroke:#d35400,stroke-width:2px;
    classDef build fill:#d6eaf8,stroke:#2874a6,stroke-width:2px;
```
