You are an expert full-stack developer tasked with building a Minimum Viable Product (MVP) for a SaaS application called 'Team Manager'. This application is designed to help businesses manage their field teams more effectively. The MVP should be a multi-page application built with Next.js using the App Router (app/ directory). It needs to include user authentication, a robust database schema using Drizzle ORM with PostgreSQL, and full CRUD (Create, Read, Update, Delete) operations for core features.
**Core Features to Implement:**
1. **User Authentication:** Implement secure user authentication for roles: Admin and Employee. Use NextAuth.js or Clerk for this. Admins should be able to manage employees, assign tasks, and view reports. Employees should be able to view their assigned tasks and update their status.
2. **Employee Management (Admin only):**
* Create new employee accounts (name, email, phone, role).
* View a list of all employees.
* Update employee details.
* Delete employee accounts.
3. **Task Management:**
* **Admin:** Create new tasks (title, description, assigned employee, due date, priority - High/Medium/Low).
* **Admin:** View a list of all tasks, filterable by employee, status, and due date.
* **Admin:** Update task details (including status).
* **Admin:** Delete tasks.
* **Employee:** View tasks assigned to them.
* **Employee:** Update task status (e.g., 'Not Started', 'In Progress', 'Completed', 'Delayed').
4. **Attendance Tracking (Simple MVP):**
* **Employee:** Simple manual check-in/check-out functionality for their work shifts.
* **Admin:** View attendance records for employees.
5. **Notifications (Basic):**
* Notify employees about new task assignments.
* Notify admins about overdue tasks or critical status changes.
**Technical Requirements:**
* **Framework:** Next.js App Router (app/ directory).
* **Language:** TypeScript.
* **Database:** PostgreSQL with Drizzle ORM.
* **Styling:** Tailwind CSS.
* **State Management:** React Context API or Zustand for simplicity in the MVP.
* **API Layer:** Use Next.js API Routes within the `app/api` directory for backend logic and database interactions. Implement full CRUD functionality for all managed resources.
**Database Schema (Drizzle ORM):**
* `users` table: id, name, email, password (hashed), role ('admin' | 'employee'), createdAt, updatedAt.
* `employees` table: id, userId (foreign key to users), phoneNumber, createdAt, updatedAt. (Optional: Can merge some fields into `users` for MVP simplicity if suitable).
* `tasks` table: id, title, description, assignedToUserId (foreign key to users), createdByUserId (foreign key to users), dueDate, priority, status ('not_started' | 'in_progress' | 'completed' | 'delayed'), createdAt, updatedAt.
* `attendance` table: id, userId (foreign key to users), checkInTime, checkOutTime, createdAt.
**API Routes Structure:**
* `app/api/auth/...` for authentication endpoints.
* `app/api/users/route.ts` for user management CRUD.
* `app/api/employees/route.ts` for employee management CRUD (if separate table).
* `app/api/tasks/route.ts` for task management CRUD.
* `app/api/attendance/route.ts` for attendance tracking.
**Project Structure:**
* `app/`: Contains all route handlers and UI components.
* `layout.tsx` and `page.tsx` for the root.
* `dashboard/`: Protected route for authenticated users.
* `page.tsx`: Admin dashboard overview.
* `employees/`: Admin employee management pages.
* `tasks/`: Admin task management pages.
* `attendance/`: Admin attendance view.
* `employee/`: Protected route for employee specific views.
* `tasks/page.tsx`: Employee's assigned tasks.
* `attendance/page.tsx`: Employee's attendance tracking.
* `api/`: API routes.
* `components/`: Reusable UI components.
* `lib/`: Utility functions, database connection, Drizzle schema definitions.
* `types/`: TypeScript interfaces and types.
**Key Considerations:**
* Ensure all API routes are protected and only accessible by authenticated users with appropriate roles.
* Implement proper error handling and feedback to the user.
* The UI should be clean, responsive, and user-friendly, prioritizing mobile experience for employees.
* Do not create just a landing page or a simple SPA. The MVP must demonstrate backend functionality with CRUD operations and a multi-page structure.
* Focus on completing the core CRUD logic for tasks and user management first. Attendance and notifications can be simpler implementations for the MVP.