# Migration Evidence Builder (V1)

`migration_evidence_builder` is a CLI-first Flask app module for manually ingesting applicant migration evidence files, processing them into reusable structured formats, and generating sponsor visa preparation support outputs.

## Scope (V1)

- No frontend/UI.
- Local folder-based processing.
- No visa approval decision logic.
- No migration legal advice.
- No final PDF rendering.
- No multi-user auth.

The app is designed to support subclass `482` and `186` workflows while clearly separating:

- verified evidence
- inferred suggestions
- missing evidence

## App Layout

```text
apps/migration_evidence_builder/
  api/v1/blueprint.py
  cli/runner.py
  services/
    intake_service.py
    extraction_service.py
    canonical_service.py
    timeline_service.py
    occupation_service.py
    checklist_service.py
    report_service.py
  schemas/templates/
  templates/sample_outputs/
  README.md
```

## Storage Layout

Per applicant root:

```text
storage/applicants/<applicant_id>/
  applicant.json
  intake/
    identity/
      passport/
        YYYY-MM-DD_passport-bio-page/
          original.pdf
    education/
    employment/
    translations/
  identity/<subcategory>/<document_folder>/
  education/<subcategory>/<document_folder>/
  employment/<subcategory>/<document_folder>/
  translations/<subcategory>/<document_folder>/
  generated/
    timeline.md + timeline.json
    checklist.md + checklist.json
    occupation_analysis.md + occupation_analysis.json
    cv.md
    gap_report.md
    chatgpt_briefing_pack.md + chatgpt_briefing_pack.json
```

Per document folder:

```text
<category>/<subcategory>/<document_folder>/
  original/
    original.<ext>
  extracted/
    document.json
    entities.json
    quality.json
  summary/
    summary.md
  meta/
    manifest.json
```

## CLI Commands

Run from project root (`/var/www/html/flask_server`):

```bash
python -m apps.migration_evidence_builder.cli.runner init-applicant --applicant case_001 \
  --full-name "Jane Doe" \
  --sponsor-name "Example Sponsor Pty Ltd" \
  --nominated-occupation "Software Engineer"

python -m apps.migration_evidence_builder.cli.runner scan-intake --applicant case_001
python -m apps.migration_evidence_builder.cli.runner process-documents --applicant case_001
python -m apps.migration_evidence_builder.cli.runner build-timeline --applicant case_001
python -m apps.migration_evidence_builder.cli.runner analyze-occupations --applicant case_001
python -m apps.migration_evidence_builder.cli.runner generate-cv --applicant case_001
python -m apps.migration_evidence_builder.cli.runner generate-gap-report --applicant case_001
python -m apps.migration_evidence_builder.cli.runner generate-chatgpt-pack --applicant case_001
python -m apps.migration_evidence_builder.cli.runner generate-checklist --applicant case_001
python -m apps.migration_evidence_builder.cli.runner confirm-document --applicant case_001 \
  --document-path identity/passport/2026-04-13_passport-bio-page \
  --field owner.full_name \
  --field identifiers.passport_number \
  --field identifiers.personal_number \
  --field issuing_authority \
  --note "Confirmed against original PDF" \
  --by cgarcia
```

## Integration Notes

- Package exposes `init_app(app)` in `__init__.py` to support future route/admin integration.
- Current route footprint is minimal (`/api/migration-evidence-builder/v1/health`) to keep V1 CLI-first.
- Services are intentionally modular and isolated for future OCR/NER, legal-rule engines, and rendering layers.

## Next Extension Targets

- Real OCR parsers in `extraction_service`.
- Schema validation and strict typing in `models`.
- Route layer for admin review workflows.
- Export adapters (PDF/docx) after output format stabilizes.
