Build a fully functional MVP of 'Stealth Chat' (Gizli Sohbet), a privacy-focused AI chatbot application. The application should be built using Next.js App Router (app/ directory), with a multi-page structure. Implement robust CRUD operations for user data and chat history using Drizzle ORM with PostgreSQL as the database.
**Core Features to Implement:**
1. **User Authentication:** Secure user registration, login, and logout using NextAuth.js or a similar robust library. Implement password hashing and secure session management.
2. **User Profile Management:** Users should be able to manage their profile information. This includes an 'Account Settings' page where users can view and potentially update basic profile details.
3. **Data Privacy Controls:**
* **Data Usage Consent:** A dedicated section in 'Account Settings' where users can explicitly grant or revoke consent for their chat data to be used for AI model training. Default should be 'opt-in' (meaning data is NOT used by default).
* **Chat History Deletion:** Users must have the ability to delete individual chat sessions and their entire chat history. This action should be irreversible and remove data from the database.
* **Data Export:** (Optional for MVP, but good to consider) A feature to export chat history in a user-readable format (e.g., JSON, TXT).
4. **Chat Interface:**
* **Multi-Page Structure:** Implement a dedicated page for the chat interface (e.g., `/chat`). This page should be protected and only accessible to logged-in users.
* **Real-time Chat:** Simulate real-time chat experience. When a user sends a message, it should be saved to the database, and the AI response should be fetched and displayed.
* **Message Display:** Display user messages and AI responses clearly, distinguishing between the two.
5. **AI Integration:**
* **Placeholder AI Endpoint:** For the MVP, simulate AI responses. Create an API route (e.g., `POST /api/chat`) that accepts user messages and returns a predefined or slightly varied AI response. In a later stage, this would be replaced with actual LLM API calls (e.g., OpenAI, Anthropic, local models).
* **API Route for Chat:** The `/api/chat` route should handle receiving user messages, saving them to the database associated with the user's session, and returning the AI's response.
6. **Database Schema (Drizzle ORM with PostgreSQL):**
* `users` table: `id`, `name`, `email`, `password_hash`, `created_at`, `updated_at`.
* `chats` table: `id`, `user_id` (foreign key to users), `created_at`, `updated_at`.
* `messages` table: `id`, `chat_id` (foreign key to chats), `sender` ('user' or 'ai'), `content` (text), `created_at`.
* `user_privacy_settings` table: `user_id` (foreign key to users, unique), `allow_data_for_training` (boolean, default false), `created_at`, `updated_at`.
**Technical Stack & Requirements:**
* **Framework:** Next.js 13+ (App Router).
* **Database:** PostgreSQL.
* **ORM:** Drizzle ORM.
* **Authentication:** NextAuth.js.
* **Styling:** Tailwind CSS (or choose a simple, clean UI library like Shadcn/ui).
* **State Management:** React Context API or Zustand for simpler client-side state.
* **Deployment:** Ensure the structure is ready for deployment on platforms like Vercel or Netlify.
**Key Considerations for Prompt:**
* **Directory Structure:** Organize the Next.js App Router correctly (e.g., `app/`, `components/`, `lib/`, `db/`, `api/`).
* **API Routes:** Implement API routes for handling user messages, fetching chat history, managing user settings, and authentication.
* **CRUD Logic:** Ensure complete Create, Read, Update, Delete functionality for chat messages and user settings.
* **Error Handling:** Implement basic error handling for API calls and database operations.
* **Security:** Prioritize security in authentication, data handling, and API route implementation. Never expose sensitive keys directly in frontend code.