Create a full-stack Next.js 14 application using the App Router (app/ directory) for managing financial assets and liabilities during separation or divorce. The application should allow users to securely upload financial documents, analyze them for hidden debts or assets, and generate reports for legal proceedings. Use Drizzle ORM with PostgreSQL for the database. Implement robust CRUD operations for all data entities. The application should have multiple pages and clear navigation.
**Database Schema (Drizzle ORM):**
1. **users:**
* id (uuid, primary key)
* email (text, unique)
* password (text)
* name (text)
* created_at (timestamp)
2. **financial_documents:**
* id (uuid, primary key)
* user_id (uuid, foreign key to users)
* file_url (text)
* document_type (text, e.g., 'bank_statement', 'credit_card_statement', 'loan_application')
* uploaded_at (timestamp)
* analysis_status (text, e.g., 'pending', 'analyzed', 'error')
3. **financial_analysis_results:**
* id (uuid, primary key)
* document_id (uuid, foreign key to financial_documents)
* user_id (uuid, foreign key to users)
* potential_hidden_debt (decimal)
* potential_hidden_asset (decimal)
* summary (text)
* created_at (timestamp)
4. **legal_reports:**
* id (uuid, primary key)
* user_id (uuid, foreign key to users)
* report_name (text)
* generated_at (timestamp)
* file_url (text)
**API Routes (app/api/...):**
* `/api/auth/...`: Authentication routes (signup, login, logout, session handling).
* `/api/documents`: CRUD for `financial_documents` (upload, list, view, delete).
* `/api/documents/[id]/analyze`: Trigger financial document analysis.
* `/api/analysis`: CRUD for `financial_analysis_results` (list, view).
* `/api/reports`: CRUD for `legal_reports` (generate, list, view, delete).
**App Router Structure (app/):**
* `app/layout.tsx`: Root layout.
* `app/page.tsx`: Landing page.
* `app/(auth)/login/page.tsx`, `app/(auth)/signup/page.tsx`: Authentication pages.
* `app/(app)/dashboard/page.tsx`: User dashboard.
* `app/(app)/documents/page.tsx`: Page to upload and list financial documents.
* `app/(app)/documents/[id]/page.tsx`: Page to view a specific document and its analysis.
* `app/(app)/analysis/page.tsx`: Page to view all analysis results.
* `app/(app)/reports/page.tsx`: Page to manage legal reports.
* `app/(app)/profile/page.tsx`: User profile settings.
**Key Functionality Requirements:**
1. **Secure File Upload:** Implement secure file upload handling, potentially using libraries like `react-hook-form` and `multer` (if needed server-side for processing, although Next.js 14 file uploads can be handled directly). Store files securely (e.g., S3 or local storage with appropriate permissions). Assign a `file_url` in the `financial_documents` table.
2. **Document Analysis (Mock/Placeholder):** For the MVP, the analysis can be simulated. When the `/api/documents/[id]/analyze` endpoint is hit, update the `analysis_status` to 'analyzed' and create dummy `financial_analysis_results` entries. In a real-world scenario, this would involve an external AI/ML service or complex parsing logic.
3. **CRUD Operations:** Implement full CRUD for users, documents, analysis results, and reports. Ensure proper data validation and error handling.
4. **Authentication & Authorization:** Secure all authenticated routes. Users should only be able to access their own data.
5. **UI/UX:** Design a clean and intuitive user interface. The app should feel trustworthy and secure.
6. **Error Handling:** Implement comprehensive error handling for API calls, file uploads, and data processing.
7. **Data Fetching:** Use Server Components and Client Components effectively. Fetch data server-side where possible for better performance and SEO.