Develop a fully functional MVP for a "Smart Decision Assistant" (SDA) web application. The core goal is to help users simulate major financial decisions like buying a home and selling investments, visualizing the outcomes.
**Technology Stack**: Next.js 14+ (App Router), TypeScript, Tailwind CSS, Drizzle ORM, PostgreSQL database, NextAuth.js for authentication (email/password).
**Database Schema (Drizzle ORM)**:
* `users` table: `id` (string, uuid, primary key), `email` (string, unique), `passwordHash` (string), `createdAt` (timestamp), `updatedAt` (timestamp).
* `financial_assets` table: `id` (string, uuid, primary key), `userId` (string, foreign key to users.id), `name` (string), `type` (string enum: 'Stock', 'ETF', 'HYSA', 'Roth IRA', 'Other'), `currentValue` (decimal), `purchasePrice` (decimal, nullable, for capital gains calculation), `contributionAmount` (decimal, nullable, for recurring contributions).
* `liabilities` table: `id` (string, uuid, primary key), `userId` (string, foreign key to users.id), `name` (string), `type` (string enum: 'Mortgage', 'Loan', 'Credit Card', 'Other'), `outstandingBalance` (decimal), `monthlyPayment` (decimal, nullable), `interestRate` (decimal, nullable).
* `property_considerations` table: `id` (string, uuid, primary key), `userId` (string, foreign key to users.id), `name` (string), `price` (decimal), `downPaymentPercentage` (decimal, e.g., 0.20 for 20%), `interestRate` (decimal), `loanTermYears` (integer), `hoaMonthly` (decimal), `propertyTaxMonthly` (decimal), `insuranceMonthly` (decimal, nullable).
* `scenarios` table: `id` (string, uuid, primary key), `userId` (string, foreign key to users.id), `name` (string), `description` (text, nullable), `selectedPropertyId` (string, foreign key to property_considerations.id), `downPaymentAmount` (decimal), `assetsSoldDetails` (jsonb: array of `{ assetId: string, amount: decimal, capitalGains: decimal, type: string }`), `monthlyMortgagePayment` (decimal), `totalMonthlyHousingCost` (decimal), `estimatedCapitalGainsTax` (decimal), `remainingLiquidAssets` (decimal), `projectedRetirementImpact` (text), `createdAt` (timestamp), `updatedAt` (timestamp).
**Project Structure**: Adhere to Next.js App Router conventions (e.g., `app/`, `lib/db.ts`, `lib/schema.ts`, `components/`, `app/api/`).
**Authentication (NextAuth.js)**: Implement secure email/password authentication. Users must be logged in to access and manage their financial data and scenarios.
**Core Pages & Functionality (Multi-page application)**:
1. **`/` (Dashboard)**: A user dashboard displaying a summary of their aggregated financial assets, total liabilities, and quick links to manage data or create new scenarios.
2. **`/assets` (Financial Assets Management)**:
* Display a paginated list of the authenticated user's financial assets.
* **CRUD**: Allow adding new assets (name, type, current value, optional purchase price, optional recurring contribution amount).
* **CRUD**: Enable editing and deleting existing assets.
3. **`/liabilities` (Liabilities Management)**:
* Display a list of the authenticated user's liabilities.
* **CRUD**: Allow adding new liabilities (name, type, outstanding balance, optional monthly payment, optional interest rate).
* **CRUD**: Enable editing and deleting existing liabilities.
4. **`/properties` (Property Considerations Management)**:
* Display a list of potential properties the user is considering.
* **CRUD**: Allow adding new properties (name, price, desired down payment percentage, estimated interest rate, loan term in years, monthly HOA, monthly property tax, optional monthly insurance).
* **CRUD**: Enable editing and deleting existing properties.
5. **`/scenarios` (Scenario Planning)**:
* Display a list of previously created scenarios by the user.
* **`/scenarios/new` (Create New Scenario)**: This is the core functionality.
* **Step 1: Property Selection**: User selects one `PropertyConsideration` from their saved list via a dropdown.
* **Step 2: Down Payment Input**: User specifies the exact `downPaymentAmount` for the selected property. This can be more or less than the `downPaymentPercentage` defined in the `PropertyConsideration`.
* **Step 3: Asset Selling Strategy**: User interactively selects `FinancialAsset`s from their list to sell and specifies the `amount` to sell from each asset to meet the `downPaymentAmount`. The UI should dynamically update to show remaining down payment needed and remaining asset values. If `purchasePrice` is available, calculate potential capital gains for each selected asset (e.g., `(amountSold / currentValue) * (currentValue - purchasePrice)`).
* **Step 4: Calculations & Summary**: Upon submission, perform the following calculations on the server-side via an API route:
* **Loan Amount**: `PropertyConsideration.price - downPaymentAmount`
* **Monthly Mortgage Payment (P&I)**: Use the standard amortizing loan formula: `M = P [ i(1 + i)^n ] / [ (1 + i)^n – 1]` where `P` is loan amount, `i` is monthly interest rate (`PropertyConsideration.interestRate / 12`), `n` is total number of payments (`PropertyConsideration.loanTermYears * 12`).
* **Total Monthly Housing Cost**: Sum of `Monthly Mortgage Payment + PropertyConsideration.hoaMonthly + PropertyConsideration.propertyTaxMonthly + PropertyConsideration.insuranceMonthly`.
* **Estimated Capital Gains Tax**: Sum of capital gains from all sold assets, multiplied by a simplified flat tax rate (e.g., 15%).
* **Remaining Liquid Assets**: The total value of all assets not sold in the scenario.
* **Projected Retirement Impact**: A textual assessment (e.g., "Selling Roth IRA assets may incur penalties and reduce future retirement savings.") based on the types of assets sold and their original contribution amounts.
* **Step 5: Display Re