# tomig06/tinyreload architecture

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

- Interactive diagram: https://gitdiagram.com/tomig06/tinyreload
- Repository: https://github.com/tomig06/tinyreload

## Overview

#### Purpose and Entry Point
`tinyreload` is a single Go binary that serves a static-site directory and live-reloads connected browsers when files change. The executable entry point and server orchestration are in `tinyreload.go`; module dependencies are defined in `go.mod`.

#### CLI and Process Startup
The process accepts `-path` for the static-root directory and `-addr` for the HTTP listen address. Startup configures the file server, WebSocket endpoint, embedded client asset, filesystem watcher, and HTTP listener.
- `tinyreload.go`
- `go.mod`

#### Static File Serving and HTML Transformation
Requests are resolved against the configured static root. Directory handling redirects or resolves paths toward `index.html`. HTML responses are modified to inject the browser client script, while HTML is served with no-cache behavior so reloads fetch current markup.
- `tinyreload.go`

#### Embedded Browser Runtime
The reload client is bundled into the Go binary rather than copied from the served site. Browsers receive it at `/tinyreload.js`; it establishes a WebSocket connection and applies reload commands.
- `injectable/tinyreload.js`
- `tinyreload.go`

#### Live-Reload Transport
The server maintains WebSocket-connected browser clients and broadcasts filesystem-change events as file URLs. The browser runtime distinguishes CSS updates from other changes: CSS is refreshed in place, while non-CSS changes trigger a full page reload.
- `tinyreload.go`
- `injectable/tinyreload.js`

#### Filesystem Watch Pipeline
A recursive watcher monitors the configured static root and its subdirectories. Change events are filtered to ignore dotfiles, then translated into browser-facing paths and sent through the WebSocket broadcast path. This is the main boundary between local filesystem events and browser reload behavior.
- `tinyreload.go`

#### Runtime and Delivery Model
The architecture is local-process oriented: Go hosts HTTP and WebSocket services, serves user-provided static files, and embeds its only client-side dependency. No database, cloud infrastructure, build pipeline, or external runtime service is required. `setup.sh` provides repository setup for local development.
- `tinyreload.go`
- `injectable/tinyreload.js`
- `setup.sh`

