Create a full-stack MVP application named 'HomeWise Budget' using Next.js 14 App Router, Drizzle ORM with a PostgreSQL database, and Tailwind CSS. The application should cater to families seeking to manage their finances, plan major purchases like a home, and build savings.
**Application Structure (Next.js App Router):**
1. `/app/layout.tsx`: Root layout with basic navigation (Dashboard, Home Simulator, Emergency Fund, Debt Manager, Settings, Auth).
2. `/app/page.tsx`: Landing page (can be a simple intro page or redirect to dashboard if logged in).
3. `/app/(auth)/register/page.tsx`: User registration page.
4. `/app/(auth)/login/page.tsx`: User login page.
5. `/app/dashboard/page.tsx`: User's financial overview, showing summary of income, expenses, net, debt, and savings progress.
6. `/app/income/page.tsx`: Page to view, add, edit, and delete income entries.
7. `/app/expense/page.tsx`: Page to view, add, edit, and delete expense entries.
8. `/app/home-simulator/page.tsx`: Interactive tool for home purchase simulation.
9. `/app/emergency-fund/page.tsx`: Page to set emergency fund goals and track progress.
10. `/app/debt-manager/page.tsx`: Page to view, add, edit, and delete debt entries.
11. `/app/settings/page.tsx`: User settings (e.g., profile, subscription details).
**Database Schema (Drizzle ORM for PostgreSQL):**
Define the following tables with appropriate fields and relationships.
* `users`: `id` (uuid, primary key), `email` (string, unique), `passwordHash` (string), `createdAt` (timestamp), `updatedAt` (timestamp).
* `incomes`: `id` (uuid, primary key), `userId` (uuid, foreign key to users.id), `amount` (numeric), `source` (string), `date` (date), `createdAt` (timestamp).
* `expenses`: `id` (uuid, primary key), `userId` (uuid, foreign key to users.id), `amount` (numeric), `category` (string), `description` (string), `date` (date), `createdAt` (timestamp).
* `debts`: `id` (uuid, primary key), `userId` (uuid, foreign key to users.id), `name` (string), `type` (enum: 'student_loan', 'credit_card', 'car_loan', 'other'), `totalAmount` (numeric), `currentBalance` (numeric), `monthlyPayment` (numeric), `interestRate` (numeric), `createdAt` (timestamp).
* `savingsGoals`: `id` (uuid, primary key), `userId` (uuid, foreign key to users.id), `name` (string), `targetAmount` (numeric), `currentAmount` (numeric, default 0), `deadline` (date, nullable), `type` (enum: 'emergency_fund', 'down_payment', 'retirement', 'other'), `createdAt` (timestamp).
* `homeSimulations`: `id` (uuid, primary key), `userId` (uuid, foreign key to users.id), `name` (string), `purchasePrice` (numeric), `downPaymentPercentage` (numeric), `interestRate` (numeric), `loanTermYears` (integer), `monthlyMortgageEstimate` (numeric, calculated), `propertyTaxEstimate` (numeric), `insuranceEstimate` (numeric), `createdAt` (timestamp).
**API Routes (Next.js API Routes in `app/api` directory):**
Implement full CRUD operations for all user-specific data, protected by authentication.
* `/api/auth/register` (POST)
* `/api/auth/login` (POST)
* `/api/auth/logout` (POST)
* `/api/income` (GET, POST)
* `/api/income/[id]` (GET, PUT, DELETE)
* `/api/expense` (GET, POST)
* `/api/expense/[id]` (GET, PUT, DELETE)
* `/api/debt` (GET, POST)
* `/api/debt/[id]` (GET, PUT, DELETE)
* `/api/saving-goal` (GET, POST)
* `/api/saving-goal/[id]` (GET, PUT, DELETE)
* `/api/home-simulation` (GET, POST)
* `/api/home-simulation/[id]` (GET, PUT, DELETE)
**Frontend Implementation (React with Next.js & Tailwind CSS):**
* **Authentication**: Implement user registration and login forms with client-side validation using Zod. Securely handle sessions (e.g., using `next-auth` or simple JWTs with cookies).
* **Dashboard**: Display a summary of user's financial data. Calculate and show:
* Total monthly income.
* Total monthly expenses.
* Net monthly income.
* Current debt balance vs. total debt.
* Progress towards primary savings goal (e.g., emergency fund).
* Visually represent these using simple charts/progress bars.
* **Income/Expense Pages**:
* Forms to add new income/expense entries.
* Display lists of all entries, sortable by date/category.
* Edit and Delete functionality for individual entries.
* Basic filtering by category/date range.
* **Debt Manager**:
* Form to add/edit/delete debt entries.
* List all debts, showing name, type, total amount, current balance, monthly payment, and interest rate.
* Calculate and display total monthly debt payments.
* **Emergency Fund Planner**:
* Form to set a target amount and optional deadline.
* Display current balance and progress percentage.
* Allow users to record contributions to the fund.
* **Home Simulator**:
* An interactive form allowing users to input: purchase price, down payment percentage, interest rate, and loan term (years).
* Calculate and display estimated monthly mortgage payment.
* Include fields for estimated property tax and insurance.
* Display total cost over the loan term.
* **Crucially**: Incorporate a simple amortization schedule visualization (table or chart) showing principal and interest breakdown over time.
* Ability to save multiple simulation scenarios.
**General Requirements:**
* Use TypeScript throughout.
* Implement robust error handling on both frontend and backend.
* Ensure data validation on API routes (e.g., using Zod).
* Styling using Tailwind CSS for a clean, responsive, and modern UI.
* Make sure all functionalities involve interaction with the database.
* The application should be a multi-page application, not a SPA.
* Database connection setup for Drizzle with PostgreSQL (e.g., using `dotenv` for credentials).
* Include basic project setup instructions for running locally.
* **Do not generate a static landing page. Focus on the core application features.**