# UC-04 View All Survey Templates (Module 2) - Architectural Mapping

This document maps the visual components from the **UC-04 View All Survey Templates** Use Case diagram to the Laravel backend implementation.

## 1. Actors
* **Actors**: Quality and Admin.
* **Role Protection**: Enforced via `Route::middleware(['role:Quality,Admin'])` for the entire `TemplateController` resource group. 

## 2. "List All Templates with Status" (<<include>>) & "Filter by Date / IsActive" (<<extend>>)
* **API Endpoint**: `GET /templates`.
* **DRY/SOLID Implementation**: The `TemplateController::index` uses the shared `TemplateQueryService` with the `TemplateFilter::forTemplateManagement()` specification. This ensures that the query returns *all* templates (active or inactive) and includes the critical `HasResponses` aggregate count.

## 3. "View Template Detail (Sections+Questions)" (<<extend>>)
* **API Endpoint**: `GET /templates/{id}`.
* **Data Retrieval**: `TemplateController::show` again utilizes the `TemplateQueryService` to eagerly load nested relationships (`sections.questions.options`) efficiently without N+1 query problems.

## 4. "Toggle Template IsActive" (<<extend>>)
* **API Endpoint**: `PATCH /templates/{id}/toggle`.
* **Business Logic**: Handled by `TemplateService::toggleActive` and the `TemplateRepository`. This adheres to the Repository pattern to isolate database update statements from the controller logic.
