# Nerd Monitor - Agent Guidelines ## Build & Test Commands ```bash # Generate Templ templates (required before building) make templ # Build server and agent for current OS make build # Build individual components make build-server make build-agent # Build for all platforms (Linux, macOS, Windows) make build-all # Clean build artifacts make clean ``` Note: This Go 1.21 project uses Templ for templating. Always run `make templ` before building. ## Code Style Guidelines **Imports**: Standard library first, then third-party packages, then internal modules. Organize alphabetically within each group. **Formatting & Types**: Use `gofmt` standards. Explicit struct field comments for exported types. Prefer `error` return values (no panic for recoverable errors). **Naming**: CamelCase for exported symbols, lowercase for unexported. Receiver names as single letters (e.g., `(m *Manager)`). Constants use ALL_CAPS_SNAKE_CASE. **Error Handling**: Define sentinel errors in dedicated files (e.g., `auth/errors.go`). Check errors explicitly; use `http.Error(w, "message", status)` for HTTP responses. Wrap errors with context when needed. **Project Structure**: - `cmd/`: Executable entry points (server, agent) - `internal/`: Packages (api, auth, stats, store, ui) - `views/`: Templ templates (*.templ files) **Concurrency**: Use `sync.RWMutex` for shared state. Always defer lock releases. Keep critical sections small. **HTTP**: Use Chi router. Handlers follow `func (h *Handler) Name(w http.ResponseWriter, r *http.Request)`. Set Content-Type headers explicitly. Validate query parameters early and return 400/404 appropriately.