From 3cfa8d7618abdb9cba0b89267518c2cb12df792a Mon Sep 17 00:00:00 2001 From: Victor Broman Date: Fri, 6 Feb 2026 18:41:43 +0100 Subject: [PATCH] adds --- .gitignore | 36 +++++++++ AGENTS.md | 97 ++++++++++++++++++++++++ templates/customers/form.html | 4 +- templates/ledger/journal_entry_form.html | 2 +- templates/login.html | 2 +- templates/orders/form.html | 4 +- 6 files changed, 139 insertions(+), 6 deletions(-) create mode 100644 .gitignore create mode 100644 AGENTS.md diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..35748b7 --- /dev/null +++ b/.gitignore @@ -0,0 +1,36 @@ +# Binaries for programs and plugins +*.exe +*.exe~ +*.dll +*.so +*.dylib + +# Test binary, built with `go test -c` +*.test + +# Output of the go coverage tool, specifically when used with LiteIDE +*.out + +# Dependency directories (remove the comment below to include it) +# vendor/ + +# Go workspace file +go.work + +# Project specific binaries +erp_system + +# SQLite +*.db +*.db-shm +*.db-wal + +# OS Specific +.DS_Store +Thumbs.db + +# Editor/IDE specific +.idea/ +.vscode/ +*.swp +*~ diff --git a/AGENTS.md b/AGENTS.md new file mode 100644 index 0000000..227d1a8 --- /dev/null +++ b/AGENTS.md @@ -0,0 +1,97 @@ +# ERP System Agent Guidelines + +This document provides instructions for coding agents working on the ERP System repository. + +## 1. Build, Lint, and Test + +### Build +To build the application: +```bash +go build -o erp_system main.go +``` +To run the application locally: +```bash +go run main.go +``` +The server defaults to port `1337`. + +### Test +Run all tests: +```bash +go test ./... +``` +Run a specific test package: +```bash +go test ./internal/handlers/... +``` +Run a single specific test function: +```bash +# Pattern: go test -v -run +go test -v ./internal/handlers -run TestLoginSubmit +``` + +### Lint / Verify +Run standard Go vetting: +```bash +go vet ./... +``` +Format code (always run before committing): +```bash +go fmt ./... +``` + +## 2. Code Style & Conventions + +### General +- **Language:** Go 1.25.6+ +- **Formatting:** Strictly adhere to `gofmt` standards. +- **Naming:** + - Use `PascalCase` for exported structs, fields, and functions. + - Use `camelCase` for unexported (private) identifiers. + - Keep variable names short but descriptive (e.g., `req` vs `r` is fine if context is clear, but `userRequest` is better for complex scopes). + +### Project Structure +- `main.go`: Application entry point, router setup, dependency injection. +- `internal/`: Private application code. + - `database/`: DB initialization and helpers. + - `handlers/`: HTTP handlers. + - `models/`: Data structs and business logic/DB queries. + - `middleware/`: HTTP middleware (Auth, etc.). +- `templates/`: HTML templates (server-side rendered). + +### Imports +Group imports into three blocks separated by a newline: +1. Standard library (e.g., `"net/http"`, `"os"`) +2. Third-party packages (e.g., `"github.com/gorilla/sessions"`) +3. Internal project packages (e.g., `"erp_system/internal/models"`) + +Example: +```go +import ( + "log" + "net/http" + + "github.com/gorilla/sessions" + + "erp_system/internal/models" +) +``` + +### Error Handling +- **Explicit Checks:** Always check errors. `if err != nil { ... }`. +- **Handlers:** Use `http.Error(w, err.Error(), http.Status...)` to return errors to the client. +- **Logging:** Log critical errors on the server side using `log.Printf` or similar before returning HTTP 500. + +### HTTP & Routing +- Use Go's standard `net/http` `ServeMux` with Go 1.22+ routing patterns (e.g., `mux.Handle("GET /path/{id}", ...)`). +- **HTMX:** The application uses HTMX. + - Check for `HX-Request` header to differentiate full page loads vs partials. + - Use `HX-Redirect` header for client-side redirection when handling HTMX requests. + - Render partial templates when appropriate. + +### Database +- Use `internal/models` for all database interactions. +- Pass the database connection (`*sql.DB`) or a wrapping struct to handlers via dependency injection (see `Handler` struct in `main.go`). + +## 3. Cursor / Copilot Rules +(No specific Cursor or Copilot rules found in the repository yet. Adhere to the conventions above.) diff --git a/templates/customers/form.html b/templates/customers/form.html index d8d7126..8737a65 100644 --- a/templates/customers/form.html +++ b/templates/customers/form.html @@ -14,9 +14,9 @@
diff --git a/templates/ledger/journal_entry_form.html b/templates/ledger/journal_entry_form.html index fcfa9bb..e709c92 100644 --- a/templates/ledger/journal_entry_form.html +++ b/templates/ledger/journal_entry_form.html @@ -12,7 +12,7 @@ {{end}}
- +
diff --git a/templates/login.html b/templates/login.html index 70eaa8c..bb4b0a7 100644 --- a/templates/login.html +++ b/templates/login.html @@ -23,7 +23,7 @@
{{end}} - +
diff --git a/templates/orders/form.html b/templates/orders/form.html index aa2fac0..d1ea2db 100644 --- a/templates/orders/form.html +++ b/templates/orders/form.html @@ -14,9 +14,9 @@