Develop a full-stack web application named 'Housing Decision Aid' as an MVP. The application will help users, primarily young adults and students, compare housing options based on their personal financial situation and lifestyle preferences.
**Tech Stack:**
- Frontend: Next.js 14 (App Router), React, TypeScript, Tailwind CSS
- Backend: Next.js API Routes
- Database: PostgreSQL (using Drizzle ORM)
- Authentication: NextAuth.js for email/password authentication (or a basic custom implementation for MVP)
**Core Functionality:**
1. **User Authentication:** Allow users to register, log in, and log out securely.
2. **Financial Profile Management:** Users can input and manage their monthly income and various expense categories.
3. **Housing Option Input:** Users can add multiple housing options, providing details for each.
4. **Comparison Tool:** Based on the user's financial profile and selected housing options, the application will perform a detailed financial and lifestyle comparison.
5. **Decision Recommendation:** Present a summary and recommendation based on financial impact and user-defined lifestyle preferences.
**Database Schema (Drizzle ORM):**
```typescript
// users table
CREATE TABLE users (
id SERIAL PRIMARY KEY,
email TEXT UNIQUE NOT NULL,
password_hash TEXT NOT NULL,
created_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP,
updated_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP
);
// financial_profiles table (one-to-one with users)
CREATE TABLE financial_profiles (
id SERIAL PRIMARY KEY,
user_id INTEGER REFERENCES users(id) ON DELETE CASCADE UNIQUE NOT NULL,
monthly_income DECIMAL(10, 2) NOT NULL DEFAULT 0.00,
monthly_expenses_food DECIMAL(10, 2) NOT NULL DEFAULT 0.00,
monthly_expenses_transport DECIMAL(10, 2) NOT NULL DEFAULT 0.00,
monthly_expenses_insurance DECIMAL(10, 2) NOT NULL DEFAULT 0.00,
monthly_expenses_phone DECIMAL(10, 2) NOT NULL DEFAULT 0.00,
monthly_expenses_other DECIMAL(10, 2) NOT NULL DEFAULT 0.00
);
// housing_options table (one-to-many with users)
CREATE TABLE housing_options (
id SERIAL PRIMARY KEY,
user_id INTEGER REFERENCES users(id) ON DELETE CASCADE NOT NULL,
option_name TEXT NOT NULL,
monthly_rent DECIMAL(10, 2) NOT NULL,
monthly_utilities DECIMAL(10, 2) NOT NULL DEFAULT 0.00,
square_footage INTEGER,
num_bedrooms INTEGER,
num_bathrooms INTEGER,
num_roommates INTEGER NOT NULL DEFAULT 0,
distance_to_school_min INTEGER,
first_month_cost_special DECIMAL(10, 2) DEFAULT 0.00,
shared_room BOOLEAN NOT NULL DEFAULT FALSE,
comfort_score INTEGER CHECK (comfort_score >= 1 AND comfort_score <= 5) DEFAULT 3, -- User preference score (1-5)
privacy_score INTEGER CHECK (privacy_score >= 1 AND privacy_score <= 5) DEFAULT 3, -- User preference score (1-5)
created_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP,
updated_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP
);
```
**API Routes (Next.js App Router):**
- `POST /api/auth/register`: Create a new user account.
- `POST /api/auth/login`: Authenticate user and issue session token.
- `GET /api/financial-profile`: Retrieve the authenticated user's financial profile.
- `POST /api/financial-profile`: Create the authenticated user's financial profile.
- `PUT /api/financial-profile`: Update the authenticated user's financial profile.
- `GET /api/housing-options`: Retrieve all housing options for the authenticated user.
- `POST /api/housing-options`: Create a new housing option for the authenticated user.
- `GET /api/housing-options/[id]`: Retrieve a specific housing option by ID for the authenticated user.
- `PUT /api/housing-options/[id]`: Update a specific housing option by ID for the authenticated user.
- `DELETE /api/housing-options/[id]`: Delete a specific housing option by ID for the authenticated user.
- `GET /api/comparison`: Calculate and return a comparison summary based on the user's financial profile and all their housing options. This should include metrics like disposable income per option, potential monthly savings, and a weighted 'quality of life' score based on `comfort_score` and `privacy_score`.
**Frontend Pages (Next.js App Router):**
- `/`: Landing page with marketing content and calls to action (login/register).
- `/auth/login`: User login form.
- `/auth/register`: User registration form.
- `/dashboard`: A protected route showing a summary of the user's financial profile and a list of their added housing options.
- `/dashboard/profile`: Protected route with a form to manage (view/edit) the user's financial profile.
- `/dashboard/housing`: Protected route to view all housing options and a form to add a new housing option.
- `/dashboard/housing/[id]`: Protected route to view/edit/delete a specific housing option.
- `/dashboard/compare`: Protected route displaying the comparison results, potentially using simple charts (e.g., bar chart for disposable income) and tables.
**Instructions for AI:**
1. Initialize a Next.js 14 project using `create-next-app` with TypeScript and Tailwind CSS.
2. Set up Drizzle ORM to connect to a PostgreSQL database. Define the Drizzle schemas exactly as provided above.
3. Implement the full CRUD operations for `financial_profiles` and `housing_options` via Next.js API routes, ensuring proper authentication and authorization (only a user can access/modify their own data).
4. Implement the `/api/comparison` route with the logic to calculate:
- `total_monthly_expenses = monthly_expenses_food + ... + monthly_expenses_other`
- `total_cost_per_option = monthly_rent + monthly_utilities`
- `disposable_income_per_option = monthly_income - total_monthly_expenses - total_cost_per_option`
- A simplified `quality_of_life_score` per option based on `comfort_score` and `privacy_score` (e.g., average or weighted sum).
5. Create all specified frontend pages as Next.js React components. Use Tailwind CSS for styling to ensure a clean and responsive UI.
6. Implement forms for data input and display data in tables/lists. For the compariso