Your task is to develop a fully functional MVP (Minimum Viable Product) for an application named 'ProductOps Hub'. This application will help solo founders and small teams manage their digital product portfolios, license keys, and basic sales tracking. The core requirements include a multi-page architecture, robust database integration, and full CRUD operations.
Technical Stack:
* Framework: Next.js (App Router, latest stable version)
* Language: TypeScript
* Database: PostgreSQL (use Drizzle ORM for schema definition and migrations)
* Styling: Tailwind CSS
* Authentication: NextAuth.js
Database Schema (Drizzle ORM):
Implement the following tables with appropriate types, relationships, and constraints.
1. **User**:
* `id`: Primary Key (UUID)
* `email`: String (Unique, Not Null)
* `passwordHash`: String (Not Null) - for local credentials or use NextAuth.js providers
* `name`: String (Nullable)
* `createdAt`: Timestamp (Default Now)
* `updatedAt`: Timestamp (Default Now, On Update)
2. **Product**:
* `id`: Primary Key (UUID)
* `userId`: Foreign Key to User.id (Not Null) - owner of the product
* `name`: String (Not Null)
* `description`: Text (Nullable)
* `price`: Decimal (Not Null, default 0.00)
* `currency`: String (Default 'USD')
* `productType`: String (e.g., 'Mac App', 'Web App', 'E-book', 'Template')
* `salesPlatform`: String (e.g., 'Gumroad', 'Stripe', 'App Store', 'Website')
* `externalUrl`: String (URL to product page/sales page, Nullable)
* `createdAt`: Timestamp (Default Now)
* `updatedAt`: Timestamp (Default Now, On Update)
3. **LicenseKey**:
* `id`: Primary Key (UUID)
* `productId`: Foreign Key to Product.id (Not Null)
* `keyString`: String (Unique, Not Null) - the actual license key string
* `customerEmail`: String (Not Null)
* `status`: Enum ('active', 'inactive', 'revoked') (Default 'active')
* `generatedAt`: Timestamp (Default Now)
* `activatedAt`: Timestamp (Nullable)
* `expiresAt`: Timestamp (Nullable)
* `notes`: Text (Nullable)
4. **Sale**:
* `id`: Primary Key (UUID)
* `productId`: Foreign Key to Product.id (Not Null)
* `userId`: Foreign Key to User.id (Not Null) - owner of the product/sale
* `customerEmail`: String (Not Null)
* `amount`: Decimal (Not Null)
* `currency`: String (Not Null, e.g., 'USD', 'EUR')
* `transactionId`: String (Unique, Nullable - from external platform)
* `salesPlatform`: String (e.g., 'Gumroad', 'Stripe', 'Manual Entry')
* `saleDate`: Timestamp (Not Null)
* `createdAt`: Timestamp (Default Now)
Application Structure (Next.js App Router):
The application must have a multi-page structure within the `app/` directory.
* `/app/layout.tsx`: Root layout with basic navigation (login/signup, dashboard, products, licenses, sales, settings).
* `/app/page.tsx`: Landing page with a brief description of the app and clear calls to action for login/signup.
* `/app/dashboard/page.tsx`: Protected route. Displays a summary of the user's products, total sales, and recent license key activities.
* `/app/products/page.tsx`: Protected route. Lists all products owned by the authenticated user in a table or card format. Includes "Add New Product" button.
* `/app/products/new/page.tsx`: Protected route. Form to create a new `Product`.
* `/app/products/[id]/page.tsx`: Protected route. Displays details of a specific `Product`, including a list of its associated `LicenseKey`s and `Sale`s. Buttons for "Edit Product" and "Generate Licenses".
* `/app/products/[id]/edit/page.tsx`: Protected route. Form to edit an existing `Product`.
* `/app/licenses/page.tsx`: Protected route. Lists all `LicenseKey`s across all products for the authenticated user, with filters.
* `/app/licenses/generate/[productId]/page.tsx`: Protected route. Form to generate a specified number of `LicenseKey`s for a given `productId`.
* `/app/sales/page.tsx`: Protected route. Lists all `Sale` records for the authenticated user. Includes an "Add Manual Sale" button.
* `/app/settings/page.tsx`: Protected route. User profile and account management.
* `/app/api/...`: Directory for API routes.
API Routes (Next.js Route Handlers):
Implement RESTful API endpoints with full CRUD functionality where applicable. All API routes must be protected and accessible only to authenticated users (via NextAuth.js session).
* **`products` endpoints:**
* `GET /api/products`: Fetch all products for the authenticated user.
* `POST /api/products`: Create a new product.
* `GET /api/products/[id]`: Fetch a single product by ID, including its associated license keys and sales.
* `PUT /api/products/[id]`: Update an existing product by ID.
* `DELETE /api/products/[id]`: Delete a product by ID.
* **`licenses` endpoints:**
* `POST /api/licenses/generate`: Generate multiple license keys for a given product.
* `GET /api/licenses`: Fetch all license keys for the authenticated user.
* `PUT /api/licenses/[id]`: Update a license key's status (e.g., deactivate, revoke).
* **`sales` endpoints:**
* `POST /api/sales`: Add a new sale record (manual entry).
* `GET /api/sales`: Fetch all sales for the authenticated user.
Functionality Details:
1. **Authentication:** Set up NextAuth.js (e.g., using Credentials Provider for email/password) to manage user sessions. Protect all pages and API routes except `/`, `/api/auth`, and `/api/register` (if separate registration endpoint).
2. **Product Management:** Users can add, view, edit, and delete their digital products.
3. **License Key Generation & Management:** For each product, users can generate unique license keys. Keys should be trackable (status, customer, activation/expiration dates). A simple license key generation algorithm (e.g., UUID-based or random alphanumeric string) should be