Develop a fully functional MVP for 'Finance Guardian' using Next.js 14 with the App Router, Drizzle ORM for database interactions (PostgreSQL), and Tailwind CSS for styling. The application helps elderly individuals or their designated caregivers manage financial tasks, set reminders, and securely delegate access. Database integration should include setup and migrations. All forms must include client-side validation. Implement secure authentication (e.g., JWT-based). All API routes should enforce authentication and authorization based on user roles (elder or caregiver) and access levels. Provide a comprehensive folder structure adhering to Next.js App Router conventions and a basic database seed script for initial data. The styling should be minimal yet professional using Tailwind CSS. All features mentioned below must be fully functional with proper database interactions and API calls.
**Database Schema (Drizzle ORM):**
1. **User**: Fields: `id` (uuid, primary key), `email` (string, unique), `passwordHash` (string), `firstName` (string), `lastName` (string), `role` (enum: 'elder', 'caregiver'), `createdAt` (timestamp, default now()), `updatedAt` (timestamp, default now(), on update now()).
2. **ElderProfile**: Fields: `id` (uuid, primary key), `userId` (uuid, foreign key to User, unique), `dateOfBirth` (date), `contactNumber` (string), `address` (string), `emergencyContactName` (string), `emergencyContactNumber` (string), `createdAt` (timestamp, default now()), `updatedAt` (timestamp, default now(), on update now()).
3. **CaregiverAccess**: Fields: `id` (uuid, primary key), `elderId` (uuid, foreign key to ElderProfile), `caregiverUserId` (uuid, foreign key to User where role='caregiver'), `accessLevel` (enum: 'view_only', 'limited_manage'), `grantedAt` (timestamp, default now()), `revokedAt` (timestamp, nullable). Composite unique constraint on `elderId` and `caregiverUserId`.
4. **FinancialTask**: Fields: `id` (uuid, primary key), `elderId` (uuid, foreign key to ElderProfile), `title` (string), `description` (string, nullable), `dueDate` (date), `isRecurring` (boolean, default false), `recurrencePattern` (string, nullable - e.g., 'monthly', 'annually'), `status` (enum: 'pending', 'completed', 'overdue'), `assignedToUserId` (uuid, nullable, foreign key to User), `createdAt` (timestamp, default now()), `updatedAt` (timestamp, default now(), on update now()).
5. **Document**: Fields: `id` (uuid, primary key), `elderId` (uuid, foreign key to ElderProfile), `fileName` (string), `fileType` (string), `storagePath` (string - simulate S3 or local storage path), `uploadedByUserId` (uuid, foreign key to User), `uploadDate` (timestamp, default now()), `category` (string, nullable - e.g., 'Tax', 'Insurance', 'Bank Statement').
**API Routes (Next.js App Router - app/api):**
Implement full CRUD operations for each primary entity, ensuring proper authentication and authorization:
- `/api/auth/register` (POST): Register new user (elder or caregiver) with email and password.
- `/api/auth/login` (POST): Authenticate user and return a JWT.
- `/api/users/[id]` (GET, PUT, DELETE): Manage user profiles. A user can only access/modify their own profile or if they are authorized as a caregiver for an elder.
- `/api/elder-profiles` (POST): Create ElderProfile. Only 'elder' role users can create their own profile initially.
- `/api/elder-profiles/[id]` (GET, PUT, DELETE): Manage specific ElderProfile. Accessible by the elder user or authorized caregivers.
- `/api/caregiver-access` (POST): Grant caregiver access to an elder profile. Only the elder user can initiate this.
- `/api/caregiver-access/[id]` (PUT, DELETE): Update or revoke caregiver access. Elder can revoke, caregiver can request revocation.
- `/api/elder-profiles/[elderId]/tasks` (GET, POST): Fetch/Create financial tasks for a specific elder. Accessible by the elder user or authorized caregivers.
- `/api/tasks/[taskId]` (GET, PUT, DELETE): Manage a specific financial task. Accessible by the elder user or authorized caregivers.
- `/api/elder-profiles/[elderId]/documents` (GET, POST): Fetch/Upload documents for a specific elder. Accessible by the elder user or authorized caregivers.
- `/api/documents/[documentId]` (GET, DELETE): Manage a specific document. Accessible by the elder user or authorized caregivers.
**User Interface (Next.js App Router - Multi-page structure):**
1. **Landing Page (`/`):** A compelling marketing page with clear calls-to-action for login and registration. Should include a brief description of the service and its benefits.
2. **Authentication Pages (`/register`, `/login`):** Fully functional forms with client-side validation for user registration (allowing selection of 'elder' or 'caregiver' role) and login.
3. **Elder Dashboard (`/dashboard/elder`):** The primary hub for 'elder' users. Displays a summary of upcoming financial tasks, a list of recent documents, and a section to view/manage their assigned caregivers. All data fetched dynamically via API.
4. **Caregiver Dashboard (`/dashboard/caregiver`):** The primary hub for 'caregiver' users. Lists all elders they have been granted access to, with a summary of their tasks. Each elder should have a link to their specific management pages.
5. **Financial Task Management (`/dashboard/elder/[elderId]/tasks` and `/dashboard/elder/[elderId]/tasks/[taskId]`):**
- A page listing all financial tasks (categorized by status: upcoming, completed, overdue) for a specific elder. Filtering and sorting options.
- Full CRUD functionality: forms to create new tasks, edit existing tasks, mark tasks as complete, or delete them. Task detail page for comprehensive viewing and editing of a single task.
6. **Document Management (`/dashboard/elder/[elderId]/documents`):**
- A secure page listing all uploaded financial documents for a specific elder. Each document should have a simulated 'view/download' link and a delete option.
- Full CRUD funct