# Architecture and Technology

## 1. Recommended application shape

Start as a **modular monolith** in one Laravel repository. Do not split into microservices for the MVP.

- Laravel 13: domain logic, authentication, database, queues, storage, policies, routes.
- Filament 5: `/admin` panel for staff operations.
- Inertia.js + Vue 3: candidate portal and exam-taking experience.
- MySQL/MariaDB: persistent storage.
- Laravel Excel 4.x: workbook parsing and template export.
- Laravel Storage: private media files.
- Pest or PHPUnit: backend tests; Vitest for Vue unit tests if frontend logic warrants it; Playwright or browser verification for end-to-end flows.

Admin and candidate UI can coexist: Filament is a server-driven admin panel; Inertia/Vue powers the custom exam experience. They do not need to be forced into one frontend framework.

## 2. Suggested domain modules

- Identity: users, roles, authentication, participant profile.
- QuestionBank: question packages, questions, media metadata, publish/duplicate.
- Import: upload sessions, staged rows, workbook parsing, archive extraction, validation, commit.
- Exam: exam configuration, availability, attempt lifecycle, snapshot, autosave, timer, submit, grading.
- Reporting: attempt list, score summaries, exports.
- Audit: sensitive admin activity and package publication history.

## 3. Suggested code organization

Follow Laravel's conventional directories. Add domain-oriented folders only where they improve clarity:

```text
app/
  Actions/
    Imports/ParseQuestionImport.php
    Imports/ValidateQuestionImport.php
    Imports/CommitQuestionImport.php
    Exams/StartExamAttempt.php
    Exams/SaveExamAnswer.php
    Exams/SubmitExamAttempt.php
    Exams/GradeExamAttempt.php
  Enums/
  Filament/Resources/
  Http/Controllers/
  Http/Requests/
  Http/Resources/
  Jobs/
  Models/
  Policies/
  Services/
resources/js/
  Pages/
    Candidate/
    Exam/
  Components/
    exam/
  composables/
  layouts/
routes/
  web.php
  candidate.php (optional if route file is registered)
  api.php (only if a real external/mobile API is needed)
```

Keep controllers thin. Put import/exam business rules in testable Actions or Services. Do not create generic repositories for every Eloquent model without a concrete need.

## 4. Request lifecycle

### Admin import
Browser → authenticated Filament action/page → upload validation → private staging storage → workbook parser → ZIP validation/extraction → staged rows → preview/error report → explicit transaction commit → draft package/questions → audit event.

### Candidate exam
Vue/Inertia page → Laravel route/controller → policy/ownership check → exam action → server-generated snapshot → sanitized participant resource (no key) → Vue UI. Every answer update and final submit is revalidated by server.

## 5. Queue and background jobs

For an initial small import, parsing may be synchronous only if file size and row count are strictly bounded and UX stays responsive. Preferred design: create an import batch and dispatch a queue job for parsing/validation; UI polls batch status. Use database queue for low-complexity hosting if supported. If queue worker is unavailable on shared hosting, implement a synchronous bounded mode or scheduled worker strategy, with documented limits. Do not assume Redis is available.

## 6. Package selection and version rules

- Use Laravel 13 only after confirming PHP 8.3+ and required PHP extensions on development and production environments.
- Filament 5 currently documents compatibility with PHP 8.2+ and Laravel 11.28+, but verify all package constraints together with the chosen Laravel version.
- Laravel Excel 4.x documents PHP 8.3+ and Laravel 12/13 support; check `php_zip`, XML, GD, iconv, simplexml, XMLReader, and zlib extensions.
- Use `composer show`, `composer why-not`, and official docs rather than copying version pins from old tutorials.
- After scaffolding, install Laravel Boost as a development dependency and run `php artisan boost:install` if it supports the installed Laravel/Antigravity workflow. Enable Laravel and Filament skills when available. This complements, not replaces, the project's custom `.agents/skills`.

## 7. Frontend rules

- Use Inertia navigation for page-to-page SPA behavior; avoid full reload unless a file download or explicit navigation requires it.
- Candidate exam components must be isolated from Filament internals.
- State that affects grading is persisted to the server; client state is only presentation/cache.
- Use stable IDs for questions, not just visible numbers.
- Countdown uses server `expires_at`; render remaining seconds from a synchronized server timestamp.

## 8. Hosting strategy

Use local private storage and MySQL first for simple deployment, but validate shared hosting limitations before development lock-in. If background queue workers, symlinks, or large uploads are unavailable, adapt within documented bounds. Do not expose the whole project root as public web root; only Laravel `public/` should be web-accessible.
