Develop a comprehensive MVP for a 'Tax Filing Companion' web application using Next.js 14 App Router, TypeScript, Tailwind CSS, Drizzle ORM with PostgreSQL (or SQLite for local development), and NextAuth.js for authentication. The application should facilitate tax management for married couples, providing tools for tracking filing statuses, organizing documents, and setting deadline reminders. Ensure all functionalities are fully working.
**Core Requirements & Features:**
1. **Project Setup**: Initialize a Next.js project using the App Router (`app/` directory), configure TypeScript, Tailwind CSS, Drizzle ORM, and NextAuth.js.
2. **Authentication (NextAuth.js)**: Implement secure email/password authentication (login, register, logout). Protect routes to ensure only authenticated users can access the dashboard and other features.
3. **Database Schema (Drizzle ORM)**: Define and implement the following Drizzle schema. Use Drizzle migrations to manage schema changes.
* `users` table: `id` (uuid), `email` (unique, string), `passwordHash` (string), `name` (string, nullable), `createdAt` (timestamp), `updatedAt` (timestamp).
* `spouses` table: `id` (uuid), `userId1` (FK to users.id), `userId2` (FK to users.id), `status` (enum: 'pending', 'linked', 'declined'), `createdAt`, `updatedAt`.
* `taxYears` table: `id` (uuid), `userId` (FK to users.id), `year` (number, unique per user), `status` (enum: 'not_started', 'in_progress', 'filed'), `createdAt`, `updatedAt`.
* `documents` table: `id` (uuid), `userId` (FK to users.id), `taxYearId` (FK to taxYears.id, nullable), `filename` (string, path/key for storage), `originalFilename` (string), `mimeType` (string), `size` (number), `uploadDate` (timestamp), `description` (string, nullable), `sharedWithSpouse` (boolean, default false), `createdAt`, `updatedAt`.
* `deadlines` table: `id` (uuid), `userId` (FK to users.id), `taxYearId` (FK to taxYears.id, nullable), `description` (string), `deadlineDate` (date), `reminderEnabled` (boolean, default true), `reminderSent` (boolean, default false), `createdAt`, `updatedAt`.
4. **API Routes (Next.js App Router - `app/api/...`)**: Develop robust API endpoints for full CRUD operations.
* `/api/auth`: Login, Register, Logout.
* `/api/users`: Get current user profile, Update user profile.
* `/api/spouses`: Invite spouse (send email with link/code), Accept/Decline invitation, Get linked spouse's basic info (name, filing status for linked tax years).
* `/api/tax-years`: Create a new tax year entry, Get all tax years for a user, Get a single tax year, Update tax year status, Delete a tax year.
* `/api/documents`: Upload a document (handle file storage in `public/uploads` for MVP, store path in DB), Get documents for a user/tax year, Get single document metadata, Update document metadata (e.g., description, `sharedWithSpouse`), Delete a document.
* `/api/deadlines`: Create a new deadline, Get all deadlines for a user/tax year, Get a single deadline, Update deadline details, Delete a deadline.
5. **User Interface (Multi-page structure with Next.js components)**:
* **Landing Page**: Simple public page introducing the app.
* **Authentication Pages**: Responsive Login and Register forms.
* **Dashboard (`/dashboard`)**: Overview of current tax year status for the user and linked spouse, upcoming deadlines, quick links to documents.
* **Tax Years Page (`/tax-years`)**: List of all managed tax years. Clicking a year leads to its detail page.
* **Tax Year Detail Page (`/tax-years/[yearId]`)**: Displays detailed status for a specific year, associated documents, and deadlines. Allows updating tax year status.
* **Document Management Page (`/documents`)**: Upload new documents, list all documents with filters/search, view/edit document metadata, delete documents. Implement a simple file uploader component.
* **Spouse Management Page (`/spouse`)**: Interface to invite a spouse, view invitation status, or see linked spouse's details. Once linked, show read-only access to their tax year statuses and shared documents.
* **Deadlines Page (`/deadlines`)**: List all deadlines, add new deadlines, edit/delete existing ones. Implement toggles for reminder enablement.
* **Profile Settings Page (`/profile`)**: User can update their name, email, or password.
* **Legal Info / FAQ Page (`/info/faq`)**: Static content or simple markdown rendering for common tax questions.
6. **Error Handling & Validation**: Implement robust error handling for API routes and client-side forms. Ensure input validation for all user-submitted data.
7. **File Storage**: For MVP, store uploaded documents in a local directory (`public/uploads`) on the server. The database should only store the file path/name, not the actual file binary.
8. **Instructions**: Provide clear setup instructions for running the application locally, including database setup (e.g., using `docker-compose` for PostgreSQL or local SQLite) and environment variable configuration.