# maddalax/htmgo architecture

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

- Interactive diagram: https://gitdiagram.com/maddalax/htmgo
- Repository: https://github.com/maddalax/htmgo

## Overview

htmgo is a Go framework and toolchain for building interactive, server-rendered websites with htmx. Its principal workflow is to define pages and partials in Go, register routes, handle requests through the framework, and render HTML responses; the CLI supports project setup and development workflows. Separate branches cover WebSocket interactions, HTML-to-Go conversion, and the project’s own website. Some subsystems are represented from README or source-index references because their implementation excerpts were not provided; edges are limited to documented or visible relationships.

Main entry points: [`framework/h/app.go`](https://github.com/maddalax/htmgo/blob/master/framework/h/app.go) (HTTP App Server), [`cli/htmgo/runner.go`](https://github.com/maddalax/htmgo/blob/master/cli/htmgo/runner.go) (CLI Runner), [`tools/html-to-htmgo/htmltogo/main.go`](https://github.com/maddalax/htmgo/blob/master/tools/html-to-htmgo/htmltogo/main.go) (HTML-to-Go Converter), [`extensions/websocket/internal/wsutil/handler.go`](https://github.com/maddalax/htmgo/blob/master/extensions/websocket/internal/wsutil/handler.go) (WebSocket HTTP Handler)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_framework["Web Framework"]
  node_page_authoring["Go Page and Partial Authoring"]
  node_app_server["HTTP App Server<br/>[app.go]"]
  node_request_lifecycle["Request Lifecycle<br/>[lifecycle.go]"]
  node_hx_support["htmx Support"]
  node_service_locator["Service Locator<br/>[locator.go]"]
  node_rendering["HTML Rendering<br/>[render.go]"]
  node_framework_js["JS Commands<br/>[commands.go]"]
end

subgraph group_cli["CLI Tooling"]
  node_cli_runner["CLI Runner<br/>[runner.go]"]
  node_astgen["Page Registration<br/>[entry.go]"]
  node_template_setup["Template Setup<br/>[main.go]"]
  node_build_tasks["Build and Watch Tasks"]
end

subgraph group_websocket["WebSocket Extension"]
  node_ws_http["WebSocket HTTP Handler<br/>[handler.go]"]
  node_socket_manager["Socket and Room Manager<br/>[manager.go]"]
  node_ws_events["WebSocket Event Handlers<br/>[handler.go]"]
  node_ws_sessions["Socket Sessions<br/>[session.go]"]
end

subgraph group_site["Project Website"]
  node_site_app["Website App<br/>[main.go]"]
  node_site_pages["Website Pages<br/>[index.go]"]
  node_site_layout["Website Layout and Navigation<br/>[navbar.go]"]
  node_site_helpers["Markdown and Site Helpers"]
end

subgraph group_converter["HTML Converter"]
  node_converter_api["HTML-to-Go Converter<br/>[main.go]"]
  node_html_parser["HTML Parser Adapter<br/>[parser.go]"]
  node_html_domain["Parsed Node Model<br/>[node.go]"]
  node_html_formatter["Go Formatter Adapter<br/>[formatter.go]"]
end

node_developer(("Developer"))
node_site_user(("Website Visitor"))
node_browser(("Browser"))
node_html_input["HTML Input"]
node_go_output["Go Markup Output"]

node_developer -->|"runs commands"| node_cli_runner
node_cli_runner -->|"invokes registration"| node_astgen
node_cli_runner -->|"invokes setup"| node_template_setup
node_cli_runner -->|"runs tasks"| node_build_tasks
node_developer -->|"defines pages"| node_page_authoring
node_page_authoring -.->|"registers pages"| node_app_server
node_app_server -.->|"handles requests"| node_request_lifecycle
node_app_server -->|"uses htmx headers"| node_hx_support
node_app_server -->|"provides services"| node_service_locator
node_request_lifecycle -->|"uses htmx helpers"| node_hx_support
node_browser -->|"sends requests"| node_app_server
node_app_server -.->|"renders responses"| node_rendering
node_rendering -.->|"returns HTML"| node_browser
node_framework_js -->|"uses markup API"| node_page_authoring
node_app_server -.->|"serves socket handler"| node_ws_http
node_ws_http -->|"adds and dispatches"| node_socket_manager
node_socket_manager -.->|"emits socket events"| node_ws_events
node_ws_events -->|"reads socket state"| node_socket_manager
node_ws_http -->|"uses sessions"| node_ws_sessions
node_site_user -->|"visits site"| node_site_app
node_site_app -->|"registers services"| node_site_helpers
node_site_pages -.->|"wraps page"| node_site_layout
node_html_input -->|"provides markup"| node_converter_api
node_converter_api -->|"parses input"| node_html_parser
node_html_parser -->|"builds nodes"| node_html_domain
node_converter_api -->|"formats nodes"| node_html_formatter
node_converter_api -->|"returns Go markup"| node_go_output

click node_cli_runner "https://github.com/maddalax/htmgo/blob/master/cli/htmgo/runner.go"
click node_astgen "https://github.com/maddalax/htmgo/blob/master/cli/htmgo/tasks/astgen/entry.go"
click node_template_setup "https://github.com/maddalax/htmgo/blob/master/cli/htmgo/tasks/downloadtemplate/main.go"
click node_build_tasks "https://github.com/maddalax/htmgo/tree/master/cli/htmgo/tasks"
click node_page_authoring "https://github.com/maddalax/htmgo/tree/master/framework/h"
click node_app_server "https://github.com/maddalax/htmgo/blob/master/framework/h/app.go"
click node_request_lifecycle "https://github.com/maddalax/htmgo/blob/master/framework/h/lifecycle.go"
click node_hx_support "https://github.com/maddalax/htmgo/tree/master/framework/hx"
click node_service_locator "https://github.com/maddalax/htmgo/blob/master/framework/service/locator.go"
click node_rendering "https://github.com/maddalax/htmgo/blob/master/framework/h/render.go"
click node_framework_js "https://github.com/maddalax/htmgo/blob/master/framework/js/commands.go"
click node_ws_http "https://github.com/maddalax/htmgo/blob/master/extensions/websocket/internal/wsutil/handler.go"
click node_socket_manager "https://github.com/maddalax/htmgo/blob/master/extensions/websocket/internal/wsutil/manager.go"
click node_ws_events "https://github.com/maddalax/htmgo/blob/master/extensions/websocket/ws/handler.go"
click node_ws_sessions "https://github.com/maddalax/htmgo/blob/master/extensions/websocket/session/session.go"
click node_site_app "https://github.com/maddalax/htmgo/blob/master/htmgo-site/main.go"
click node_site_pages "https://github.com/maddalax/htmgo/blob/master/htmgo-site/pages/index.go"
click node_site_layout "https://github.com/maddalax/htmgo/blob/master/htmgo-site/partials/navbar.go"
click node_site_helpers "https://github.com/maddalax/htmgo/tree/master/htmgo-site/internal"
click node_converter_api "https://github.com/maddalax/htmgo/blob/master/tools/html-to-htmgo/htmltogo/main.go"
click node_html_parser "https://github.com/maddalax/htmgo/blob/master/tools/html-to-htmgo/internal/adapters/services/parser/parser.go"
click node_html_domain "https://github.com/maddalax/htmgo/blob/master/tools/html-to-htmgo/internal/domain/node.go"
click node_html_formatter "https://github.com/maddalax/htmgo/blob/master/tools/html-to-htmgo/internal/adapters/services/formatter/formatter.go"

classDef toneNeutral fill:#f8fafc,stroke:#334155,stroke-width:1.5px,color:#0f172a
classDef toneBlue fill:#dbeafe,stroke:#2563eb,stroke-width:1.5px,color:#172554
classDef toneAmber fill:#fef3c7,stroke:#d97706,stroke-width:1.5px,color:#78350f
classDef toneMint fill:#dcfce7,stroke:#16a34a,stroke-width:1.5px,color:#14532d
classDef toneRose fill:#ffe4e6,stroke:#e11d48,stroke-width:1.5px,color:#881337
classDef toneIndigo fill:#e0e7ff,stroke:#4f46e5,stroke-width:1.5px,color:#312e81
classDef toneTeal fill:#ccfbf1,stroke:#0f766e,stroke-width:1.5px,color:#134e4a
class node_page_authoring,node_app_server,node_request_lifecycle,node_hx_support,node_service_locator,node_rendering,node_framework_js,node_browser toneBlue
class node_cli_runner,node_astgen,node_template_setup,node_build_tasks toneAmber
class node_ws_http,node_socket_manager,node_ws_events,node_ws_sessions toneMint
class node_site_app,node_site_pages,node_site_layout,node_site_helpers toneRose
class node_converter_api,node_html_parser,node_html_domain,node_html_formatter,node_developer,node_site_user,node_html_input,node_go_output toneIndigo
```

## Components

### Web Framework

- [Go Page and Partial Authoring](https://github.com/maddalax/htmgo/tree/master/framework/h): `framework/h`
- [HTTP App Server](https://github.com/maddalax/htmgo/blob/master/framework/h/app.go): `framework/h/app.go`
- [Request Lifecycle](https://github.com/maddalax/htmgo/blob/master/framework/h/lifecycle.go): `framework/h/lifecycle.go`
- [htmx Support](https://github.com/maddalax/htmgo/tree/master/framework/hx): `framework/hx`
- [Service Locator](https://github.com/maddalax/htmgo/blob/master/framework/service/locator.go): `framework/service/locator.go`
- [HTML Rendering](https://github.com/maddalax/htmgo/blob/master/framework/h/render.go): `framework/h/render.go`
- [JS Commands](https://github.com/maddalax/htmgo/blob/master/framework/js/commands.go): `framework/js/commands.go`

### CLI Tooling

- [CLI Runner](https://github.com/maddalax/htmgo/blob/master/cli/htmgo/runner.go): `cli/htmgo/runner.go`
- [Page Registration](https://github.com/maddalax/htmgo/blob/master/cli/htmgo/tasks/astgen/entry.go): `cli/htmgo/tasks/astgen/entry.go`
- [Template Setup](https://github.com/maddalax/htmgo/blob/master/cli/htmgo/tasks/downloadtemplate/main.go): `cli/htmgo/tasks/downloadtemplate/main.go`
- [Build and Watch Tasks](https://github.com/maddalax/htmgo/tree/master/cli/htmgo/tasks): `cli/htmgo/tasks`

### WebSocket Extension

- [WebSocket HTTP Handler](https://github.com/maddalax/htmgo/blob/master/extensions/websocket/internal/wsutil/handler.go): `extensions/websocket/internal/wsutil/handler.go`
- [Socket and Room Manager](https://github.com/maddalax/htmgo/blob/master/extensions/websocket/internal/wsutil/manager.go): `extensions/websocket/internal/wsutil/manager.go`
- [WebSocket Event Handlers](https://github.com/maddalax/htmgo/blob/master/extensions/websocket/ws/handler.go): `extensions/websocket/ws/handler.go`
- [Socket Sessions](https://github.com/maddalax/htmgo/blob/master/extensions/websocket/session/session.go): `extensions/websocket/session/session.go`

### Project Website

- [Website App](https://github.com/maddalax/htmgo/blob/master/htmgo-site/main.go): `htmgo-site/main.go`
- [Website Pages](https://github.com/maddalax/htmgo/blob/master/htmgo-site/pages/index.go): `htmgo-site/pages/index.go`
- [Website Layout and Navigation](https://github.com/maddalax/htmgo/blob/master/htmgo-site/partials/navbar.go): `htmgo-site/partials/navbar.go`
- [Markdown and Site Helpers](https://github.com/maddalax/htmgo/tree/master/htmgo-site/internal): `htmgo-site/internal`

### HTML Converter

- [HTML-to-Go Converter](https://github.com/maddalax/htmgo/blob/master/tools/html-to-htmgo/htmltogo/main.go): `tools/html-to-htmgo/htmltogo/main.go`
- [HTML Parser Adapter](https://github.com/maddalax/htmgo/blob/master/tools/html-to-htmgo/internal/adapters/services/parser/parser.go): `tools/html-to-htmgo/internal/adapters/services/parser/parser.go`
- [Parsed Node Model](https://github.com/maddalax/htmgo/blob/master/tools/html-to-htmgo/internal/domain/node.go): `tools/html-to-htmgo/internal/domain/node.go`
- [Go Formatter Adapter](https://github.com/maddalax/htmgo/blob/master/tools/html-to-htmgo/internal/adapters/services/formatter/formatter.go): `tools/html-to-htmgo/internal/adapters/services/formatter/formatter.go`

### Other components

- **Developer**
- **Website Visitor**
- **Browser**
- **HTML Input**
- **Go Markup Output**

## Connections

- Developer → CLI Runner: runs commands (evidence: `cli/htmgo/runner.go`)
- CLI Runner → Page Registration: invokes registration (evidence: `cli/htmgo/runner.go`)
- CLI Runner → Template Setup: invokes setup (evidence: `cli/htmgo/runner.go`)
- CLI Runner → Build and Watch Tasks: runs tasks (evidence: `cli/htmgo/runner.go`)
- Developer → Go Page and Partial Authoring: defines pages
- Go Page and Partial Authoring → HTTP App Server: registers pages
- HTTP App Server → Request Lifecycle: handles requests
- HTTP App Server → htmx Support: uses htmx headers (evidence: `framework/h/app.go`)
- HTTP App Server → Service Locator: provides services (evidence: `framework/h/app.go`)
- Request Lifecycle → htmx Support: uses htmx helpers (evidence: `framework/h/lifecycle.go`)
- Browser → HTTP App Server: sends requests (evidence: `framework/h/app.go`)
- HTTP App Server → HTML Rendering: renders responses
- HTML Rendering → Browser: returns HTML
- JS Commands → Go Page and Partial Authoring: uses markup API (evidence: `framework/js/commands.go`)
- HTTP App Server → WebSocket HTTP Handler: serves socket handler
- WebSocket HTTP Handler → Socket and Room Manager: adds and dispatches (evidence: `extensions/websocket/internal/wsutil/handler.go`)
- Socket and Room Manager → WebSocket Event Handlers: emits socket events
- WebSocket Event Handlers → Socket and Room Manager: reads socket state (evidence: `extensions/websocket/ws/handler.go`)
- WebSocket HTTP Handler → Socket Sessions: uses sessions
- Website Visitor → Website App: visits site (evidence: `htmgo-site/main.go`)
- Website App → Markdown and Site Helpers: registers services (evidence: `htmgo-site/main.go`)
- Website Pages → Website Layout and Navigation: wraps page
- HTML Input → HTML-to-Go Converter: provides markup (evidence: `tools/html-to-htmgo/htmltogo/main.go`)
- HTML-to-Go Converter → HTML Parser Adapter: parses input (evidence: `tools/html-to-htmgo/htmltogo/main.go`)
- HTML Parser Adapter → Parsed Node Model: builds nodes (evidence: `tools/html-to-htmgo/internal/adapters/services/parser/parser.go`)
- HTML-to-Go Converter → Go Formatter Adapter: formats nodes (evidence: `tools/html-to-htmgo/htmltogo/main.go`)
- HTML-to-Go Converter → Go Markup Output: returns Go markup (evidence: `tools/html-to-htmgo/htmltogo/main.go`)
