# Architecture overview (Phase 1 scaffold)

Modular monolith; Laravel API + Vue SPA served from the same origin.

```mermaid
flowchart LR
  B[Vue SPA] -->|cookie + XSRF header| MW[Request id, security headers, throttle]
  MW --> AUTH[auth:sanctum]
  AUTH --> CTX[company.context]
  CTX --> FR[FormRequest] --> C[Controller] --> R[API Resource] --> B
  C --> M[Eloquent models + CompanyScope] --> DB[(MySQL)]
```

## Decisions made in this scaffold (see SRS assumptions A1–A9)

- **Tenancy (A1):** `company_id` on tenant tables; `BelongsToCompany` adds a global `CompanyScope` that returns **no rows**
  when no company context is set; `company_id` is never mass-assignable. `CompanyContext` is a scoped service.
  Login resolves the single active company; several active companies is an explicit error (not guessed).
- **Auth provider exception:** `CompanyAwareUserProvider` lets the guard load users by id/credentials without a context;
  every other `User` query stays scoped. Login credentials include `company_id` and `status = active`.
- **RBAC:** `permission = module.resource.action`, role grants carry scope `own|team|company`, widest scope wins,
  deny by default (`PermissionResolver`). Only permissions that guard something existing are seeded.
- **SPA (A4):** Vite builds into `public/build`; `routes/web.php` serves one Blade shell for client routes and excludes
  `api/*`, `sanctum/*`, `up` so unknown API paths return JSON 404.
- **Frontend stack:** Vue 3 `<script setup>` + TypeScript strict, Pinia, Vue Router, vue-i18n (en), Tailwind CSS 4.
  Route guards are UX only. TanStack Query and form libraries from the plan are added when the first data screens need them.

## Deviations from the approved plan (to confirm)

1. **PHPUnit instead of Pest** for now (Pest/plugin versions could not be resolved without Composer here). Tests are plain
   PHPUnit classes that Pest can run unchanged; switching is a `composer require --dev` away.
2. **No CSP header yet** (needs a nonce strategy that works with Vite dev + build); basic security headers are set.
3. **Audit, MFA and password-reset are now implemented** (this foundation step). Still open in Phase 1: company settings screens and e-mail verification.
4. **No CSP header yet**, and the PHPUnit/Pest decision above still stands.
