From 56a21b27fe763cf68fe388564c8b15074aedc328 Mon Sep 17 00:00:00 2001 From: DaX Date: Tue, 7 Oct 2025 17:57:34 +0200 Subject: [PATCH] Add new Bambu Lab colors and update documentation Add three new filament colors to support Wood and Matte finishes: - Classic Birch (PLA Wood) - #E8D5B7 - Rosewood (PLA Wood) - #472A22 - Desert Tan (PLA Matte) - #E8DBB7 Update CLAUDE.md with improved documentation: - Enhanced architecture details - Added color requests schema - Expanded deployment and database sections - Added testing and security details --- CLAUDE.md | 88 +++++++++++++++++++++++++++----------- src/data/bambuLabColors.ts | 1 + 2 files changed, 65 insertions(+), 24 deletions(-) diff --git a/CLAUDE.md b/CLAUDE.md index 73fbc06..592c9e0 100644 --- a/CLAUDE.md +++ b/CLAUDE.md @@ -1,6 +1,6 @@ # CLAUDE.md -This file provides guidance for AI-assisted development in this repository. +This file provides guidance to Claude Code (claude.ai/code) when working with code in this repository. ## Project Overview @@ -22,20 +22,19 @@ Filamenteka is a 3D printing filament inventory management system for tracking B ```bash # Development npm run dev # Start Next.js development server (port 3000) -npm run build # Build static export to /out directory -npm run lint # Run ESLint -npm test # Run Jest tests +npm run build # Build static export to /out directory +npm run lint # Run ESLint +npm test # Run Jest tests +npm run test:watch # Run Jest in watch mode # Security & Quality -npm run security:check # Check for credential leaks -npm run test:build # Test if build succeeds +npm run security:check # Check for credential leaks +npm run test:build # Test if build succeeds +./scripts/pre-commit.sh # Runs security, build, and test checks (use before commits) # Database Migrations -npm run migrate # Run pending migrations -npm run migrate:clear # Clear migration history - -# Pre-commit Hook -./scripts/pre-commit.sh # Runs security, build, and test checks +npm run migrate # Run pending migrations +npm run migrate:clear # Clear migration history ``` ## Architecture @@ -47,18 +46,26 @@ npm run migrate:clear # Clear migration history - `/page.tsx` - Admin login - `/dashboard/page.tsx` - Filament CRUD operations - `/colors/page.tsx` - Color management + - `/requests/page.tsx` - Customer color requests +- `/src` - Source files + - `/components` - React components + - `/services/api.ts` - Axios instance with auth interceptors + - `/data` - Color definitions (bambuLabColors.ts, bambuLabColorsComplete.ts) + - `/types` - TypeScript type definitions ### API Structure -- `/api` - Node.js Express server (runs on EC2) - - `/server.js` - Main server file - - `/routes` - API endpoints for filaments, colors, auth +- `/api` - Node.js Express server (runs on EC2, port 80) + - `/server.js` - Main Express server with all routes inline - Database: PostgreSQL on AWS RDS + - Endpoints: `/api/login`, `/api/filaments`, `/api/colors`, `/api/sale/bulk`, `/api/color-requests` ### Key Components - `FilamentTableV2` - Main inventory display with sorting/filtering - `SaleManager` - Bulk sale management interface - `ColorCell` - Smart color rendering with gradient support - `EnhancedFilters` - Advanced filtering system +- `ColorRequestForm` - Customer color request form +- `ColorRequestModal` - Modal for color requests ### Data Models @@ -90,22 +97,41 @@ colors: { } ``` +#### Color Requests Schema +```sql +color_requests: { + id: UUID, + color_name: VARCHAR(255), # Requested color name + message: TEXT, # Customer message + contact_name: VARCHAR(255), # Customer name (required) + contact_phone: VARCHAR(50), # Customer phone (required) + status: VARCHAR(20), # Status: pending, reviewed, fulfilled + created_at: TIMESTAMP +} +``` + ## Deployment ### Frontend (AWS Amplify) - Automatic deployment on push to main branch - Build output: Static files in `/out` directory - Config: `amplify.yml`, `next.config.js` (output: 'export') +- Security check runs during build (amplify.yml preBuild phase) ### API Server (EC2) -- Manual deployment via `scripts/deploy-api.sh` +- Manual deployment via `scripts/deploy-api.sh` or `scripts/deploy-api-update.sh` - Server: `3.71.161.51` - Domain: `api.filamenteka.rs` +- Service: `node-api` (systemd) +- IMPORTANT: When deploying API, remember to build for AMD64 Linux (not ARM macOS) ### Database (RDS PostgreSQL) - Host: `filamenteka.ci7fsdlbzmag.eu-central-1.rds.amazonaws.com` +- User: `filamenteka_admin` +- Database: `filamenteka` - Migrations in `/database/migrations/` - Schema in `/database/schema.sql` +- Use `scripts/update-db-via-aws.sh` for running migrations on production ## Important Patterns @@ -127,7 +153,10 @@ colors: { ### Testing - Jest + React Testing Library - Tests in `__tests__/` directory +- Config: `jest.config.js`, `jest.setup.js` - Coverage goal: >80% +- Run with `npm test` or `npm run test:watch` +- Tests include: component tests, API integration tests, data consistency checks ## Environment Variables @@ -135,27 +164,38 @@ colors: { # Frontend (.env.local) NEXT_PUBLIC_API_URL=https://api.filamenteka.rs/api -# API Server -DATABASE_URL=postgresql://... +# API Server (.env in /api directory) +DATABASE_URL=postgresql://filamenteka_admin:PASSWORD@filamenteka.ci7fsdlbzmag.eu-central-1.rds.amazonaws.com:5432/filamenteka JWT_SECRET=... +ADMIN_PASSWORD=... NODE_ENV=production +PORT=80 ``` ## Security Considerations -- Admin routes protected by JWT authentication -- Password hashing with bcrypt +- Admin routes protected by JWT authentication (24h expiry) +- Password hashing with bcrypt (for future multi-user support) - SQL injection prevention via parameterized queries -- Credential leak detection in pre-commit hooks -- CORS configured for production domains only +- Credential leak detection in pre-commit hooks (`scripts/security/security-check.js`) +- CORS configured to allow all origins (update for production hardening) +- Auth token interceptors handle 401/403 automatically +- Pre-commit hook runs security checks, build tests, and unit tests ## Database Operations When modifying the database: -1. Create migration file in `/database/migrations/` +1. Create migration file in `/database/migrations/` with sequential numbering 2. Test locally first -3. Run migration on production via scripts -4. Update corresponding TypeScript types +3. Run migration on production: + - Use `scripts/update-db-via-aws.sh` for remote execution + - Or use `npm run migrate` for local/scripted execution +4. Update corresponding TypeScript types in `/src/types/` + +Important database constraints: +- `filaments.boja` has foreign key to `colors.name` (ON UPDATE CASCADE) +- `filaments.kolicina` has check constraint: `kolicina = refill + spulna` +- Always update `colors` table first before adding filaments with new colors ## Terraform Infrastructure diff --git a/src/data/bambuLabColors.ts b/src/data/bambuLabColors.ts index 15ed9f3..79f6b71 100644 --- a/src/data/bambuLabColors.ts +++ b/src/data/bambuLabColors.ts @@ -33,6 +33,7 @@ export const bambuLabColors: Record = { 'Charcoal': { hex: '#000000' }, 'Cherry Pink': { hex: '#E9B6CC' }, 'Chocolate': { hex: '#4A3729' }, + 'Classic Birch': { hex: '#E8D5B7' }, 'Clay Brown': { hex: '#8E621A' }, 'Clear': { hex: '#FAFAFA' }, 'Clear Black': { hex: '#5A5161' },