# maxence-charriere/go-app architecture

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

- Interactive diagram: https://gitdiagram.com/maxence-charriere/go-app
- Repository: https://github.com/maxence-charriere/go-app

## Overview

##### Project Components
- Library Core (pkg/app):
– Contains the main engine, component definitions, event handling, state management, HTML generation, and HTTP support.
– Holds modules for actions, attributes, cache, context, notifications, routing, etc.
- UI Layer (pkg/ui):
- Auxiliary Services:
– Cache (pkg/cache): Implements caching strategies (LRU, expirations).
– CLI (pkg/cli): Provides command-line interfaces and commands for the framework.
– Errors (pkg/errors) and Logs (pkg/logs): Responsible for error management and logging respectively.
– Analytics (pkg/analytics): Integrates analytics information (e.g., Google Analytics) into the app.
- Documentation and Developer Resources (docs):
– Complete docs including architectural overviews, component guides, and integration instructions.
– Source files (docs/src) and generated web resources (docs/web) for the documentation site.
- WebAssembly (Wasm) Integration:
– Files for generating and handling Wasm (e.g., pkg/app/wasm.go, pkg/app/wasmexec.go, docs/web/app.wasm) which allow apps built with go-app to run in browsers.
- HTTP Server Integration:
– Demonstrated in the README “Standard HTTP” sample, showing how the library integrates with the net/http package.

##### Relationships and Interactions
- The User Code (application components written by developers using go-app) calls the declarative API provided by pkg/app.
- The UI components (defined in pkg/app and supported by pkg/ui) are rendered as HTML/CSS/JS – this rendering mechanism is connected to autogenerated resources (see pkg/app/gen for scripts and styling).
- The library integrates with the HTTP server model:
– Developers set up routing (app.Route) to point to their components.
– An HTTP handler (app.Handler) is available for integration with the Go net/http package.
- WebAssembly acts as a bridge to enable Go code to run in the browser and manage client-side interactions.
- Internal modules (cache, errors, logs, analytics) function as supporting services for performance, debugging, and additional integrations.

##### Architectural Patterns/Design Principles
- Modular design: Each major functionality (UI rendering, caching, CLI, logging) is isolated in its own package.
- Declarative UI: The library leverages a declarative syntax to compose UI elements solely in Go.
- Integration with existing standards: Uses Go’s http package for server-side routing and WebAssembly for client-side execution.
- Separation of concerns: Distinct responsibilities are assigned to packages—UI layout (pkg/app, pkg/ui), state and logic (pkg/app), caching (pkg/cache), etc.

- UI Engine (pkg/app)
- UI Components/Helpers (pkg/ui)
- WebAssembly Bridge (Wasm components & generated files)
- HTTP Integration (Handler, routing via app.Route and net/http)

## Diagram (Mermaid)

```mermaid
flowchart TD
    subgraph "go-app Framework"
        subgraph "Core Components"
            AD["UI Declarative Engine (pkg/app)"]:::core
            UH["UI Helpers (pkg/ui)"]:::core
        end
        subgraph "Integration Layers"
            WASM["WebAssembly Bridge"]:::integration
            subgraph "Wasm Files"
                W1["Wasm File (pkg/app/wasm.go)"]:::integration
                W2["Wasm Exec (pkg/app/wasmexec.go)"]:::integration
                W3["App Wasm (docs/web/app.wasm)"]:::integration
            end
            HTTP["HTTP Integration (pkg/app/http.go)"]:::integration
        end
        subgraph "Supporting Services"
            CACHE["Cache (pkg/cache)"]:::support
            CLI["CLI (pkg/cli)"]:::support
            ERR["Errors (pkg/errors)"]:::support
            LOGS["Logs (pkg/logs)"]:::support
            ANALYTICS["Analytics (pkg/analytics)"]:::support
        end
    end

    APD["Application Developer"]:::developer
    CLIENT["Client (Browser)"]:::integration
    DOC["Documentation (docs)"]:::docs

    APD -->|"calls"| AD
    AD -->|"uses"| UH
    AD -->|"routes"| HTTP
    AD -->|"rendersWith"| WASM
    AD -.->|"supports"| CACHE
    AD -.->|"supports"| CLI
    AD -.->|"supports"| ERR
    AD -.->|"supports"| LOGS
    AD -.->|"supports"| ANALYTICS
    HTTP -->|"serves"| CLIENT
    WASM -->|"includes"| W1
    WASM -->|"includes"| W2
    WASM -->|"includes"| W3
    APD -->|"refersTo"| DOC

    click AD "https://github.com/maxence-charriere/go-app/tree/master/pkg/app"
    click UH "https://github.com/maxence-charriere/go-app/tree/master/pkg/ui"
    click CACHE "https://github.com/maxence-charriere/go-app/tree/master/pkg/cache"
    click CLI "https://github.com/maxence-charriere/go-app/tree/master/pkg/cli"
    click ERR "https://github.com/maxence-charriere/go-app/tree/master/pkg/errors"
    click LOGS "https://github.com/maxence-charriere/go-app/tree/master/pkg/logs"
    click ANALYTICS "https://github.com/maxence-charriere/go-app/tree/master/pkg/analytics"
    click DOC "https://github.com/maxence-charriere/go-app/tree/master/docs"
    click W1 "https://github.com/maxence-charriere/go-app/blob/master/pkg/app/wasm.go"
    click W2 "https://github.com/maxence-charriere/go-app/blob/master/pkg/app/wasmexec.go"
    click W3 "https://github.com/maxence-charriere/go-app/blob/master/docs/web/app.wasm"
    click HTTP "https://github.com/maxence-charriere/go-app/blob/master/pkg/app/http.go"

    classDef core fill:#add8e6,stroke:#000,stroke-width:1px;
    classDef support fill:#c8e6c9,stroke:#000,stroke-width:1px,rx:5,ry:5;
    classDef integration fill:#ffcc80,stroke:#000,stroke-width:1px;
    classDef docs fill:#e0e0e0,stroke:#000,stroke-width:1px;
    classDef developer fill:#fff59d,stroke:#000,stroke-width:1px;
```
