# New Project Feasibility (2026-10-16)

Third module of **Analyze Property → New Project Analysis** (Projects · Layout ROI Summary ·
**New Project Feasibility**). Route prefix `/analyze-property/feasibility`, feature
`Feature::NEW_PROJECT_FEASIBILITY` (open by default; gate it on the Function access matrix).

## What it does

A member defines a project that is **not in our catalogue** and reads it through the **same
project page a launch has** — Overview, Units · Price, Investment Analysis, Financial Projection,
New Supply, Amenities, Developer:

- **Location** — a pin (the Subsale tab's `LocationPicker`), in any market `ListsAnalysisMarkets`
  offers (the Subsale tab's list, shared).
- **Developer** — picked from the directory (`Developer::searchMain()`, the admin picker's query),
  so the Developer tab shows that developer's real published projects and other records
  (`FindDeveloperTrackRecord`, grouped by pivot name like a launch's).
- **Layouts** — name, built-up, price, bedrooms, bathrooms, car parks, units, an optional **plan
  drawing**, and **dual key**: one room type per key plus each key's area. Uploading a plan for a
  dual key asks AI to split the built-up between the keys (`KeySizeEstimator`, the estimator the
  catalogue's dual keys are sized with) and fills the boxes, marked "AI estimate · n%"; typing a size
  marks it typed. No sizes → each key is priced on its room type's median rent.
- **Loan** — margin of finance %, rate, tenure (prefilled from the market's `financing()`), passed as
  the page's `loanTerms`, so every calculator on the result page lends on them.

## How it works

**One page, two data sources.** `ProjectDetailContent` builds its lazy fetches from `detail.slug`
(`/{country}/projects/{slug}/analysis|unit-rental|supply|amenity-demand`). It now takes an
`endpoints` prop (declared in `projectDetailProps.js`, null for catalogue projects) and a study passes
its own routes. Everything else on the page is unchanged.

**In-memory catalogue models.** The analysis code takes `CatalogProject` / `CatalogFloorPlan`. A
study hands it UNSAVED ones — `FeasibilityStudy::toCatalogProject()` and
`FeasibilityLayout::toFloorPlan()` — carrying only what the study states (lat/lng, country,
key_bedrooms, key_sqft …). Never `save()` them. That is what lets the engine, `FindNearbyProjectSupply`,
`LayoutRent` (the dual-key sum) and `KeySizeEstimator` run unchanged.

| Tab | Server | Notes |
|---|---|---|
| Overview / Units · Price | `BuildFeasibilityPage` → `detail` in `CatalogueDetailService::forSlug()`'s shape | No photos (hero = plan drawings), no facilities, no sale history, no VR. `shortlisted: null` hides the save star. |
| Investment Analysis / Financial Projection | `RunFeasibilityAnalysis` (`GET {id}/analysis?floor_plan=`) | Same engine call and wrapper as `ProjectDetailController::buildAnalysis`, **no `catalog_project_id`** (anchors on the nearest project), `MarketSourceOverlay` applied, `OwnProjectPricing` not (a study has no own listings). Cached a day by its inputs, not stored. Rent is computed in the browser by `petaLayoutRent` from the floor plan's `key_bedrooms` / `key_sqft`; `predicted_rent` + `keys` are added for non-JS clients. |
| New Supply | `FindNearbyProjectSupply::execute(toCatalogProject())` | Master connection; `id` null → `whereNotNull`, so nothing is excluded. |
| Amenities | `GenerateFeasibilityLocationInsight` | Same three parts as a launch's (`GenerateAmenityDemand`, `CatalystScoreService`, `LocationOutlookService`), cached by rounded coordinates, not stored (`LocationInsightStore` keys on a catalogue row). Malaysia only for the narrative. |
| Developer | `FindDeveloperTrackRecord` | Published cards (8) + unpublished records (24 shown, all counted). |
| unit-rental | returns `available: false` | A study's layouts always have price + size, so the deep analysis answers first. |

**Dual key whole-unit bedrooms.** The builder sends a dual key's `bedrooms` as the keys' sum with a
studio counted as 1 (studio + 2-bed = 3) — the bedroom count the engine reads the SALE comparables
on. The rent never uses it: it is the sum of the keys.

**Storage.** `feasibility_studies` (lead-owned, soft deletes, blame) + `feasibility_layouts`
(`key_bedrooms`, `key_sqft` JSON, `key_sqft_source` typed|ai, confidence, basis). Plan drawings are
`Media` on the layout, collection `feasibility-floor-plan`, stored after the commit; a replaced or
removed drawing is deleted afterwards (`FeasibilityStudyRepository`). Edits SYNC layouts: a row with
a known uuid updates, a new row is added, a missing one is deleted.

**Ownership.** Every route resolves the study by uuid AND the member's `lead_id`; anyone else's is 404.

## Related files

- Routes: `routes/main.php` — the `analyze-property/feasibility` group (before `analyze-property/{id}`).
- [`app/Http/Controllers/Main/Portal/FeasibilityController.php`](/app/Http/Controllers/Main/Portal/FeasibilityController.php)
- [`app/Http/Controllers/Concerns/ListsAnalysisMarkets.php`](/app/Http/Controllers/Concerns/ListsAnalysisMarkets.php) — shared with `SubsaleAnalysisController`.
- `app/Http/Requests/Main/Portal/Feasibility/{Store,Update,EstimateKeys}Request.php`
- [`app/Actions/BuildFeasibilityPage.php`](/app/Actions/BuildFeasibilityPage.php), [`RunFeasibilityAnalysis.php`](/app/Actions/RunFeasibilityAnalysis.php), [`GenerateFeasibilityLocationInsight.php`](/app/Actions/GenerateFeasibilityLocationInsight.php), [`FindDeveloperTrackRecord.php`](/app/Actions/FindDeveloperTrackRecord.php)
- [`src/Analysis/FeasibilityStudy.php`](/src/Analysis/FeasibilityStudy.php), [`FeasibilityLayout.php`](/src/Analysis/FeasibilityLayout.php), [`Repositories/FeasibilityStudyRepository.php`](/src/Analysis/Repositories/FeasibilityStudyRepository.php)
- `database/migrations/2026_10_16_120000_create_feasibility_studies.php`
- `resources/js/Pages/Main/Portal/AnalyzeProperty/Feasibility/{Index,Edit,Show}.vue`
- Shared pieces changed: `ProjectDetailContent.vue` + `projectDetailProps.js` (`endpoints`),
  `KeySizeEstimator::estimate($plan, ?$attachments)`, `Developer::searchMain()`, `AnalyzeTabs.vue`.
- Test: `tests/Feature/Main/Portal/Analyze/FeasibilityTest.php`.

**Not built yet:** a study cannot be shared or exported; the developer tab reads the master
catalogue only (wk's own rows are not included, as on a launch's page); a study's amenity narrative
is Malaysia-only.
