Create a full-stack web application using Next.js App Router (app directory), Drizzle ORM with PostgreSQL, and Tailwind CSS. The application, named 'Secure Payment Pledge', is designed to mitigate chargeback risks for SaaS businesses offering annual prepayment options. It needs to manage digital contracts, collect usage proof, and send automated alerts.
**Core Functionality:**
1. **User Authentication:** Implement secure user registration and login using NextAuth.js.
2. **Contract Management Module:**
* **Schema:** Create a `contracts` table with fields like `id`, `userId`, `customerId`, `serviceDescription`, `paymentAmount`, `paymentDate`, `startDate`, `endDate`, `status` (e.g., 'active', 'disputed', 'completed'), `contractDocumentUrl`, `createdAt`, `updatedAt`.
* **CRUD Operations:** Implement API routes (`app/api/contracts/route.ts`) for creating, reading, updating, and deleting contracts. Provide form components in the UI (`app/dashboard/contracts/new`, `app/dashboard/contracts/[id]/edit`) for managing contracts.
* **Digital Signing:** Integrate a simple digital signing mechanism (e.g., a checkbox and timestamp for MVP) to acknowledge contract terms.
3. **Usage Proof Collection Module:**
* **Schema:** Create a `usageLogs` table with fields like `id`, `contractId`, `userId`, `timestamp`, `action` (e.g., 'login', 'feature_use', 'session_end'), `details` (JSONB for flexibility).
* **API Integration:** Develop API endpoints (`app/api/usage/log`) to receive usage data from client applications (simulated for MVP with manual entry or a dedicated client-side logging mechanism). The `contracts` table should link to relevant customer data that would theoretically provide this usage.
* **Reporting:** A dashboard view (`app/dashboard/contracts/[id]/usage`) to display collected usage logs for a specific contract.
4. **Chargeback Alert & Dispute Module:**
* **Schema:** Create a `chargebackDisputes` table with fields like `id`, `contractId`, `customerId`, `disputeDate`, `reason`, `amount`, `status` (e.g., 'open', 'evidence_submitted', 'won', 'lost'), `evidenceUrls` (array of strings), `createdAt`, `updatedAt`.
* **Stripe Webhook Simulation:** Implement an API route (`app/api/webhooks/stripe`) that can simulate receiving a chargeback notification. This route should trigger the creation of a new entry in the `chargebackDisputes` table.
* **Evidence Submission:** UI components (`app/dashboard/disputes/[id]/evidence`) for users to upload relevant documents (contract, logs, emails) and submit them. Store these URLs in the `chargebackDisputes` table.
* **Automated Alerts:** Implement server-side logic (or scheduled jobs) to check for new disputes and potentially send email notifications (using a placeholder email service for MVP).
5. **Dashboard:** A main dashboard (`app/dashboard`) showing an overview of active contracts, open disputes, and key metrics.
6. **Database:** Use PostgreSQL as the database. Set up Drizzle ORM for schema definition and migrations.
* **Schema Definition:** Define all schemas (`db/schema.ts`) using Drizzle's syntax.
* **Migrations:** Set up Drizzle Kit for database migrations.
7. **UI/UX:** Use Tailwind CSS for styling. Ensure a clean, intuitive user interface across all modules.
8. **Deployment:** Structure the project for easy deployment to platforms like Vercel.
**Project Structure Guidelines:**
* Use `app/` directory for routing.
* Place API routes in `app/api/`.
* Define database schema in `db/schema.ts`.
* Handle migrations with Drizzle Kit.
* Organize UI components logically (e.g., `components/ui`, `features/contracts`).
* Implement server components and client components where appropriate.
**MVP Constraints:**
* Focus on the core CRUD logic for contracts and disputes.
* Usage log collection can be simplified initially (e.g., manual entry or basic simulated data).
* Email notifications can be placeholder functions.
* Digital signing is a basic acknowledgment.
* Stripe integration is simulated via webhook endpoint.
* Ensure data integrity and basic validation.