You are an expert full-stack developer. Your task is to build a comprehensive MVP for a financial management application called 'CareVault' using Next.js 14+ with App Router, TypeScript, Drizzle ORM with PostgreSQL, NextAuth.js, and Tailwind CSS. The application aims to help family members securely manage the financial affairs of elderly relatives, especially for recurring tasks like Social Security withdrawals, without needing physical bank visits. The solution must be multi-page, secure, and intuitive for both caregivers and elderly users.
**Core Requirements:**
1. **Project Setup**: Initialize a Next.js 14+ project with TypeScript, configure Tailwind CSS, Drizzle ORM for PostgreSQL, and NextAuth.js for authentication.
2. **Database Schema (Drizzle ORM)**: Define the following tables with appropriate fields, primary keys, and relationships:
* `users`: (id, email, hashedPassword, name, role (ENUM: 'caregiver', 'elderly'), createdAt, updatedAt). Use `text` for strings, `timestamp` for dates, `boolean` where appropriate.
* `elderlyProfiles`: (id, userId (FK to users.id, where role='elderly'), preferredName, dateOfBirth, address, contactPhone, notes, createdAt, updatedAt).
* `caregiverRelations`: (id, caregiverUserId (FK to users.id, where role='caregiver'), elderlyProfileId (FK to elderlyProfiles.id), permissions (TEXT[] or JSONB array: 'read_only', 'manage_accounts', 'manage_payments', 'manage_documents'), status (ENUM: 'pending', 'active', 'revoked'), createdAt, updatedAt).
* `bankAccounts`: (id, elderlyProfileId (FK to elderlyProfiles.id), bankName, accountNumber, accountType, currentBalance (NUMERIC), lastSyncDate (TIMESTAMP, simulated), notes, createdAt, updatedAt).
* `transactions`: (id, bankAccountId (FK to bankAccounts.id), type (ENUM: 'deposit', 'withdrawal', 'transfer'), amount (NUMERIC), date (TIMESTAMP), description, category, status (ENUM: 'pending', 'approved', 'declined'), recordedByUserId (FK to users.id), createdAt, updatedAt).
* `scheduledPayments`: (id, bankAccountId (FK to bankAccounts.id), targetDescription, targetDetails, amount (NUMERIC), frequency (ENUM: 'daily', 'weekly', 'monthly', 'quarterly', 'yearly'), nextPaymentDate (TIMESTAMP), notes, status (ENUM: 'active', 'paused', 'completed'), approvedByElderly (BOOLEAN), createdAt, updatedAt).
* `documents`: (id, elderlyProfileId (FK to elderlyProfiles.id), documentType (ENUM: 'POA', 'Will', 'Medical Directive', 'Other'), filename, fileUrl (e.g., S3 URL placeholder), uploadedByUserId (FK to users.id), uploadDate, description, createdAt, updatedAt).
3. **Authentication (NextAuth.js)**:
* Implement email/password login and registration for both caregiver and elderly roles.
* Create a mechanism for role-based access control throughout the application.
* Session management.
4. **UI/UX (Tailwind CSS)**:
* Design a clean, responsive, and intuitive user interface suitable for both desktop and mobile.
* Ensure accessibility considerations, especially for elderly users (larger fonts, clear buttons).
5. **Pages (Next.js App Router & Multi-Page Structure)**:
* **`/` (Landing Page)**: A public-facing page with a brief description of CareVault and calls to action (Login/Register).
* **`/login`**: User login form.
* **`/register`**: User registration form (distinguish between caregiver and elderly signup flow, or have caregivers invite elderly).
* **`/dashboard`**: The main hub for logged-in users.
* **Caregiver View**: Display a list of managed elderly profiles. Each profile should be a clickable card leading to its dedicated management pages.
* **Elderly View**: Display an overview of their own financial status, recent transactions (simulated), and a list of linked caregivers with their permissions.
* **`/elderly/[elderlyProfileId]/profile`**: Page for caregivers to view/edit an elderly person's profile details.
* **`/elderly/[elderlyProfileId]/bank-accounts`**: List all simulated bank accounts linked to an elderly profile. Allow caregivers to add new bank accounts (manual entry of bank name, account number, initial balance) and view/edit existing ones.
* **`/elderly/[elderlyProfileId]/bank-accounts/[bankAccountId]/transactions`**: Display a simulated transaction history for a specific bank account. Allow caregivers to manually add, edit, and delete transactions (e.g., 'SSN Deposit $1500', 'Withdrawal $200 for cash').
* **`/elderly/[elderlyProfileId]/scheduled-payments`**: Manage recurring payments/transfers.
* Caregivers can create, edit, delete scheduled payments (e.g., 'Transfer $500 to [Caregiver's bank account] on the 1st of every month').
* Elderly users can view these schedules and, if active in the system, potentially approve pending payments or pause/cancel their own schedules.
* **`/elderly/[elderlyProfileId]/documents`**: Secure document storage and viewing.
* Caregivers can upload, view, and delete legal documents (e.g., Power of Attorney, medical directives) for an elderly profile. Placeholder for file storage (e.g., show a link or generic file icon).
* **`/caregivers` (for Elderly User)**: A page where an elderly user can view their linked caregivers and their granted permissions. Option to revoke caregiver access.
* **`/settings`**: User-specific settings (change password, update profile details).
6. **API Routes (Next.js App Router)**: Implement API routes for all CRUD operations on the defined database models. Ensure proper authentication and authorization checks (e.g., a caregiver can only manage profiles they are linked to).
* `/api/auth/[...nextauth]` for NextAuth.js.
* `/api/users` (for profile updates).
* `/api/elderly-profiles`
* `/api/caregiver-relations`
* `/api/bank-accounts`
* `/api/transactions`
* `/api/scheduled-payments`
* `/api/documents`
**Important Consider