coolify/.ai/README.md
Andras Bacsai 7ceb124e9b feat: add validation for YAML parsing, integer parameters, and Docker Compose custom fields
This commit adds comprehensive validation improvements and DRY principles for handling Coolify's custom Docker Compose extensions.

## Changes

### 1. Created Reusable stripCoolifyCustomFields() Function
- Added shared helper in bootstrap/helpers/docker.php
- Removes all Coolify custom fields (exclude_from_hc, content, isDirectory, is_directory)
- Handles both long syntax (arrays) and short syntax (strings) for volumes
- Well-documented with comprehensive docblock
- Follows DRY principle for consistent field stripping

### 2. Fixed Docker Compose Modal Validation
- Updated validateComposeFile() to use stripCoolifyCustomFields()
- Now removes ALL custom fields before Docker validation (previously only removed content)
- Fixes validation errors when using templates with custom fields (e.g., traccar.yaml)
- Users can now validate compose files with Coolify extensions in UI

### 3. Enhanced YAML Validation in CalculatesExcludedStatus
- Added proper exception handling with ParseException vs generic Exception
- Added structure validation (checks if parsed result and services are arrays)
- Comprehensive logging with context (error message, line number, snippet)
- Maintains safe fallback behavior (returns empty collection on error)

### 4. Added Integer Validation to ContainerStatusAggregator
- Validates maxRestartCount parameter in both aggregateFromStrings() and aggregateFromContainers()
- Corrects negative values to 0 with warning log
- Logs warnings for suspiciously high values (> 1000)
- Prevents logic errors in crash loop detection

### 5. Comprehensive Unit Tests
- tests/Unit/StripCoolifyCustomFieldsTest.php (NEW) - 9 tests, 43 assertions
- tests/Unit/ContainerStatusAggregatorTest.php - Added 6 tests for integer validation
- tests/Unit/ExcludeFromHealthCheckTest.php - Added 4 tests for YAML validation
- All tests passing with proper Log facade mocking

### 6. Documentation
- Added comprehensive Docker Compose extensions documentation to .ai/core/deployment-architecture.md
- Documents all custom fields: exclude_from_hc, content, isDirectory/is_directory
- Includes examples, use cases, implementation details, and test references
- Updated .ai/README.md with navigation links to new documentation

## Benefits
- Better UX: Users can validate compose files with custom fields
- Better Debugging: Comprehensive logging for errors
- Better Code Quality: DRY principle with reusable validation
- Better Reliability: Prevents logic errors from invalid parameters
- Better Maintainability: Easy to add new custom fields in future

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude <noreply@anthropic.com>
2025-11-20 18:34:49 +01:00

5.9 KiB

Coolify AI Documentation

Welcome to the Coolify AI documentation hub. This directory contains all AI assistant instructions organized by topic for easy navigation and maintenance.

Quick Start

  • For Claude Code: Start with CLAUDE.md in root directory
  • For Cursor IDE: Check .cursor/rules/coolify-ai-docs.mdc which references this directory
  • For Other AI Tools: Continue reading below

Documentation Structure

📚 Core Documentation

Essential project information and architecture:

💻 Development

Day-to-day development practices:

  • Workflow - Development setup, commands, and daily workflows
  • Testing Patterns - How to write and run tests (Unit vs Feature, Docker requirements)
  • Laravel Boost - Laravel-specific guidelines and best practices

🎨 Patterns

Code patterns and best practices by domain:

📖 Meta

Documentation about documentation:

Quick Decision Tree

What do you need help with?

Running Commands

development/development-workflow.md

  • Frontend: npm run dev, npm run build
  • Backend: php artisan serve, php artisan migrate
  • Tests: Docker for Feature tests, mocking for Unit tests
  • Code quality: ./vendor/bin/pint, ./vendor/bin/phpstan

Writing Tests

development/testing-patterns.md

  • Unit tests: No database, use mocking, run outside Docker
  • Feature tests: Can use database, must run inside Docker
  • Command: docker exec coolify php artisan test

Building UI

patterns/frontend-patterns.md or patterns/form-components.md

  • Livewire components with server-side state
  • Alpine.js for client-side interactivity
  • Tailwind CSS 4.1.4 for styling
  • Form components with built-in authorization

Database Work

patterns/database-patterns.md

  • Eloquent ORM patterns
  • Migration best practices
  • Relationship definitions
  • Query optimization

Security & Auth

patterns/security-patterns.md

  • Team-based access control
  • Policy and gate patterns
  • Form authorization (canGate, canResource)
  • API security

Laravel-Specific Questions

development/laravel-boost.md

  • Laravel 12 patterns
  • Livewire 3 best practices
  • Pest testing patterns
  • Laravel conventions

Docker Compose Extensions

core/deployment-architecture.md

  • Custom fields: exclude_from_hc, content, isDirectory
  • How to use inline file content
  • Health check exclusion patterns
  • Volume creation control

Version Numbers

core/technology-stack.md

  • Single source of truth for all version numbers
  • Don't duplicate versions elsewhere, reference this file

Navigation Tips

  1. Start broad: Begin with project-overview or ../CLAUDE.md
  2. Get specific: Navigate to topic-specific files for details
  3. Cross-reference: Files link to related topics
  4. Single source: Version numbers and critical data exist in ONE place only

For AI Assistants

Important Patterns to Follow

Testing Commands:

  • Unit tests: ./vendor/bin/pest tests/Unit (no database, outside Docker)
  • Feature tests: docker exec coolify php artisan test (requires database, inside Docker)
  • NEVER run Feature tests outside Docker - they will fail with database connection errors

Version Numbers:

  • Always use exact versions from technology-stack.md
  • Laravel 12.4.1, PHP 8.4.7, Tailwind 4.1.4
  • Don't use "v12" or "8.4" - be precise

Form Authorization:

  • ALWAYS include canGate and :canResource on form components
  • See form-components.md for examples

Livewire Components:

Code Style:

  • Run ./vendor/bin/pint before finalizing changes
  • Follow PSR-12 standards
  • Use PHP 8.4 features (constructor promotion, typed properties, etc.)

Contributing

When updating documentation:

  1. Read meta/maintaining-docs.md
  2. Follow the single source of truth principle
  3. Update cross-references when moving content
  4. Test all links work
  5. Run Pint on markdown files if applicable

Questions?