# Glimmer — Codex Guide ## Project Overview **Glimmer** is a single-binary Go URL shortener + pastebin with image and file upload support. It runs on a Raspberry Pi Zero (512 MB RAM, ARMv5) and compiles to a fully self-contained binary — no CGo, no external runtime, no system SQLite. Live at [luci.ooo](https://luci.ooo). --- ## Build Commands ```bash make build # Windows → glimmer.exe make build-linux # Linux x86-64 → glimmer make build-arm # RPi Zero (ARMv5) → glimmer-arm make run # Build + run on Windows make clean # Remove all compiled binaries make hash # Interactively hash a password for config.toml ``` Always run `go build ./...` (or `make build`) after any Go changes to confirm the project compiles before finishing a task. --- ## Project Structure ``` glimmer/ ├── main.go # Entry point; --hash-password flag ├── config.toml # Runtime config (not embedded — loaded at startup) ├── go.mod / go.sum ├── Makefile ├── data/ │ ├── urls.db # SQLite DB (auto-created) │ └── uploads/ # Uploaded images & files (auto-created) └── internal/ ├── config/config.go # TOML config structs + loader ├── db/db.go # DB open/migrate; Link + Paste + Upload CRUD ├── slug/slug.go # Base-36 slug generation + validation └── server/ ├── server.go # Mux, middleware wiring, server start ├── handlers.go # All HTTP handlers + rendering helpers ├── middleware.go # Auth, CSRF, sessions, rate limiter ├── templates.go # embed.FS for templates + static; initTemplates() ├── static/ │ ├── css/ │ │ └── style.css # Custom Solis-style design system (amber/cream, Outfit font) │ ├── favicon.ico │ ├── favicon.png │ ├── js/ # Per-page scripts (CSP blocks inline JS) │ │ ├── base.js # QR modal, data-confirm forms, glimmerCopy │ │ └── *.js # One file per template that needs behaviour │ └── upload.js # Shared client-side upload helper (window.GlimmerUpload) └── templates/ ├── base.html # Layout wrapper: sidebar (logged in) or public header ├── index.html # Public: URL shortener form ├── admin_login.html # Login (light, centered card) ├── admin.html # Dashboard: stats, tiles, links tables ├── admin_edit.html # Edit a single link ├── admin_bin.html # Pastes list (cards + preview dialog) ├── admin_bin_edit.html # Create / edit paste (uses /static/upload.js) ├── admin_uploads.html # Image + file upload management ├── bin_view.html # Public paste viewer ├── bin_token.html # Token prompt for protected pastes └── 404.html ``` --- ## Architecture ### Single package per layer - `internal/config` — pure config loading, no HTTP - `internal/db` — pure database, no HTTP - `internal/slug` — pure slug logic, no HTTP - `internal/server` — everything HTTP: mux, handlers, middleware, templates ### All handlers on `*Server` ```go type Server struct { cfg *config.Config db *db.DB sessions *sessionStore limiter *rateLimiter } ``` ### pageData is the single template context struct All templates receive a `pageData` struct. Add new fields there when templates need new data — never pass raw types directly. ### Templates are embedded, not on disk Templates and static files are embedded into the binary via `//go:embed` in `templates.go`. Changes to templates are compiled in; they are **not** reloaded at runtime. Always rebuild after template changes. ### No JS frameworks — and no inline JS All JavaScript is vanilla ES5-style (`var`, not `const`/`let`). No build step, no npm, no bundler. The CSP is `script-src 'self'`, so **inline `