---
phase: 97-project-generation
plan: 01
subsystem: automation
tags: [photoshop, python, psd, project-generation, smart-object]

requires: []
provides:
  - project_mappings table and CRUD UI
  - project_generated flag on order_items
  - Claude Code /wygeneruj-projekty command
  - Photoshop API script for PSD generation
  - Project status badges on order list and details
affects: [future product-specific generators]

tech-stack:
  added: [photoshop-python-api]
  patterns: [claude-as-engine, photoshop-com-api, smart-object-text-replace]

key-files:
  created:
    - tools/generowanie/buteleczki_wzor1.py
    - src/Modules/Settings/ProjectMappingController.php
    - src/Modules/Settings/ProjectMappingRepository.php
    - resources/views/settings/project-mappings.php
    - .claude/commands/wygeneruj-projekty.md
    - database/migrations/20260412_000097_add_project_generation.sql
    - database/migrations/20260412_000098_rename_external_status_id_to_status_code.sql
  modified:
    - routes/web.php
    - resources/views/layouts/app.php
    - resources/lang/pl.php
    - src/Modules/Orders/OrdersController.php
    - src/Modules/Orders/OrdersRepository.php
    - resources/views/orders/show.php

key-decisions:
  - "Claude as generation engine — AI interprets client personalization instead of rigid PHP parser"
  - "Rename external_status_id to status_code — column held internal status, name was misleading"
  - "Position preservation via bounds+translate — Photoshop API ignores textItem.position assignment"

patterns-established:
  - "Smart Object text editing: save bounds before, translate after change"
  - "Claude Code command as workflow engine for semi-automated processes"

duration: ~120min
started: 2026-04-12T00:00:00Z
completed: 2026-04-12T01:30:00Z
---

# Phase 97 Plan 01: Project Generation Summary

**Polautomatyczne generowanie projektow graficznych PSD z danych zamowien — Claude jako silnik interpretacji danych klienta, Photoshop API do podmiany tekstow w Smart Objects.**

## Performance

| Metric | Value |
|--------|-------|
| Duration | ~120min |
| Started | 2026-04-12 |
| Completed | 2026-04-12 |
| Tasks | 5 completed (3 auto + 2 checkpoints) |
| Files created | 8 |
| Files modified | 15+ (including rename refactor) |

## Acceptance Criteria Results

| Criterion | Status | Notes |
|-----------|--------|-------|
| AC-1: Tabela project_mappings + kolumna project_generated | Pass | Migracja 000097 + 000098 |
| AC-2: CRUD mapowan w panelu | Pass | Ustawienia > Mapowanie projektow |
| AC-3: Komenda /wygeneruj-projekty | Pass | Test end-to-end z zamowieniem OP000000159 |

## Accomplishments

- Skrypt Python `buteleczki_wzor1.py` generuje PSD przez Photoshop COM API z zachowaniem pozycji warstw
- CRUD mapowan produktow na skrypty w panelu ustawien
- Komenda Claude Code `/wygeneruj-projekty` — Claude odpytuje DB, interpretuje personalizacje AI-em, uruchamia skrypt, oznacza w bazie
- Flagi statusu projektow na liscie zamowien (zielona/zolta/szara ikonka) i w szczegolach (badge przy produkcie)
- Rename `external_status_id` → `status_code` w 13+ plikach PHP — poprawka mylacej nazwy kolumny
- Detekcja Photoshopa przed generowaniem (tasklist)

## Files Created/Modified

| File | Change | Purpose |
|------|--------|---------|
| `tools/generowanie/buteleczki_wzor1.py` | Created | Skrypt Photoshop API — buteleczki weselne Wzor 1 |
| `database/migrations/20260412_000097_add_project_generation.sql` | Created | Tabela project_mappings + kolumny project_generated |
| `database/migrations/20260412_000098_rename_external_status_id_to_status_code.sql` | Created | Rename kolumny statusu |
| `src/Modules/Settings/ProjectMappingRepository.php` | Created | CRUD repository dla mapowan |
| `src/Modules/Settings/ProjectMappingController.php` | Created | Kontroler CRUD mapowan |
| `resources/views/settings/project-mappings.php` | Created | Widok ustawien mapowan |
| `resources/scss/modules/_project-mappings.scss` | Created | Style mapowan + badge projektow |
| `.claude/commands/wygeneruj-projekty.md` | Created | Komenda Claude Code |
| `routes/web.php` | Modified | Routing + instancjacja kontrolera |
| `resources/views/layouts/app.php` | Modified | Link w sidebar menu |
| `resources/lang/pl.php` | Modified | Tlumaczenia |
| `resources/scss/app.scss` | Modified | Import SCSS modulu |
| `src/Modules/Orders/OrdersRepository.php` | Modified | projects_done/total w query + rename |
| `src/Modules/Orders/OrdersController.php` | Modified | projectBadge() + productsHtml() |
| `resources/views/orders/show.php` | Modified | Badge przy produkcie |
| `src/Modules/Orders/OrderImportRepository.php` | Modified | Rename |
| `src/Modules/Automation/OrderStatusAgedService.php` | Modified | Rename |
| `src/Modules/Automation/AutomationService.php` | Modified | Rename |
| `src/Modules/Settings/AllegroOrderImportService.php` | Modified | Rename |
| `src/Modules/Settings/AllegroStatusSyncService.php` | Modified | Rename |
| `src/Modules/Settings/ShopproStatusSyncService.php` | Modified | Rename |
| `src/Modules/Settings/ShopproPaymentStatusSyncService.php` | Modified | Rename |
| `src/Modules/Settings/ShopproOrderMapper.php` | Modified | Rename |

## Deviations from Plan

### Summary

| Type | Count | Impact |
|------|-------|--------|
| Scope additions | 2 | Valuable improvements |
| Auto-fixed | 3 | Import namespace fixes |

### Scope Additions

1. **Rename `external_status_id` → `status_code`** — odkryto podczas testow komendy ze nazwa kolumny jest mylaca. Refactor 13+ plikow + migracja.

2. **Flagi statusu projektow na liscie/szczegolach** — uzytkownik poprosil o wizualna informacje o statusie generacji. Dodano ikonki i badge.

### Auto-fixed Issues

1. **Bledne importy w ProjectMappingController** — `App\Core\Template\Template` → `App\Core\View\Template`, `App\Core\Translation\Translator` → `App\Core\I18n\Translator`, `App\Core\Session\Flash` → `App\Core\Support\Flash`

## Decisions Made

| Decision | Rationale | Impact |
|----------|-----------|--------|
| Claude jako silnik generowania | AI lepiej interpretuje rozne formaty personalizacji niz sztywny parser PHP | Komenda zamiast serwisu PHP |
| Rename external_status_id | Kolumna trzyma wewnetrzny status, nazwa mylaca | 13+ plikow zmienionych, czytelniejszy kod |
| Bounds+translate dla pozycji | textItem.position nie dziala w Photoshop API | Niezawodne zachowanie pozycji warstw |

## Next Phase Readiness

**Ready:**
- System gotowy do rozszerzenia o nowe skrypty (kubki, pudełka, itp.)
- Mapowania w panelu — latwe dodawanie nowych produktow
- Struktura warstw PSD uporzadkowana (imie_zenskie, imie_meskie, data, zyczenia)

**Concerns:**
- Kazdy nowy produkt wymaga osobnego skryptu Python + uporządkowania warstw PSD

**Blockers:** None

---
*Phase: 97-project-generation, Plan: 01*
*Completed: 2026-04-12*
