# Warmup Strategy Code Map

## Layering rule

Warmup strategy intentionally uses a stricter architecture than older Acelle CRUD modules.

Required flow:

`FormRequest -> DTO -> Service -> Model/View`

Controllers orchestrate only. They do not validate raw payloads or persist business data directly.

## Request layer

- `app/Http/Requests/Admin/WarmupStrategy/StoreWarmupStrategyRequest.php`
- `app/Http/Requests/Admin/WarmupStrategy/UpdateWarmupStrategyRequest.php`
- `app/Http/Requests/Admin/WarmupStrategy/PreviewWarmupStrategyRequest.php`
- `app/Http/Requests/Admin/WarmupStrategy/AssignWarmupStrategyRequest.php`

Responsibilities:

- HTTP authorization
- payload validation
- normalization of booleans/defaults
- cross-field validation for the active limit option (`limit_per_day_cap >= starting_volume`, `limit_target_volume >= starting_volume`)
- strategy-specific growth normalization (`exponential_factor` persists as source field and maps to compatibility `daily_increment` percent)

## DTO layer

- `app/Dto/WarmupStrategyData.php`
- `app/Dto/WarmupStrategyPreviewData.php`

Responsibilities:

- strongly typed transfer objects between request/controller/service
- prevent loosely typed array plumbing across the module
- keep preview output separate from persistence shape

## Service layer

- `app/Services/WarmupStrategyService.php`

Responsibilities:

- create/update persistence
- preset payload generation
- assignment to sending servers
- warmup preview building
- compatibility mapping from limit-specific UI fields to legacy warmup engine fields
- providing preset payloads with both linear and exponential UI growth keys
- serving backend preview payloads for AJAX form preview and server-rendered list cards
- bulk enable/disable/delete helpers

## Model layer

- `app/Model/WarmupStrategy.php`
- `app/Model/SendingServer.php`

`WarmupStrategy` responsibilities:

- constants
- casts/fillables
- scopes
- read-side helpers such as `getPlanDetails()`, `estimatedFullWarmupDay()`, `riskLevel()`

`SendingServer` responsibilities:

- relation to warmup strategy
- persistence helper for assignment foreign key

## Controller layer

- `app/Http/Controllers/Admin/WarmupStrategyController.php`
- `app/Http/Controllers/Admin/SendingServerController.php`

Responsibilities:

- authorize the flow
- call service methods
- pass typed/prepared data to views
- return redirects or JSON responses

## View layer

- `resources/views/admin/warmup_strategies/create.blade.php`
- `resources/views/admin/warmup_strategies/edit.blade.php`
- `resources/views/admin/warmup_strategies/_form.blade.php`
- `resources/views/admin/warmup_strategies/_preview.blade.php`
- `resources/views/admin/warmup_strategies/_script.blade.php`
- `resources/views/admin/warmup_strategies/index.blade.php`
- `resources/views/admin/warmup_strategies/_list.blade.php`
- `resources/views/admin/sending_servers/warmup.blade.php`

Rules:

- Use helper controls from `resources/views/helpers/form_control/**`
- Keep custom CSS isolated under `warmup-*` classes in `public/core/css/app.css`
- Warmup text must come from `resources/lang/en/warmup.php`
- Growth input row is strategy-aware: linear shows `daily_increment`, exponential shows `exponential_factor`
- Limit row is limit-type-aware: `per_day_cap`, `target_volume`, and `stop_after_days` each reveal their own explicit field
- Right preview column renders ECharts line chart using existing frontend assets (`core/echarts/echarts.min.js`, `core/echarts/dark.js`)
- Frontend script renders preview data returned by the backend preview endpoint; it does not calculate warmup plans locally

## Translation layer

- `resources/lang/en/warmup.php`

This file is the source of truth for new warmup UI copy, helper text, flash messages, and validation messages.

## Database layer

- `database/migrations/2023_08_09_022243_create_warmup_strategies_table.php`
- `database/migrations/2024_12_06_084603_add_warmup_strategy_id_to_sending_servers.php`
- `database/migrations/2026_03_19_110000_add_designer_fields_to_warmup_strategies_table.php`
- `database/migrations/2026_03_19_111000_fix_warmup_strategy_foreign_key_on_sending_servers.php`
- `database/migrations/2026_03_20_090000_add_exponential_factor_to_warmup_strategies_table.php`
- `database/migrations/2026_03_21_090000_replace_warmup_limit_fields.php`

Notes:

- The follow-up migration repairs the incorrect foreign key target on `sending_servers.warmup_strategy_id`.
- The explicit limit migration replaces `maximum_volume` and `warmup_duration` with `limit_per_day_cap`, `limit_target_volume`, and `limit_stop_after_days`.
- New warmup product fields coexist with legacy compatibility fields until the runtime sending engine is upgraded to read the new model directly.