|
| 1 | +# CLAUDE.md |
| 2 | + |
| 3 | +This file provides guidance to Claude Code (claude.ai/code) when working with code in this repository. |
| 4 | + |
| 5 | +## Project Overview |
| 6 | + |
| 7 | +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. |
| 8 | + |
| 9 | +## Architecture |
| 10 | + |
| 11 | +- **Web Framework**: Gin (github.com/gin-gonic/gin) |
| 12 | +- **Database**: SQLite with GORM ORM |
| 13 | +- **Template Engine**: Go's standard text/template |
| 14 | +- **Authentication**: Session-based using gin-contrib/sessions |
| 15 | + |
| 16 | +### Core Components |
| 17 | + |
| 18 | +1. **Models**: Data structures and database operations |
| 19 | + - `models/connect.go`: Database connection setup |
| 20 | + - `models/segments.go`: Segment-related models and operations |
| 21 | + - `models/colors.go`: Color type and color models |
| 22 | + - `models/locations.go`: Company, Section, and Rack models and queries |
| 23 | + - `models/users.go`: User authentication and management |
| 24 | + - `models/forms.go`: Form structures for validation |
| 25 | + - `models/validators.go`: Custom validation functions |
| 26 | + |
| 27 | +2. **Controllers**: Request handlers |
| 28 | + - `controllers.go`: Main application controllers |
| 29 | + - `admin/*.go`: Admin panel controllers |
| 30 | + |
| 31 | +3. **Views**: HTML templates using Gin's template engine |
| 32 | + - `templates/app/`: Frontend templates |
| 33 | + - `templates/admin/`: Admin interface templates |
| 34 | + |
| 35 | +4. **Static Assets**: CSS, JavaScript, and other static files |
| 36 | + |
| 37 | +### User Roles |
| 38 | + |
| 39 | +- **Regular Users**: Can view and manage segments |
| 40 | +- **Superusers**: Have access to the admin panel |
| 41 | + |
| 42 | +## Development Commands |
| 43 | + |
| 44 | +### Building and Running Locally |
| 45 | + |
| 46 | +```shell |
| 47 | +# Build the application |
| 48 | +go build -o segments |
| 49 | + |
| 50 | +# Run the application |
| 51 | +./segments |
| 52 | +``` |
| 53 | + |
| 54 | +### Docker Build and Run |
| 55 | + |
| 56 | +```shell |
| 57 | +# Build Docker image |
| 58 | +docker build -t segments . |
| 59 | + |
| 60 | +# Run Docker container |
| 61 | +docker run -p 8080:8080 segments |
| 62 | +``` |
| 63 | + |
| 64 | +### Database Migrations |
| 65 | + |
| 66 | +Database 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. |
| 67 | + |
| 68 | +```go |
| 69 | +// Enable migrations by changing this line in models/connect.go |
| 70 | +if 1 == 1 { // Change from 1 == 0 to 1 == 1 |
| 71 | + db.AutoMigrate( |
| 72 | + &ColorType{}, |
| 73 | + &Color{}, |
| 74 | + &Company{}, |
| 75 | + &Section{}, |
| 76 | + &Rack{}, |
| 77 | + &OrderNumber{}, |
| 78 | + &Segment{}, |
| 79 | + &User{}, |
| 80 | + ) |
| 81 | +} |
| 82 | +``` |
| 83 | + |
| 84 | +## Main Data Structure |
| 85 | + |
| 86 | +The application revolves around these key entities: |
| 87 | + |
| 88 | +1. **Companies**: Top-level organization |
| 89 | +2. **Sections**: Subdivisions within a company |
| 90 | +3. **Racks**: Physical storage locations within a section |
| 91 | +4. **Segments**: The actual rectangles being tracked, containing: |
| 92 | + - Dimensions (width, height) |
| 93 | + - Color information |
| 94 | + - Location (rack) |
| 95 | + - Status (active, defective) |
| 96 | + - Order number (for removed segments) |
| 97 | + |
| 98 | +## Contributing Guidelines |
| 99 | + |
| 100 | +When modifying code: |
| 101 | + |
| 102 | +1. Follow the existing code structure and naming conventions |
| 103 | +2. Test changes locally before committing |
| 104 | +3. For admin-related functionality, use the admin package |
| 105 | +4. For new model fields, update the corresponding template files |
0 commit comments