# hexya-erp/hexya architecture

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

- Interactive diagram: https://gitdiagram.com/hexya-erp/hexya
- Repository: https://github.com/hexya-erp/hexya

## Overview

##### Project type and purpose
- Hexya is an open-source ERP and business-application development framework written in Go.
- It exposes both a command-line interface (in cmd/) and a reusable library (in src/) for building modular business applications.

##### File structure
- Top-level:
– cmd/ : CLI entrypoints (generate code, launch server, update DB, i18n, version, project scaffolding)
– main.go, go.mod/go.sum: module definition and root launcher
– doc/: user and developer documentation (install, tutorial, design, contribution)
- src/: framework core divided into:
– actions: declarative actions driving UI and workflows
– controllers: HTTP controllers and test harness
– i18n: locale file handling and translation generators
– menus: menu tree definitions
– models: full-featured type-safe ORM + query builder + security (Postgres backend)
– reports: report generation (text, formats)
– server: HTTP server, routing, module loading, context management
– templates: view rendering engines (Gin, Pongo2)
– views: XML view definitions and inheritance mechanisms
– tests/tools: integration and unit tests; assorted utility libraries
- tools/: CLI helper libraries (config, assets, logging, password, XML and PO file utilities, code generators)

##### Insights from README
- Core features: ORM, views, controllers, modular “iterative definition” (plugins extend models/actions/views in place).
- Architecture: MVC-style with an extension point per component—models, views, methods, menus, controllers.
- Deployment: server.go boots, loads registered modules, wires routes, exposes HTTP API, manages DB schema.

## Diagram (Mermaid)

```mermaid
graph TB
    %% CLI Layer
    subgraph "CLI Layer"
        direction TB
        G1["Generate Command"]:::cli
        G2["Hexya CLI"]:::cli
        G3["i18n Command"]:::cli
        G4["Module Command"]:::cli
        G5["Project Scaffold"]:::cli
        G6["Server Launcher"]:::cli
        G7["DB Updater"]:::cli
        G8["Version"]:::cli
    end

    %% Server Layer
    subgraph "Server Layer"
        direction TB
        S1["Server Bootstrap"]:::server
        S2["Router"]:::server
        S3["Context Manager"]:::server
        S4["Module Loader"]:::server
    end

    %% Framework Core
    subgraph "Framework Core"
        direction TB
        subgraph "Models / ORM"
            M1["db_postgres.go"]:::core
            M2["queries.go"]:::core
            M3["base_model.go"]:::core
        end
        subgraph "Controllers & Actions"
            C1["controllers.go"]:::core
            A1["actions.go"]:::core
        end
        subgraph "Views & Templates"
            V1["views.go"]:::core
            T1["gin.go"]:::core
            T2["pongo2.go"]:::core
            T3["templates.go"]:::core
        end
        subgraph "Reports Engine"
            R1["reports.go"]:::core
            R2["text_report.go"]:::core
        end
        subgraph "Menus Manager"
            U1["menus.go"]:::core
        end
        subgraph "i18n Engine"
            I1["i18n.go"]:::core
            I2["locale.go"]:::core
            I3["translation.go"]:::core
        end
    end

    %% Extension Modules
    subgraph "Extension Modules"
        direction TB
        E1["testmodule"]:::ext
        E2["testllmodule"]:::ext
    end

    %% External Systems
    subgraph "External Systems"
        direction TB
        DB["PostgreSQL"]:::external
        FS["File System (PO/locale files, assets)"]:::external
    end

    %% Flow Connections
    G6 -->|invokes| S1
    S1 --> S4
    S1 --> S2
    S1 --> S3

    S4 --> E1
    S4 --> E2

    %% HTTP Request Flow
    HTTP["HTTP Request"]:::external --> S2
    S2 --> C1
    C1 --> M1
    M1 --> DB
    C1 --> V1
    V1 --> T1
    V1 --> T2
    T1 --> Client["HTTP Response"]:::external
    T2 --> Client

    %% Reports Flow
    C1 --> R1
    R1 --> Client

    %% i18n Initialization
    S1 --> I1
    I1 --> FS

    %% Class Definitions
    classDef cli fill:#ffe4b2,stroke:#cc8400
    classDef server fill:#b2dfff,stroke:#0073cc
    classDef core fill:#d4f2d4,stroke:#339933
    classDef ext fill:#ffe6e6,stroke:#cc0000
    classDef external fill:#f5e6ff,stroke:#8000b3

    %% Click Events CLI
    click G1 "https://github.com/hexya-erp/hexya/blob/master/cmd/generate.go"
    click G2 "https://github.com/hexya-erp/hexya/blob/master/cmd/hexya.go"
    click G3 "https://github.com/hexya-erp/hexya/blob/master/cmd/i18n.go"
    click G4 "https://github.com/hexya-erp/hexya/blob/master/cmd/module.go"
    click G5 "https://github.com/hexya-erp/hexya/blob/master/cmd/project.go"
    click G6 "https://github.com/hexya-erp/hexya/blob/master/cmd/server.go"
    click G7 "https://github.com/hexya-erp/hexya/blob/master/cmd/updatedb.go"
    click G8 "https://github.com/hexya-erp/hexya/blob/master/cmd/version.go"

    %% Click Events Server
    click S1 "https://github.com/hexya-erp/hexya/blob/master/src/server/server.go"
    click S2 "https://github.com/hexya-erp/hexya/blob/master/src/server/routes.go"
    click S3 "https://github.com/hexya-erp/hexya/blob/master/src/server/context.go"
    click S4 "https://github.com/hexya-erp/hexya/blob/master/src/server/modules.go"

    %% Click Events Models
    click M1 "https://github.com/hexya-erp/hexya/blob/master/src/models/db_postgres.go"
    click M2 "https://github.com/hexya-erp/hexya/blob/master/src/models/queries.go"
    click M3 "https://github.com/hexya-erp/hexya/blob/master/src/models/base_model.go"

    %% Click Events Controllers & Actions
    click C1 "https://github.com/hexya-erp/hexya/blob/master/src/controllers/controllers.go"
    click A1 "https://github.com/hexya-erp/hexya/blob/master/src/actions/actions.go"

    %% Click Events Views & Templates
    click V1 "https://github.com/hexya-erp/hexya/blob/master/src/views/views.go"
    click T1 "https://github.com/hexya-erp/hexya/blob/master/src/templates/gin.go"
    click T2 "https://github.com/hexya-erp/hexya/blob/master/src/templates/pongo2.go"
    click T3 "https://github.com/hexya-erp/hexya/blob/master/src/templates/templates.go"

    %% Click Events Reports
    click R1 "https://github.com/hexya-erp/hexya/blob/master/src/reports/reports.go"
    click R2 "https://github.com/hexya-erp/hexya/blob/master/src/reports/text_report.go"

    %% Click Events Menus
    click U1 "https://github.com/hexya-erp/hexya/blob/master/src/menus/menus.go"

    %% Click Events i18n
    click I1 "https://github.com/hexya-erp/hexya/blob/master/src/i18n/i18n.go"
    click I2 "https://github.com/hexya-erp/hexya/blob/master/src/i18n/locale.go"
    click I3 "https://github.com/hexya-erp/hexya/blob/master/src/i18n/translations/translation.go"

    %% Click Events Extension Modules
    click E1 "https://github.com/hexya-erp/hexya/tree/master/src/tests/testmodule/"
    click E2 "https://github.com/hexya-erp/hexya/tree/master/src/tests/testllmodule/"
```
