# Auth Reference

Use `auth` as the primary architecture reference when you need a feature that demonstrates the full layering pattern.

Recommended split:

```text
src/features/auth/
  model/
    types.ts
    constants.ts
    storage.ts
    validation.ts
    AuthContext.tsx
  controller/
    useLoginController.ts
  services/
    mockAuthService.ts
  view/
    LoginForm.tsx
```

Use this flow:

1. `view/LoginForm.tsx` renders fields and delegates user actions.
2. `controller/useLoginController.ts` owns form state, validation triggering, submit status, and navigation side effects.
3. `model/validation.ts` validates input shape and returns field/form errors.
4. `services/mockAuthService.ts` performs async authentication logic or simulates it.
5. `model/AuthContext.tsx` owns session state, persistence boundaries, and auth lifecycle.
6. `app/routes/ProtectedRoute.tsx` consumes the provider and protects authenticated routes.

Service boundary rules:

- Put async auth calls in `services`, not in the view and not directly in the router.
- Keep mock services realistic enough to demonstrate orchestration boundaries.
- Let the controller call the service and then update the provider state.
- Keep storage helpers in `model` when they are part of the feature's local domain state contract.

This is the best reference in the project for showing why `services` exists and how it interacts with `model` and `controller`.
