This commit is contained in:
Victor Broman 2026-02-06 18:41:43 +01:00
parent 88ddf4c043
commit 3cfa8d7618
6 changed files with 139 additions and 6 deletions

36
.gitignore vendored Normal file

@ -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
*~

97
AGENTS.md Normal file

@ -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 <package_path> -run <TestNameRegex>
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.)

@ -14,9 +14,9 @@
<div class="bg-white shadow sm:rounded-lg"> <div class="bg-white shadow sm:rounded-lg">
<form class="space-y-6 p-6" <form class="space-y-6 p-6"
{{if .IsNew}} {{if .IsNew}}
method="POST" action="/customers" hx-post="/customers" method="POST" action="/customers" hx-post="/customers" hx-target="body"
{{else}} {{else}}
method="POST" action="/customers/{{.Customer.ID}}" hx-put="/customers/{{.Customer.ID}}" method="POST" action="/customers/{{.Customer.ID}}" hx-put="/customers/{{.Customer.ID}}" hx-target="body"
{{end}}> {{end}}>
<div class="grid grid-cols-1 gap-6 sm:grid-cols-2"> <div class="grid grid-cols-1 gap-6 sm:grid-cols-2">

@ -12,7 +12,7 @@
{{end}} {{end}}
<div class="bg-white shadow sm:rounded-lg"> <div class="bg-white shadow sm:rounded-lg">
<form class="space-y-6 p-6" method="POST" action="/ledger/journal" hx-post="/ledger/journal" id="je-form"> <form class="space-y-6 p-6" method="POST" action="/ledger/journal" id="je-form">
<div class="grid grid-cols-1 gap-6 sm:grid-cols-3"> <div class="grid grid-cols-1 gap-6 sm:grid-cols-3">
<div> <div>
<label for="entry_date" class="block text-sm font-medium text-gray-700">Date *</label> <label for="entry_date" class="block text-sm font-medium text-gray-700">Date *</label>

@ -23,7 +23,7 @@
</div> </div>
{{end}} {{end}}
<form class="mt-8 space-y-6" method="POST" action="/login" hx-post="/login"> <form class="mt-8 space-y-6" method="POST" action="/login" hx-post="/login" hx-target="body">
<div class="space-y-4 rounded-md shadow-sm"> <div class="space-y-4 rounded-md shadow-sm">
<div> <div>
<label for="username" class="block text-sm font-medium text-gray-700">Username</label> <label for="username" class="block text-sm font-medium text-gray-700">Username</label>

@ -14,9 +14,9 @@
<div class="bg-white shadow sm:rounded-lg"> <div class="bg-white shadow sm:rounded-lg">
<form class="space-y-6 p-6" <form class="space-y-6 p-6"
{{if .IsNew}} {{if .IsNew}}
method="POST" action="/orders" hx-post="/orders" method="POST" action="/orders" hx-post="/orders" hx-target="body"
{{else}} {{else}}
method="POST" action="/orders/{{.Order.ID}}" hx-put="/orders/{{.Order.ID}}" method="POST" action="/orders/{{.Order.ID}}" hx-put="/orders/{{.Order.ID}}" hx-target="body"
{{end}}> {{end}}>
<div class="grid grid-cols-1 gap-6 sm:grid-cols-2"> <div class="grid grid-cols-1 gap-6 sm:grid-cols-2">