You are an AI assistant tasked with developing a full-stack application. Create a comprehensive Next.js 14 application using the App Router, Drizzle ORM for PostgreSQL (or SQLite for local development), Tailwind CSS for styling, and Shadcn/ui components for a modern UI. Implement robust CRUD operations via Next.js API Routes and incorporate NextAuth.js for authentication. The application's core concept is the 'Do Nothing' method to combat procrastination.
Project Name: Do Nothing App
**Database Schema (Drizzle ORM):**
1. **`users` table:**
* `id`: `uuid('id').primaryKey().defaultRandom()`
* `email`: `varchar('email', { length: 256 }).unique().notNull()`
* `password_hash`: `varchar('password_hash', { length: 256 }).notNull()`
* `name`: `varchar('name', { length: 256 })`
* `created_at`: `timestamp('created_at').defaultNow().notNull()`
* `updated_at`: `timestamp('updated_at').defaultNow().onUpdateNow().notNull()`
2. **`sessions` table:**
* `id`: `uuid('id').primaryKey().defaultRandom()`
* `user_id`: `uuid('user_id').notNull().references(() => users.id, { onDelete: 'cascade' })`
* `start_time`: `timestamp('start_time').notNull()`
* `end_time`: `timestamp('end_time')`
* `duration_minutes`: `integer('duration_minutes')`
* `status`: `varchar('status', { enum: ['pending', 'completed', 'aborted'] }).notNull().default('pending')`
* `associated_task_id`: `uuid('associated_task_id').references(() => tasks.id, { onDelete: 'set null' })`
* `notes`: `text('notes')`
* `created_at`: `timestamp('created_at').defaultNow().notNull()`
3. **`tasks` table:**
* `id`: `uuid('id').primaryKey().defaultRandom()`
* `user_id`: `uuid('user_id').notNull().references(() => users.id, { onDelete: 'cascade' })`
* `title`: `varchar('title', { length: 256 }).notNull()`
* `description`: `text('description')`
* `due_date`: `date('due_date')`
* `priority`: `varchar('priority', { enum: ['low', 'medium', 'high'] }).default('medium').notNull()`
* `is_completed`: `boolean('is_completed').default(false).notNull()`
* `created_at`: `timestamp('created_at').defaultNow().notNull()`
* `updated_at`: `timestamp('updated_at').defaultNow().onUpdateNow().notNull()`
**Frontend Pages (Next.js App Router):**
1. **`/` (Home Page - Public):** Landing page with an explanation of the 'Do Nothing' method, app benefits, and calls to action for sign-up/login. Basic navigation header.
2. **`/login` & `/register` (Public):** Authentication pages using NextAuth.js.
3. **`/dashboard` (Protected):** Main user dashboard showing current tasks (upcoming, active, completed), a summary of 'Do Nothing' session history, and a prominent button to start a new session. Includes protected navigation to `/tasks` and `/history`.
4. **`/session/new` (Protected):** A form for configuring a new 'Do Nothing' session. Users can input a desired duration (e.g., 5, 10, 15 minutes) and optionally associate the session with an existing task or create a quick ad-hoc task. A 'Start Session' button initiates the process.
5. **`/session/[id]` (Protected - Active Session Page):** A minimalist page with a large, visible countdown timer. No other distracting UI elements. Displays text like 'Just sit and do nothing.' An 'Abort Session' button (with confirmation) is available. Upon timer completion, a prompt appears to transition to the associated task or the general task list. A small input field allows users to add quick notes or insights about the session.
6. **`/tasks` (Protected - Task Management):** Displays a list of all user's tasks. Provides a UI for creating, reading, updating (e.g., mark as complete, edit details), and deleting tasks (full CRUD). Includes filtering and sorting options by due date, priority, and status.
7. **`/history` (Protected - Session History):** Lists all past 'Do Nothing' sessions. For each session, it displays start time, end time, duration, status, associated task, and notes. Allows viewing and editing of session notes (CRUD for notes). Basic filtering/sorting by date or status.
**API Routes (Next.js API Routes):**
1. **`/api/auth/[...nextauth]`:** Handle NextAuth.js authentication (login, register, logout, session check). Implement credential provider for email/password.
2. **`/api/tasks` & `/api/tasks/[id]`:**
* `GET /api/tasks`: Fetch all tasks for the authenticated user.
* `POST /api/tasks`: Create a new task.
* `GET /api/tasks/[id]`: Fetch a single task by ID.
* `PATCH /api/tasks/[id]`: Update an existing task (e.g., title, description, due date, status, priority).
* `DELETE /api/tasks/[id]`: Delete a task.
3. **`/api/sessions` & `/api/sessions/[id]`:**
* `GET /api/sessions`: Fetch all 'Do Nothing' sessions for the authenticated user.
* `POST /api/sessions`: Start a new session (records `start_time`, `user_id`, optional `associated_task_id`, sets `status` to 'pending').
* `GET /api/sessions/[id]`: Fetch a single session by ID.
* `PATCH /api/sessions/[id]`: Update an existing session (e.g., set `end_time`, calculate `duration_minutes`, update `status` to 'completed' or 'aborted', update `notes`).
**Core Logic & Implementation Details:**
* **Authentication:** Integrate NextAuth.js with Drizzle ORM adapter. Ensure all protected routes (`/dashboard`, `/session/*`, `/tasks`, `/history`) require authentication.
* **Timer Component:** Implement a client-side countdown timer in the `/session/[id]` page. It should accurately track time, display remaining duration, and trigger a callback upon completion.
* **Session State:** Manage the active session state using React Context or Zustand/Jotai for a smooth user experience when navigating between session-related pages.
* **Styling:** Use Tailwind CSS for utility-first styling and integrate Shadcn/ui components (e.g., Button, Input, Card, Dialog, Table, Form) for a consistent and moder