# UC-06 Open Dashboard (Module 4) - Architectural Mapping

This document maps the visual components from the **UC-06 Open Dashboard** PlantUML diagram to the Laravel backend implementation, specifically highlighting how **SOLID** design patterns and **DRY** principles are applied to handle role-based data scoping.

## 1. Actors & Access
* **Actors**: PR Employee, PRHeader, Quality, Admin.
* **Role Protection**: The Dashboard is universally accessible to all authenticated actors. It relies on the generic `auth:api` middleware. Instead of blocking access at the route level, security is enforced at the **data layer** through dynamic scoping.

## 2. "UC-06 Open Dashboard"
* **API Endpoint**: `GET /dashboard`.
* **Controller Structure**: Handled by `app/Http/Controllers/Api/DashboardController.php` (for the Flutter app). The controller simply receives the request and delegates the data aggregation to the Service layer, adhering strictly to the **Single Responsibility Principle (SRP)**.

## 3. "Scoped Data by Role" (<<include>>)
This is the most critical architectural component, described in the diagram notes: *PR -> own submissions only, PRHeader -> branch-level, Quality/Admin -> org-wide*.
* **Strategy Pattern (SOLID - Open/Closed Principle)**: Instead of writing messy `if/else` role checks in the controller, the backend utilizes the **Strategy Pattern**.
* **Implementation (DRY)**: 
    * A `ResponseScopeFactory` inspects the authenticated user.
    * It returns the appropriate strategy: `PrResponseScope`, `PrHeaderResponseScope`, or `AdminResponseScope`.
    * Each strategy implements `ResponseScopeStrategy` and applies a specific Eloquent query builder constraint (e.g., `->where('filled_by_user_id', $user->id)` for PR).
    * This perfectly applies the **DRY** principle, as the exact same scope factory is reused in the `ResponseController` (UC-10) and `ReportController` (UC-07).

## 4. KPI Views: Avg Satisfaction, Total Responses, Trend Chart, Top/Bottom Questions (<<include>>)
* **Service Layer Aggregation**: Once the base Eloquent query is scoped securely by the Strategy Pattern, a dedicated service (e.g., a Dashboard KPI Service) chains database aggregate methods onto the builder.
* **Database Efficiency**: Aggregations like `AVG()`, `COUNT()`, and `GROUP BY` are performed directly in the MySQL database via Eloquent builder methods rather than loading massive collections into PHP memory, ensuring the application scales effectively.
