Build a comprehensive SaaS application using Next.js App Router (app/ directory). The application should manage inheritance agreements, specifically focusing on scenarios where a property is bequeathed with a condition for someone to continue living there. The MVP must include full CRUD (Create, Read, Update, Delete) functionality for all core entities and support multiple user roles (Heir, Deceased/Parent, Occupant). Utilize Drizzle ORM with PostgreSQL for the database schema and implement API routes within the app directory for all backend operations.
**Core Features & Pages:**
1. **Authentication & User Management:**
* Implement secure user registration, login, and logout using NextAuth.js.
* User roles: 'Heir', 'Parent' (for the person making the will), 'Occupant' (for the person with residency rights).
* Implement role-based access control (RBAC) for different features.
2. **Dashboard (Home Page):**
* `/` (Root route)
* Displays an overview of active inheritance agreements relevant to the logged-in user.
* For 'Heir': Shows agreements they are a part of, status, key dates, occupant details.
* For 'Parent': Allows management of their own agreement details.
* For 'Occupant': Shows details of the agreement concerning their residency.
3. **Agreement Management:**
* **Create Agreement:**
* `/agreements/new` (Multi-step form)
* Inputs: Property details, Heir details (link to user profile), Parent details (link to user profile), Occupant details (link to user profile).
* Define specific conditions: 'Lifetime Residency' for the Occupant.
* Option to add specific clauses regarding maintenance, property upkeep, financial contributions from the occupant.
* Set key dates (e.g., expected occupancy start).
* Save agreement to the database.
* **View Agreement:**
* `/agreements/[id]`
* Displays all details of a specific agreement.
* Shows status: 'Active', 'Pending Review', 'Breached', 'Completed'.
* Includes linked user profiles and property information.
* **Update Agreement:**
* `/agreements/[id]/edit`
* Allow modification of agreement details (subject to role permissions, e.g., only Heir/Parent can edit).
* Implement version history or audit log for changes.
* **Delete Agreement:**
* (Soft delete recommended) - Action available via admin or specific user roles.
4. **User Profiles:**
* `/users/[id]`
* Display user details (name, contact info, role).
* Allow users to edit their own profile information (except for role, which might be admin-set).
5. **Notifications & Alerts:**
* Implement a system for triggering notifications based on agreement status changes or approaching key dates.
* Examples: 'Occupancy date approaching', 'Potential breach detected (e.g., missed maintenance payment)', 'Agreement status updated'.
* Notifications should be visible within the app (e.g., a notification bell icon) and potentially via email.
6. **Legal Information & FAQ:**
* `/legal` & `/faq`
* Static pages providing general information about inheritance laws, tenancy rights, and common questions related to such agreements. *Disclaimer: This is not legal advice.*
**Technical Stack & Implementation Details:**
* **Framework:** Next.js (App Router)
* **Language:** TypeScript
* **Database:** PostgreSQL
* **ORM:** Drizzle ORM (with pg module)
* **Authentication:** NextAuth.js
* **Styling:** Tailwind CSS (optional, but recommended for rapid UI development)
**Database Schema (Drizzle):**
* `users` table: id, name, email, role, createdAt, updatedAt
* `properties` table: id, address, city, postalCode, country, description, ownerId (FK to users - optional, for tracking original owner)
* `agreements` table: id, propertyId (FK to properties), heirId (FK to users), parentId (FK to users), occupantId (FK to users), status (enum: 'Active', 'Pending Review', 'Breached', 'Completed'), lifetimeResidencyStartDate, lifetimeResidencyEndDate (nullable), maintenanceClause (text), financialContribution (decimal, nullable), createdAt, updatedAt, agreedAt
* `agreement_conditions` table: id, agreementId (FK to agreements), conditionType (e.g., 'maintenance_payment', 'property_upkeep'), details, dueDate (nullable)
* `notifications` table: id, userId (FK to users), message, type, read, createdAt
**API Routes (app/api/...):**
* Implement RESTful API endpoints for all CRUD operations on `users`, `properties`, `agreements`, and `notifications`.
* Example: `POST /api/agreements` (Create Agreement), `GET /api/agreements/[id]` (View Agreement), `PUT /api/agreements/[id]` (Update Agreement), `DELETE /api/agreements/[id]` (Delete Agreement).
* Ensure proper request validation and error handling.
* Leverage server actions for form submissions where appropriate.
**Deployment:**
* The application should be deployable to platforms like Vercel or similar.
**Do NOT:**
* Generate only a landing page.
* Create a simple SPA without backend logic, database interaction, and multiple pages/routes.
* Omit any of the core CRUD operations for the main entities.
* Skip the multi-page structure using Next.js App Router.
* Forget to include Drizzle ORM and detailed schema definitions.