Create a full-stack web application using Next.js App Router (app directory) with a PostgreSQL database managed by Drizzle ORM. The application should help users navigate the process of potentially buying the home they are currently renting, especially when the landlord is selling. The core features include financial calculators, co-ownership simulations, market comparison tools, and a guided step-by-step process.
**Database Schema (Drizzle ORM for PostgreSQL):**
1. **`users` table:**
* `id` (UUID, primary key)
* `email` (text, unique)
* `password` (text)
* `createdAt` (timestamp)
* `updatedAt` (timestamp)
2. **`properties` table:**
* `id` (UUID, primary key)
* `address` (text)
* `city` (text)
* `state` (text)
* `zipCode` (text)
* `currentRent` (numeric)
* `estimatedMarketValue` (numeric)
* `propertyType` (enum: 'condo', 'house', 'apartment')
* `bedrooms` (integer)
* `bathrooms` (numeric)
* `listedForSale` (boolean, default: false)
* `landlordOfferPrice` (numeric, nullable)
* `createdAt` (timestamp)
* `updatedAt` (timestamp)
3. **`userProperties` table (Link between users and properties they are interested in/renting):**
* `userId` (UUID, foreign key to `users.id`)
* `propertyId` (UUID, foreign key to `properties.id`)
* `isCurrentRenter` (boolean, default: false)
* `monthlyRentPaid` (numeric)
* `rentToIncomeRatio` (numeric)
* `primaryUserContribution` (numeric, nullable) - For co-ownership down payment
* `secondaryUserContribution` (numeric, nullable) - For co-ownership down payment
* `createdAt` (timestamp)
* `updatedAt` (timestamp)
* Primary key: (`userId`, `propertyId`)
4. **`financialCalculations` table:**
* `id` (UUID, primary key)
* `userPropertyId` (UUID, foreign key to `userProperties.id`)
* `userAnnualIncome` (numeric)
* `maxAffordableMortgage` (numeric)
* `estimatedClosingCosts` (numeric)
* `downPaymentRequired` (numeric)
* `monthlyMortgageEstimate` (numeric)
* `createdAt` (timestamp)
5. **`coOwnershipSimulations` table:**
* `id` (UUID, primary key)
* `userPropertyId` (UUID, foreign key to `userProperties.id`)
* `owner1Name` (text)
* `owner1ContributionPercent` (numeric)
* `owner1MonthlyContribution` (numeric)
* `owner2Name` (text)
* `owner2ContributionPercent` (numeric)
* `owner2MonthlyContribution` (numeric)
* `totalPurchasePrice` (numeric)
* `loanAmount` (numeric)
* `interestRate` (numeric)
* `loanTermYears` (integer)
* `createdAt` (timestamp)
**Project Structure (Next.js App Router):**
* `app/`
* `layout.tsx` (Root layout)
* `page.tsx` (Homepage/Dashboard)
* `auth/` (Login, Register pages)
* `properties/`
* `[propertyId]/`
* `page.tsx` (View specific property details)
* `financials/`
* `page.tsx` (Financial calculator for this property)
* `coownership/`
* `page.tsx` (Co-ownership simulation for this property)
* `market/`
* `page.tsx` (Market comparison tool)
* `process/`
* `page.tsx` (Step-by-step buying process guide)
* `components/` (Reusable UI components)
* `lib/` (Utility functions, database client setup)
* `server/` (API routes - using `app/api/...` or `app/**/route.ts`)
**API Routes (CRUD Operations):**
Implement API routes within the `app/api/` directory or using `route.ts` files in relevant folders for CRUD operations on all tables (`users`, `properties`, `userProperties`, `financialCalculations`, `coOwnershipSimulations`).
**Core Functionality Implementation:**
1. **Authentication:** Implement secure user authentication (e.g., NextAuth.js or custom JWT implementation).
2. **Property Management:** Allow users to add properties they are interested in, input their current rent, and specify their income. Seed some sample property data for North NJ.
3. **Financial Calculator:** Develop a robust financial calculator that takes user income, current rent, and property details to estimate affordability, mortgage potential, closing costs, and down payment needs. Use realistic mortgage rate estimates.
4. **Co-Ownership Simulation:** Create a detailed simulation tool where users can input contributions, ownership percentages, loan details (amount, interest rate, term), and see projected monthly payments for co-owners.
5. **Market Comparison:** Integrate a tool that fetches (or allows manual input of) comparable property data in a given area to help users assess fair market value.
6. **Process Guide:** A clear, step-by-step guide outlining the typical home-buying process, tailored for situations involving purchasing from a current landlord.
7. **Data Visualization:** Use charts and graphs (e.g., using Chart.js or Recharts) to visualize financial projections, co-ownership breakdowns, and market trends.
**Technology Stack:**
* **Frontend:** Next.js (App Router), React, TypeScript, Tailwind CSS
* **Backend:** Node.js (via Next.js API routes)
* **Database:** PostgreSQL
* **ORM:** Drizzle ORM
* **State Management:** React Context API or Zustand (for simpler global state)
* **Authentication:** NextAuth.js (recommended)
**Deployment Considerations:**
* Ensure the application is deployable on platforms like Vercel or similar.
* Set up database migrations using Drizzle.
**Instructions:**
* Build a complete, multi-page application, not just a landing page or a simple SPA.
* Implement full CRUD functionality for all major data entities.
* Ensure type safety using TypeScript.
* Write clean, well-organized, and maintainable code.
* Include basic error handling and user feedback mechanisms.