# UC-01 Login - Architectural Mapping

This document maps the visual components from the **UC-01 Login** Use Case diagram to the Laravel backend implementation. The architecture strictly follows **SOLID** and **DRY** principles, utilizing a Laravel back-end and MySQL database as specified.

## 1. "POST /auth/login" Endpoint & "UC-01 Login"
* **Route Definition**: The endpoint is defined as a public API route (`Route::post('auth/login', [AuthController::class, 'login']);`) in `routes/api.php`.
* **Controller**: The HTTP request is handled by `app/Http/Controllers/Api/AuthController.php`. The controller stays thin, adhering to the Single Responsibility Principle, by delegating authentication logic to a dedicated service.

## 2. "Enter Username & Password"
* **Validation**: Username and password inputs are validated using a dedicated Form Request class: `app/Http/Requests/LoginRequest.php`. This centralizes validation rules, fully satisfying the DRY principle.

## 3. "Validate JWT Credentials" (<<include>>)
* **Service Layer**: The core authentication logic resides in `app/Services/Auth/JwtAuthService.php`.
* **Database Verification**: This service attempts to match the credentials against the `ApplicationUser` MySQL table utilizing the `auth()->attempt($credentials)` method.

## 4. "Show Error Message" (<<extend>> credentials invalid)
* **Error Response**: If validation fails or credentials do not match, the `AuthController` explicitly returns a JSON error response with an HTTP 401 status code: `return response()->json(['success' => false, 'message' => 'Invalid credentials'], 401);`.

## 5. "Redirect to Next page" (<<extend>> credentials valid) & "Returns: JWT token"
* **JWT Generation**: `JwtAuthService` generates a stateless JWT. The `ApplicationUser` model implements `JWTSubject` to natively embed the user's roles and branch ID into the token payload.
* **Return Output**: The controller returns the JWT token (`return response()->json(['success' => true, 'data' => $result]);`). The "Redirect to Next page" step is handled exclusively by the Flutter mobile client upon receiving this 200 OK response.
