You are tasked with building a fully functional MVP for a SaaS application called 'PartnerLedger'. The application aims to help business partners manage their agreements, finances, and tasks transparently. Utilize Next.js 14 with the App Router, Drizzle ORM for PostgreSQL, and Tailwind CSS for styling. Ensure all core functionalities include full CRUD (Create, Read, Update, Delete) operations and are accessible through a multi-page application structure, not a single-page application (SPA).
**Core Entities and Drizzle Schema (PostgreSQL):**
1. `users`: id (uuid), email (unique), passwordHash, name, createdAt, updatedAt. (Basic user for authentication reference).
2. `partnerships`: id (uuid), name, description, ownerUserId (uuid, fk to users.id), createdAt, updatedAt.
3. `partnershipsToUsers` (Junction Table for many-to-many relationship): partnershipId (uuid, fk to partnerships.id), userId (uuid, fk to users.id), role (enum: 'owner', 'admin', 'member'), equitySplit (numeric, e.g., '0.50'), initialCapitalContribution (numeric), isActive (boolean), joinedAt.
4. `transactions`: id (uuid), partnershipId (uuid, fk to partnerships.id), submittedByUserId (uuid, fk to users.id), type (enum: 'income', 'expense'), amount (numeric), description, category, transactionDate (date), receiptImageUrl (string, optional), createdAt, updatedAt.
5. `agreements`: id (uuid), partnershipId (uuid, fk to partnerships.id), createdByUserId (uuid, fk to users.id), title, content, type (enum: 'equity', 'responsibility', 'expense_limit', 'general'), status (enum: 'draft', 'pending', 'approved', 'rejected'), signedByUsers (jsonb array of {userId: uuid, signedAt: timestamp}), createdAt, updatedAt.
6. `tasks`: id (uuid), partnershipId (uuid, fk to partnerships.id), assignedToUserId (uuid, fk to users.id, optional), createdByUserId (uuid, fk to users.id), title, description, dueDate (date), status (enum: 'todo', 'in_progress', 'done'), createdAt, updatedAt.
**Page Structure (Next.js App Router):**
* `/`: Home/Landing page (can be simple, inviting users to sign up/login).
* `/login`: User login form.
* `/signup`: User registration form.
* `/dashboard`: Displays a list of partnerships the user is part of. Allows creating a new partnership.
* `/partnerships/[partnershipId]/overview`: Main dashboard for a specific partnership, showing recent activities, current balance, pending agreements, and upcoming tasks.
* `/partnerships/[partnershipId]/transactions`: Lists all transactions for the partnership. Includes forms/modals for adding new transactions, and options to view/edit/delete existing ones.
* `/partnerships/[partnershipId]/agreements`: Lists all agreements. Includes forms/modals for creating new agreements, viewing details, editing, and a mechanism for partners to 'sign' an agreement.
* `/partnerships/[partnershipId]/tasks`: Lists all tasks. Includes forms/modals for creating new tasks, assigning them to partners, updating status, and deleting.
* `/partnerships/[partnershipId]/settings`: Partnership-specific settings, including managing partners (inviting new partners, adjusting roles/equity split).
* `/settings/profile`: User profile settings.
**API Routes (`app/api/...`):**
Create API routes for each main entity to support full CRUD operations. All routes should be protected, ensuring only authenticated users and authorized members of a partnership can access/modify data.
* `/api/auth/signup`, `/api/auth/login`
* `/api/partnerships` (GET all for user, POST new partnership)
* `/api/partnerships/[id]` (GET single, PUT update, DELETE partnership)
* `/api/partnerships/[id]/members` (GET, POST add member, PUT update member, DELETE member)
* `/api/partnerships/[id]/transactions` (GET all, POST new transaction)
* `/api/partnerships/[id]/transactions/[transactionId]` (GET single, PUT update, DELETE transaction)
* `/api/partnerships/[id]/agreements` (GET all, POST new agreement)
* `/api/partnerships/[id]/agreements/[agreementId]` (GET single, PUT update, DELETE agreement, POST sign agreement)
* `/api/partnerships/[id]/tasks` (GET all, POST new task)
* `/api/partnerships/[id]/tasks/[taskId]` (GET single, PUT update, DELETE task)
* `/api/users/[id]` (GET user profile, PUT update profile)
**Technical Requirements:**
* **Frontend:** Next.js 14 App Router with React Server Components (RSC) where appropriate, and Client Components for interactive elements (forms, modals). Use `use client` directives explicitly. Tailwind CSS for all styling.
* **Backend:** Next.js API Routes for all data interactions. Drizzle ORM for database operations (PostgreSQL). Implement robust validation for all inputs.
* **Authentication:** For the MVP, a simple session-based authentication or JWT can be used, ensuring user context is available for API calls.
* **Authorization:** Implement checks so users can only view/manage data for partnerships they are members of. Owners/Admins should have more privileges (e.g., inviting members, adjusting equity).
* **Database Setup:** Provide Drizzle schema definitions for all entities. Include basic migrations if applicable. Assume a PostgreSQL database connection string is provided via environment variables.
**Implementation Focus:**
1. Set up the Next.js project with Drizzle and Tailwind CSS.
2. Define the Drizzle schema and initial migrations.
3. Implement basic user authentication (signup, login).
4. Develop CRUD for `partnerships` and `partnershipsToUsers` (allowing a user to create a partnership and invite others).
5. Develop CRUD for `transactions` within a partnership.
6. Develop CRUD for `agreements` within a partnership, including the 'signing' functionality.
7. Develop CRUD for `tasks` within a partnership.
8. Build the key pages (`/dashboard`, `/partnerships/[id]/overview`, `/partnerships/[id]/transactions`, `/partnerships/[id]/agreements`, `/partnerships/[id]/tasks`) with a clear navigation structure.
9. Ensure data fetching and mutati