Create a full-stack web application MVP using Next.js App Router, TypeScript, and Drizzle ORM with PostgreSQL. The application should be a 'Financial Aid Assistant' designed to help elderly individuals and their caregivers manage finances, understand debt, and access aid programs.
**Core Features:**
1. **User Authentication:** Secure signup/login system (email/password, potentially social login).
2. **Financial Dashboard:** Allow users to input income (Social Security, retirement funds, etc.) and expenses (rent, utilities, food, credit card minimums, payday loans).
3. **Asset Protection Analysis:** Implement logic to analyze different income sources (like Social Security, retirement funds) and determine their vulnerability to debt collectors based on US federal and Missouri state laws. Display a clear 'Protection Status' for each income source.
4. **Debt Management Module:** Allow users to list their debts (credit cards, payday loans) with details like balance, interest rate, and minimum payment. Provide basic debt payoff strategy suggestions (e.g., snowball, avalanche).
5. **Aid Program Database:** A searchable database of federal and state (Missouri focus) aid programs for seniors (e.g., LIHEAP for utilities, SNAP for food, housing assistance). Include program descriptions, eligibility criteria, and links to official application portals.
6. **Personalized Recommendations:** Based on user's financial situation and inputted data, recommend relevant aid programs and potential debt management strategies.
**Technical Stack & Architecture:**
* **Framework:** Next.js 14 (App Router).
* **Language:** TypeScript.
* **ORM:** Drizzle ORM.
* **Database:** PostgreSQL (hosted locally for MVP development, assume cloud deployment for production).
* **UI:** Tailwind CSS for styling.
* **State Management:** React Context API or Zustand for simpler state needs.
**Project Structure (App Router):**
* `app/`
* `layout.tsx` (Root layout)
* `page.tsx` (Homepage/Dashboard)
* `auth/` (Login, signup pages)
* `dashboard/`
* `page.tsx` (Main dashboard view)
* `finance/`
* `income/` (CRUD for income sources)
* `expenses/` (CRUD for expenses)
* `debts/` (CRUD for debts)
* `analysis/` (Display asset protection analysis)
* `aid-programs/` (Search and display aid programs)
* `api/`
* `auth/` (Auth routes)
* `finance/` (Income, expense, debt CRUD routes)
* `aid-programs/` (Data fetching routes)
* `components/` (Reusable UI components)
* `lib/` (Utility functions, DB connection, Drizzle schema definitions)
* `db/` (Drizzle schema definitions)
* `styles/` (Global styles)
**Database Schema (Drizzle):**
* `users` table: `id`, `email`, `passwordHash`, `createdAt`, `updatedAt`
* `income_sources` table: `id`, `userId`, `name`, `amount`, `sourceType` (e.g., 'Social Security', 'Retirement Fund', 'Pension'), `protectionStatus` (enum: 'Protected', 'Partially Protected', 'Vulnerable'), `createdAt`, `updatedAt`
* `expenses` table: `id`, `userId`, `description`, `amount`, `category` (e.g., 'Rent', 'Utilities', 'Food', 'Credit Card Minimum'), `date`, `createdAt`, `updatedAt`
* `debts` table: `id`, `userId`, `name`, `balance`, `interestRate`, `minimumPayment`, `createdAt`, `updatedAt`
* `aid_programs` table: `id`, `name`, `description`, `eligibilityCriteria`, `applicationUrl`, `relevantJurisdiction` (e.g., 'Federal', 'Missouri'), `programType` (e.g., 'Housing', 'Food', 'Utility'), `createdAt`, `updatedAt`
**API Routes (Example for Income CRUD):**
* `POST /api/finance/income`: Create new income source.
* `GET /api/finance/income`: Get all income sources for the logged-in user.
* `GET /api/finance/income/[id]`: Get a specific income source.
* `PUT /api/finance/income/[id]`: Update a specific income source.
* `DELETE /api/finance/income/[id]`: Delete a specific income source.
**Backend Logic:**
* Implement robust input validation on all API routes.
* Ensure all database operations are atomic and handle errors gracefully.
* The 'Asset Protection Analysis' should call a backend function (potentially within an API route or a server action) that uses the `income_sources` data and predefined rules (based on the prompt's legal context) to calculate and update the `protectionStatus` field. This function might need to be triggered periodically or upon changes in income data.
* The 'Aid Program Database' should be seeded with initial data. API routes should support filtering and searching based on criteria like `relevantJurisdiction` and `programType`.
**MVP Scope:** Focus on delivering the core functionality described above. Ensure a smooth user experience for the MVP. No external integrations beyond basic database and Next.js features are required for the MVP. The goal is a functional, multi-page application with full CRUD operations for key financial data and informative displays for analysis and aid programs.