Create a full-stack Next.js 14 application using the App Router, Drizzle ORM with PostgreSQL, and Tailwind CSS for styling. The application, named 'Etsy Auditor', aims to help Etsy buyers and sellers identify and verify product authenticity. The core functionality revolves around user-submitted product reports, AI-powered analysis of product listings, and seller-provided evidence for authenticity.
**Project Structure:**
- Use the `app/` directory for routing.
- Separate pages for:
- Landing Page (`app/page.tsx`)
- User Dashboard (`app/dashboard/page.tsx`)
- Report Submission Form (`app/report/new/page.tsx`)
- View Report Details (`app/report/[id]/page.tsx`)
- Seller Authenticity Verification (`app/verify/[reportId]/page.tsx`)
- User Profile (`app/profile/[userId]/page.tsx`)
- Auth pages (Login, Signup) (`app/auth/login/page.tsx`, `app/auth/signup/page.tsx`)
**Database Schema (Drizzle ORM):**
Define the following tables using Drizzle ORM with PostgreSQL:
1. **`users` table:**
- `id` (UUID, primary key)
- `username` (VARCHAR, unique, not null)
- `email` (VARCHAR, unique, not null)
- `passwordHash` (VARCHAR, not null)
- `role` ENUM ('buyer', 'seller', 'admin')
- `createdAt` (TIMESTAMP, default now())
- `updatedAt` (TIMESTAMP, default now())
2. **`reports` table:**
- `id` (UUID, primary key)
- `reportedById` (UUID, foreign key to `users.id`, not null)
- `etsyListingUrl` (VARCHAR, not null)
- `productName` (VARCHAR, not null)
- `reportReason` (TEXT, not null)
- `additionalInfo` (TEXT)
- `submissionDate` (TIMESTAMP, default now())
- `status` ENUM ('pending', 'under_review', 'verified', 'rejected', 'escalated')
- `assignedToId` (UUID, foreign key to `users.id`, nullable - for admin assignment)
- `createdAt` (TIMESTAMP, default now())
- `updatedAt` (TIMESTAMP, default now())
3. **`evidence` table:**
- `id` (UUID, primary key)
- `reportId` (UUID, foreign key to `reports.id`, not null)
- `submittedById` (UUID, foreign key to `users.id`, not null)
- `evidenceType` ENUM ('image', 'video', 'document', 'text')
- `url` (VARCHAR, nullable - for file storage links)
- `description` (TEXT, nullable)
- `submittedAt` (TIMESTAMP, default now())
- `createdAt` (TIMESTAMP, default now())
- `updatedAt` (TIMESTAMP, default now())
4. **`analysis` table:**
- `id` (UUID, primary key)
- `reportId` (UUID, foreign key to `reports.id`, not null)
- `analyzedById` (UUID, foreign key to `users.id`, nullable - AI or admin)
- `analysisResults` (JSONB, not null)
- `analysisDate` (TIMESTAMP, default now())
- `confidenceScore` (FLOAT, nullable)
- `createdAt` (TIMESTAMP, default now())
- `updatedAt` (TIMESTAMP, default now())
5. **`verification_tokens` table:**
- `id` (UUID, primary key)
- `userId` (UUID, foreign key to `users.id`, not null)
- `reportId` (UUID, foreign key to `reports.id`, not null)
- `token` (VARCHAR, unique, not null) - used for seller verification link
- `expiresAt` (TIMESTAMP, not null)
- `createdAt` (TIMESTAMP, default now())
**API Routes (app/api/):**
Implement API routes for full CRUD operations on the defined tables. Key routes include:
- **`/api/reports` (POST):** Submit a new report.
- **`/api/reports/[id]` (GET):** Get details of a specific report.
- **`/api/reports/[id]` (PUT):** Update report status (admin/moderator).
- **`/api/reports` (GET):** Get a list of reports (paginated, filterable by status, user).
- **`/api/evidence` (POST):** Upload evidence for a report.
- **`/api/auth/signup` (POST):** User registration.
- **`/api/auth/login` (POST):** User login.
- **`/api/auth/logout` (POST):** User logout.
- **`/api/verify/request` (POST):** Request a verification token for a seller.
- **`/api/verify/:token` (GET):** Seller page to submit evidence using a token.
- **`/api/analysis` (POST):** Trigger AI analysis for a report (can be internal or external API call simulation).
**AI Integration (Simulation for MVP):**
- Create a POST API route `/api/analysis` that simulates AI analysis.
- This route should take `etsyListingUrl` and `productName` as input.
- It should return mock `analysisResults` (JSON) and a `confidenceScore` (float).
- Simulate analysis by checking for keywords like "handmade", "handcrafted", "unique", and cross-referencing with common dropshipping product imagery/traits (e.g., lack of drainage holes from the example).
- Later, this can be integrated with actual AI services (e.g., image recognition, NLP for description analysis).
**Authentication & Authorization:**
- Implement JWT-based authentication.
- Use middleware to protect routes that require login.
- Implement role-based access control (e.g., only admins can update report status, only the reporting user can edit their report before review).
**Frontend (React Components using App Router):**
- Build reusable UI components using Tailwind CSS.
- Implement forms for report submission, user signup/login, and evidence upload.
- Create dynamic pages for report details and user dashboards.
- Integrate client-side fetching of API data.
**Deployment Considerations:**
- Ensure the project is structured for easy deployment on platforms like Vercel.
- Configure environment variables for database credentials and JWT secrets.
**MVP Scope:** Focus on core reporting, basic AI simulation, and seller verification flow. Do NOT implement advanced features like payment processing or complex user reputation systems in this MVP. Ensure the AI simulation is robust enough to provide meaningful (even if mocked) feedback based on the provided problem statement.