Main entry points: [`tinyreload.go`](https://github.com/tomig06/tinyreload/blob/main/tinyreload.go) (Server orchestration), [`injectable/tinyreload.js`](https://github.com/tomig06/tinyreload/blob/main/injectable/tinyreload.js) (Reload runtime), [`go.mod`](https://github.com/tomig06/tinyreload/blob/main/go.mod) (Go module dependencies), [`setup.sh`](https://github.com/tomig06/tinyreload/blob/main/setup.sh) (Local setup script)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_go_server["Go server"]
  node_cli["CLI flags<br/>startup<br/>[tinyreload.go]"]
  node_server{{"Server orchestration<br/>Go entry point<br/>[tinyreload.go]"}}
  node_static_handler["Static file handler<br/>HTTP handler<br/>[tinyreload.go]"]
  node_html_injection["HTML injection<br/>response transform<br/>[tinyreload.go]"]
  node_embedded_client["Embedded client asset<br/>bundled JavaScript<br/>[tinyreload.js]"]
  node_websocket_hub{{"WebSocket client hub<br/>transport<br/>[tinyreload.go]"}}
  node_watcher["Recursive filesystem watcher<br/>event source<br/>[tinyreload.go]"]
  node_change_filter["Change filter and mapper<br/>event pipeline<br/>[tinyreload.go]"]
  node_http_listener["HTTP listener<br/>local listener<br/>[tinyreload.go]"]
  node_module["Go module dependencies<br/>module definition<br/>[go.mod]"]
end

subgraph group_browser["Browser"]
  node_browser_page["Site page<br/>browser document"]
  node_reload_runtime["Reload runtime<br/>browser JavaScript<br/>[tinyreload.js]"]
end

node_static_root["Static root<br/>user directory"]
node_setup["Local setup script<br/>development setup<br/>[setup.sh]"]

node_cli -->|"configures"| node_server
node_module -.->|"provides dependencies"| node_server
node_server -->|"configures"| node_static_handler
node_server -->|"configures"| node_websocket_hub
node_server -->|"starts"| node_watcher
node_server -->|"starts"| node_http_listener
node_static_root -->|"serves from"| node_static_handler
node_static_handler -->|"transforms HTML"| node_html_injection
node_html_injection -->|"returns injected page"| node_browser_page
node_embedded_client -->|"served at /tinyreload.js"| node_http_listener
node_http_listener -->|"serves HTTP"| node_browser_page
node_browser_page -->|"loads"| node_reload_runtime
node_reload_runtime -->|"connects WebSocket"| node_websocket_hub
node_static_root -->|"monitors"| node_watcher
node_watcher -->|"emits file events"| node_change_filter
node_change_filter -->|"broadcasts changed URL"| node_websocket_hub
node_websocket_hub -->|"sends reload command"| node_reload_runtime
node_setup -.->|"prepares local development"| node_module

click node_cli "https://github.com/tomig06/tinyreload/blob/main/tinyreload.go"
click node_server "https://github.com/tomig06/tinyreload/blob/main/tinyreload.go"
click node_static_handler "https://github.com/tomig06/tinyreload/blob/main/tinyreload.go"
click node_html_injection "https://github.com/tomig06/tinyreload/blob/main/tinyreload.go"
click node_embedded_client "https://github.com/tomig06/tinyreload/blob/main/injectable/tinyreload.js"
click node_websocket_hub "https://github.com/tomig06/tinyreload/blob/main/tinyreload.go"
click node_watcher "https://github.com/tomig06/tinyreload/blob/main/tinyreload.go"
click node_change_filter "https://github.com/tomig06/tinyreload/blob/main/tinyreload.go"
click node_http_listener "https://github.com/tomig06/tinyreload/blob/main/tinyreload.go"
click node_reload_runtime "https://github.com/tomig06/tinyreload/blob/main/injectable/tinyreload.js"
click node_setup "https://github.com/tomig06/tinyreload/blob/main/setup.sh"
click node_module "https://github.com/tomig06/tinyreload/blob/main/go.mod"

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_cli,node_server,node_static_handler,node_html_injection,node_embedded_client,node_websocket_hub,node_watcher,node_change_filter,node_http_listener,node_module toneBlue
class node_browser_page,node_reload_runtime toneAmber
class node_static_root,node_setup toneNeutral
```

## Components

### Go server

Single local-process runtime.

- [CLI flags](https://github.com/tomig06/tinyreload/blob/main/tinyreload.go): startup · Accepts static root and listen address. · `tinyreload.go`
- [Server orchestration](https://github.com/tomig06/tinyreload/blob/main/tinyreload.go): Go entry point · Configures HTTP, WebSocket, assets, and watching. · `tinyreload.go`
- [Static file handler](https://github.com/tomig06/tinyreload/blob/main/tinyreload.go): HTTP handler · Resolves directories and serves transformed HTML. · `tinyreload.go`
- [HTML injection](https://github.com/tomig06/tinyreload/blob/main/tinyreload.go): response transform · Injects the embedded reload client and disables HTML caching. · `tinyreload.go`
- [Embedded client asset](https://github.com/tomig06/tinyreload/blob/main/injectable/tinyreload.js): bundled JavaScript · Served at /tinyreload.js from the binary. · `injectable/tinyreload.js`
- [WebSocket client hub](https://github.com/tomig06/tinyreload/blob/main/tinyreload.go): transport · Tracks browsers and broadcasts changed file URLs. · `tinyreload.go`
- [Recursive filesystem watcher](https://github.com/tomig06/tinyreload/blob/main/tinyreload.go): event source · Monitors the static root and subdirectories. · `tinyreload.go`
- [Change filter and mapper](https://github.com/tomig06/tinyreload/blob/main/tinyreload.go): event pipeline · Ignores dotfiles and maps changes to browser paths. · `tinyreload.go`
- [HTTP listener](https://github.com/tomig06/tinyreload/blob/main/tinyreload.go): local listener · Hosts static, client asset, and WebSocket endpoints. · `tinyreload.go`
- [Go module dependencies](https://github.com/tomig06/tinyreload/blob/main/go.mod): module definition · `go.mod`

### Browser

- **Site page**: browser document
- [Reload runtime](https://github.com/tomig06/tinyreload/blob/main/injectable/tinyreload.js): browser JavaScript · Refreshes CSS in place or reloads the page. · `injectable/tinyreload.js`

### Other components

- **Static root**: user directory · User-provided site files monitored and served locally.
- [Local setup script](https://github.com/tomig06/tinyreload/blob/main/setup.sh): development setup · `setup.sh`

## Connections

- CLI flags → Server orchestration: configures
- Go module dependencies → Server orchestration: provides dependencies
- Server orchestration → Static file handler: configures
- Server orchestration → WebSocket client hub: configures
- Server orchestration → Recursive filesystem watcher: starts
- Server orchestration → HTTP listener: starts
- Static root → Static file handler: serves from
- Static file handler → HTML injection: transforms HTML
- HTML injection → Site page: returns injected page
- Embedded client asset → HTTP listener: served at /tinyreload.js
- HTTP listener → Site page: serves HTTP
- Site page → Reload runtime: loads
- Reload runtime → WebSocket client hub: connects WebSocket
- Static root → Recursive filesystem watcher: monitors
- Recursive filesystem watcher → Change filter and mapper: emits file events
- Change filter and mapper → WebSocket client hub: broadcasts changed URL
- WebSocket client hub → Reload runtime: sends reload command
- Local setup script → Go module dependencies: prepares local development
