You are an expert full-stack developer. Your task is to build a comprehensive MVP for a 'Flow Rhythm' application using Next.js 14 with the App Router, React, TypeScript, Tailwind CSS, Drizzle ORM (with SQLite for development simplicity, easily switchable to PostgreSQL), and NextAuth.js for authentication. The application will help users understand their natural work rhythms and energy levels to foster sustainable productivity.
**Application Structure & Technologies:**
* **Frontend**: Next.js 14 (App Router), React, TypeScript, Tailwind CSS.
* **Backend**: Next.js API Routes.
* **Database**: SQLite (Drizzle ORM for schema definition and queries).
* **Authentication**: NextAuth.js (Email/Password or OAuth providers like Google).
**Database Schema (using Drizzle ORM):**
1. **users**: `id` (primary key, string), `name` (string, nullable), `email` (string, unique), `password` (string, hashed), `emailVerified` (timestamp, nullable), `image` (string, nullable).
2. **energy_logs**: `id` (primary key, string), `userId` (string, foreign key to users.id), `logDate` (date), `hourOfDay` (number, 0-23), `energyLevel` (number, 1-5, e.g., 1=low, 5=high), `activityType` (string, enum: 'deep_work', 'shallow_work', 'break', 'meeting', 'creative', 'other'), `notes` (string, nullable), `createdAt` (timestamp).
3. **tasks**: `id` (primary key, string), `userId` (string, foreign key to users.id), `title` (string), `description` (string, nullable), `dueDate` (date, nullable), `priority` (string, enum: 'low', 'medium', 'high'), `status` (string, enum: 'todo', 'in_progress', 'done', 'archived'), `estimatedEnergy` (number, 1-5, nullable), `createdAt` (timestamp), `updatedAt` (timestamp).
**Pages (Next.js App Router):**
* `/`: Marketing Landing Page. Static content, call to action for signup/login.
* `/login`: User login page.
* `/register`: User registration page.
* `/dashboard`: Protected route. Displays a personalized overview: current day's energy log summary, upcoming tasks, and initial personalized recommendations (e.g., 'Your peak energy is usually around 10 AM for deep work').
* `/log-energy`: Protected route. A form for users to log their energy level for specific hours and associated activities. Includes options to quickly log for multiple hours or a whole day with default activities.
* `/tasks`: Protected route. A page to view, add, edit, and delete tasks. Tasks should be filterable by status, priority, and sortable by due date.
* `/insights`: Protected route. Displays visual insights using charts (e.g., Recharts or similar library) based on `energy_logs` and `tasks` data. Examples: daily average energy levels, weekly energy trends, energy levels by activity type, task completion rates over time, recommended deep work slots based on historical peaks.
* `/settings`: Protected route. User profile settings (name, email, password change).
**API Routes (Next.js):**
* `api/auth/[...nextauth]`: NextAuth.js authentication routes.
* `api/energy-logs`: Full CRUD operations for `energy_logs`.
* `GET /api/energy-logs?date=YYYY-MM-DD`: Get logs for a specific day.
* `POST /api/energy-logs`: Create a new energy log entry.
* `PUT /api/energy-logs/[id]`: Update an existing energy log entry.
* `DELETE /api/energy-logs/[id]`: Delete an energy log entry.
* `api/tasks`: Full CRUD operations for `tasks`.
* `GET /api/tasks?status=todo&priority=high`: Get tasks with filters.
* `POST /api/tasks`: Create a new task.
* `PUT /api/tasks/[id]`: Update an existing task.
* `DELETE /api/tasks/[id]`: Delete a task.
* `api/insights`: Endpoint to serve aggregated data for the `/insights` page. This route should process `energy_logs` and `tasks` to return data suitable for charting (e.g., `GET /api/insights/daily-avg-energy`, `GET /api/insights/peak-times`).
**Key Requirements for MVP Implementation:**
* **Full CRUD**: Ensure all models (`energy_logs`, `tasks`) have functional Create, Read, Update, Delete operations via API routes and corresponding frontend forms/views.
* **Authentication**: Implement protected routes for `/dashboard`, `/log-energy`, `/tasks`, `/insights`, `/settings` using NextAuth.js session management.
* **Data Visualization**: Include at least two types of charts (e.g., bar chart, line chart) on the `/insights` page to display user productivity data.
* **Responsive Design**: Use Tailwind CSS to ensure the application is functional and aesthetically pleasing on both desktop and mobile devices.
* **Error Handling**: Basic error handling for API responses and user input.
* **Code Structure**: Organize code logically within the `app/` directory, separating components, lib, db, api routes, etc.
* **Drizzle Configuration**: Set up Drizzle ORM with `drizzle-kit` for schema definition, migrations, and database interactions.
**Initial Setup Steps (within the AI's response):**
1. Project setup with `create-next-app`.
2. NextAuth.js configuration.
3. Drizzle ORM setup with SQLite.
4. Definition of Drizzle schema for `users`, `energy_logs`, `tasks`.
5. Basic implementation of the landing page and authentication routes.
6. Placeholder components and routes for the main protected pages and API endpoints.
Focus on robust functionality for the core features, demonstrating a working, multi-page application with a backend and database, not just a static display.