# Jobbjakt Architecture Evolution

## Guiding constraints

- Preserve the existing single-master-profile model.
- Keep job applications and their workflow at the centre of the domain.
- Make AI providers replaceable and optional.
- Add SaaS foundations without prematurely building a billing platform or team product.
- Keep feature slices small while reducing the current controller concentration.

## Target boundaries

```text
Web UI
  -> Application APIs
      -> Application workflow domain
      -> Career profile and document domain
      -> Discovery provider adapters
      -> Connected-account adapters
      -> AI provider boundary
      -> Entitlements and usage policy
```

### Career profile and documents

`ApplicationUser.ProfileCvStructureJson` remains the canonical master profile during the transition. A later migration may normalize high-change sections (projects and portfolio items) into user-owned tables, but generated CVs and application-specific drafts must remain immutable copies with a profile-version reference.

### Discovery

Create an `IJobDiscoveryProvider` contract with normalized query and result types. Providers own authentication, source-specific filters, terms-aware attribution, and mapping. The UI and import flow must not know provider payload shapes. Cache public results briefly, do not persist an external job until the user imports it.

### AI

Extract AI prompts and model transport from controllers behind task-focused interfaces: CV extraction, CV tailoring, draft generation, interview preparation, and summarization. Each request records provider, model, input profile version, job context, and user review state. Local and online providers implement the same boundary.

### Entitlements

Introduce account-level plan, entitlement, and usage-ledger records before payment integration. Product code checks named capabilities (for example `ai.tailor_cv`, `cv.premium_theme`, `storage.attachments`) rather than payment-provider state. This supports trials, manual access, subscriptions, and future organisation plans.

## Incremental engineering work

1. Add targeted feature services beside the existing controllers for every touched feature; do not attempt a big-bang controller rewrite.
2. Replace local-only preferences that affect behaviour with user-owned persisted settings.
3. Replace the in-memory CV queue with a database-backed work item before horizontal hosting.
4. Use PostgreSQL for hosted multi-tenant deployment; retain SQLite for self-hosted/single-user deployments.
5. Add provider health, job processing, AI usage, and entitlement audit telemetry before paid hosting.

## Explicit non-goals for the first SaaS release

- Teams/organisations and shared candidate data.
- Auto-apply automation or scraping-proxy infrastructure.
- A browser-extension marketplace release.
- A billing-provider integration before commercial policy is decided.
