As an expert Next.js developer, create a fully functional MVP web application named 'Tax Path'. This application should help married couples in the US analyze the financial implications of filing taxes jointly versus separately, especially concerning student loan payments. Implement it using Next.js App Router, a multi-page architecture, PostgreSQL with Drizzle ORM, and Tailwind CSS for styling. Ensure full CRUD functionality for user data, financial inputs, and student loan details. The core logic for tax and student loan impact comparison should be implemented server-side within API routes.
**Key Requirements:**
1. **Project Setup:** Initialize a Next.js project with App Router, Drizzle ORM configured for PostgreSQL, and Tailwind CSS.
2. **Database Schema (Drizzle ORM):**
* `users` table: `id` (UUID, PK), `email` (unique), `password_hash`, `created_at`, `updated_at`.
* `finances` table: `id` (UUID, PK), `user_id` (FK to users), `income_spouse1`, `income_spouse2`, `deductions_spouse1`, `deductions_spouse2`, `tax_credits_spouse1`, `tax_credits_spouse2`, `filing_status_preference` (enum: 'joint', 'separate', 'undecided'), `created_at`, `updated_at`. Store all relevant tax-related financial data for both spouses.
* `student_loans` table: `id` (UUID, PK), `user_id` (FK to users), `owner_spouse_id` (enum: 'spouse1', 'spouse2'), `loan_provider`, `original_principal`, `current_principal`, `interest_rate`, `repayment_plan_type` (e.g., 'standard', 'PAYE', 'REPAYE'), `monthly_payment_current`, `created_at`, `updated_at`.
* `scenarios` table: `id` (UUID, PK), `user_id` (FK to users), `scenario_name` (e.g., 'Joint Filing 2023', 'Separate Filing 2023'), `filing_status_used` (enum: 'joint', 'separate'), `estimated_federal_tax_liability`, `estimated_student_loan_payment_impact`, `total_estimated_financial_impact`, `comparison_date`.
3. **Authentication:** Implement basic JWT-based authentication for user registration, login, and session management. Protect relevant routes.
4. **Pages (App Router Structure):**
* `app/page.tsx`: Landing page with a brief explanation of the app's purpose and calls to action (Login/Register).
* `app/dashboard/page.tsx`: A protected page showing an overview for the logged-in user. Initially, prompt to add financial data.
* `app/profile/page.tsx`: Protected. Allows users to view and update their basic user profile information.
* `app/finances/page.tsx`: Protected. A form to input and manage (CRUD) financial data for both spouses (income, deductions, credits).
* `app/student-loans/page.tsx`: Protected. A form/list to input and manage (CRUD) multiple student loan details for each spouse.
* `app/compare/page.tsx`: Protected. This page will display the comparison results between joint and separate filing scenarios. It should have a button to trigger a new comparison based on current financial/loan data.
* `app/history/page.tsx`: Protected. Lists past saved scenarios from the `scenarios` table.
* `app/auth/login/page.tsx`: User login form.
* `app/auth/register/page.tsx`: User registration form.
5. **API Routes (app/api):**
* `app/api/auth/register/route.ts`: POST endpoint to create a new user.
* `app/api/auth/login/route.ts`: POST endpoint to authenticate a user and issue a JWT.
* `app/api/user/route.ts`: GET (fetch user profile), PUT (update user profile). Delete user not required for MVP.
* `app/api/finances/route.ts`: GET (fetch user's financial data), POST (create/update financial data). Delete financial data not required for MVP.
* `app/api/student-loans/route.ts`: GET (fetch all student loans for user), POST (add new loan), PUT (update existing loan), DELETE (remove loan).
* `app/api/compare/route.ts`: POST endpoint. This is the core logic. It should:
* Fetch the current user's financial and student loan data.
* Perform calculations to estimate federal income tax liability for both joint and separate filing statuses (use simplified US tax brackets for a few common income levels for MVP).
* Calculate the estimated student loan payments for relevant income-driven repayment (IDR) plans under both joint and separate filing statuses. Assume basic IDR formulas (e.g., 10% of discretionary income) for MVP.
* Store the comparison results (estimated tax, student loan impact) in the `scenarios` table.
* Return the comparison results to the client.
* `app/api/scenarios/[id]/route.ts`: GET (fetch a specific scenario).
* `app/api/scenarios/route.ts`: GET (fetch all scenarios for the user).
6. **Core Logic for `/api/compare` (Simplified for MVP):**
* **Tax Calculation:** Implement a basic federal income tax calculation. Define a few simplified tax brackets (e.g., 10%, 12%, 22%, 24%) and standard deductions for single and married filing jointly/separately. These can be hardcoded for MVP.
* **Student Loan Calculation (IDR):** Implement a simplified IDR calculation. Assume a discretionary income calculation (Adjusted Gross Income - 150% of federal poverty line). Then, assume an IDR payment of 10% of discretionary income. Show how the AGI changes with filing status and thus impacts the IDR payment.
7. **User Interface (Tailwind CSS):**
* Create clean, responsive forms for data input.
* Display comparison results clearly, perhaps using a table or simple bar chart for visual comparison of tax liabilities and student loan payments.
* Include a navigation bar for easy access to different sections.
**Development Steps:**
* Set up Next.js project.
* Configure Drizzle ORM and run migrations to create tables.
* Implement authentication API routes and UI.
* Develop CRUD API routes and UI for finances and student loans.
* Implement the core comparison logic in `app/api/compare/route.ts`.
* Create the comparison display page.
* Ensure data validation on forms.
The fi