# Laravel version – migration plan

This document describes how to run the **Boundary Commission** application as a **Laravel** (PHP) codebase, matching the current FastAPI + Next.js features.

---

## Do we have everything from FastAPI + Next.js in Laravel?

**No.** The Laravel skeleton only has a **subset** of the backend (landing + basic auth). The rest of the API and the whole Next.js frontend are not yet in Laravel.

| Area | FastAPI + Next.js | In Laravel? |
|------|-------------------|-------------|
| **Landing API** | GET /landing, admin CRUD (hero, stats, services block, cards, contact) | ✅ Yes |
| **Auth** | Login, refresh, me, logout | ✅ Login, me, logout. ❌ Refresh token flow |
| **Auth admin** | Users list/create/patch/delete, roles, groups, assign roles | ❌ No |
| **Boundary API** | Boundaries list/detail, disputes list/detail, document upload/list/PDF | ❌ No |
| **Documents / LRS** | Search, PDF by ID/number, metadata, lookup, LRS endpoints, cache, convert, etc. | ❌ No |
| **Dictionary** | document-types, party-types, legal-roles, genders, transaction-types, etc. | ❌ No |
| **Properties** | properties/search, properties/index, analytics/data-centric | ❌ No |
| **GIS** | properties/geojson, boundaries/geojson, qgis/connect | ❌ No |
| **Cashier** | payment, fees, payments | ❌ No |
| **Schema / health** | /schema, /health, / | ❌ No |
| **Next.js frontend** | Full SPA: landing, login, dashboard, workstations, boundary upload, etc. | ❌ No (no Blade/Inertia port) |

To have “everything” in Laravel you would need to port the above incrementally (see “To add (incremental)” below and the FastAPI routes in `backend/app/main.py`, `backend/api/boundary.py`).

---

## Current stack (to replicate)

| Area | Current (FastAPI + Next.js) | Laravel equivalent |
|------|-----------------------------|---------------------|
| **Backend** | FastAPI (Python), Gunicorn | Laravel (PHP), PHP-FPM / `php artisan serve` |
| **Auth** | JWT (access + refresh), bcrypt, roles | Laravel Sanctum (API tokens) or Passport; Laravel auth + roles |
| **Landing** | MySQL tables, GET /landing, admin CRUD | Laravel migrations, API resources, admin routes |
| **Boundary / Disputes** | FastAPI routers, MySQL | Laravel API controllers, Eloquent models |
| **Documents / LRS** | FastAPI endpoints, contentstore | Laravel controllers, same DB + storage |
| **Frontend** | Next.js (React) SPA | Option A: Keep Next.js talking to Laravel API. Option B: Laravel Blade + Livewire/Alpine. Option C: Laravel + Inertia.js + React |

---

## Laravel app location

The repo includes a **Laravel skeleton** in **`boundary-laravel/`** with:

- Landing page API (public GET + admin CRUD) and migrations
- Auth API (login, refresh, me, logout) using Laravel Sanctum
- Same MySQL schema (landing tables; optional migration for existing `alf_authority` / `plg_user_credentials`)

You can:

1. **Use the skeleton in-repo:** `cd boundary-laravel && composer install`, then configure `.env` and run migrations.
2. **Start from a fresh Laravel install:** `composer create-project laravel/laravel my-boundary-laravel`, then copy in the migrations, models, and controllers from `boundary-laravel/` (see README there).

---

## Feature mapping (current → Laravel)

### Done in skeleton

- **Landing**
  - Tables: `landing_hero`, `landing_stats`, `landing_services_block`, `landing_service_cards`, `landing_contact`
  - Public: `GET /api/landing` (or `GET /landing` in API)
  - Admin: CRUD for hero, stats, services block, service cards, contact (Sanctum-protected)

- **Auth**
  - Login (issue token), refresh token, `/me`, logout
  - Roles: map to Laravel roles/permissions or keep existing `alf_authority` tables and use them in middleware

### To add (incremental)

- **Boundary Commission API:** boundaries list/detail, disputes list/detail, document upload/list/PDF (port FastAPI `backend/api/boundary.py` to Laravel controllers).
- **Documents / LRS:** document search, PDF by ID/number, contentstore paths (port relevant FastAPI routes to Laravel).
- **Dashboard / workstations:** if frontend stays Next.js, point it at Laravel API; if you move to Blade/Inertia, rebuild dashboard in Laravel.

---

## Deployment (Laravel)

- **Web server:** Nginx or Apache; document root = `boundary-laravel/public`; PHP-FPM.
- **Env:** `APP_KEY`, `DB_*`, `SANCTUM_STATEFUL_DOMAINS` (if SPA).
- **After deploy:** `php artisan migrate`, `php artisan config:cache`, `php artisan route:cache`.
- Optional: Queue worker, scheduler (`php artisan schedule:work`) if you add jobs later.

---

## Summary

- **`boundary-laravel/`** = Laravel version of the app with landing + auth implemented.
- **This doc** = plan to move the rest of the features (boundary, disputes, documents, etc.) from FastAPI to Laravel step by step.
- **Frontend:** Either keep the existing Next.js app and switch its API base URL to the Laravel backend, or replace it later with Laravel Blade/Inertia.
