Skip to content

Commit 3d91580

Browse files
Merge pull request #62 from conformist-mw/fix-annoying-error
vibe code code fixing. costs only $0.38
2 parents 47c0c91 + 8164dad commit 3d91580

File tree

2 files changed

+108
-1
lines changed

2 files changed

+108
-1
lines changed

CLAUDE.md

Lines changed: 105 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,105 @@
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

templates/app/base.html

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,10 +19,11 @@
1919
<div class="container">
2020
<div class="navbar-header">
2121
<a class="navbar-brand" href="/">Отрезы</a>
22-
{{ if .User.IsSuperuser }}
22+
{{ if and .User .User.IsSuperuser }}
2323
<a class="navbar-brand" href="/admin">Admin</a>
2424
{{ end }}
2525
</div>
26+
{{ if .User }}
2627
<div class="navbar-brand navbar-right">
2728
<span class="username">
2829
<span class="glyphicon glyphicon-user"></span> {{ .User.Username }}
@@ -33,6 +34,7 @@
3334
</button>
3435
</form>
3536
</div>
37+
{{ end }}
3638
</div>
3739
</nav>
3840
{{ end }}

0 commit comments

Comments
 (0)