This file provides guidance to Claude Code (claude.ai/code) when working with code in this repository.
Segments is a Go-based web application for tracking and managing segments (rectangles) by size, type, or color. It provides functionality for adding, moving, removing, and reactivating segments. Removed segments are marked as inactive rather than deleted from the database.
- Web Framework: Gin (github.com/gin-gonic/gin)
- Database: SQLite with GORM ORM
- Template Engine: Go's standard text/template
- Authentication: Session-based using gin-contrib/sessions
-
Models: Data structures and database operations
models/connect.go: Database connection setupmodels/segments.go: Segment-related models and operationsmodels/colors.go: Color type and color modelsmodels/locations.go: Company, Section, and Rack models and queriesmodels/users.go: User authentication and managementmodels/forms.go: Form structures for validationmodels/validators.go: Custom validation functions
-
Controllers: Request handlers
controllers.go: Main application controllersadmin/*.go: Admin panel controllers
-
Views: HTML templates using Gin's template engine
templates/app/: Frontend templatestemplates/admin/: Admin interface templates
-
Static Assets: CSS, JavaScript, and other static files
- Regular Users: Can view and manage segments
- Superusers: Have access to the admin panel
# Build the application
go build -o segments
# Run the application
./segments# Build Docker image
docker build -t segments .
# Run Docker container
docker run -p 8080:8080 segmentsDatabase migrations are handled through GORM's AutoMigrate feature. The migration code in models/connect.go is disabled by default (the condition if 1 == 0). To run migrations, temporarily change this condition and run the application.
// Enable migrations by changing this line in models/connect.go
if 1 == 1 { // Change from 1 == 0 to 1 == 1
db.AutoMigrate(
&ColorType{},
&Color{},
&Company{},
&Section{},
&Rack{},
&OrderNumber{},
&Segment{},
&User{},
)
}The application revolves around these key entities:
- Companies: Top-level organization
- Sections: Subdivisions within a company
- Racks: Physical storage locations within a section
- Segments: The actual rectangles being tracked, containing:
- Dimensions (width, height)
- Color information
- Location (rack)
- Status (active, defective)
- Order number (for removed segments)
When modifying code:
- Follow the existing code structure and naming conventions
- Test changes locally before committing
- For admin-related functionality, use the admin package
- For new model fields, update the corresponding template files