You are an expert full-stack developer tasked with building a comprehensive Minimum Viable Product (MVP) for 'Production Compass (Üretim Pusulası)', a SaaS application designed to help small-scale manufacturing businesses streamline their operations. The application should be built using Next.js with the App Router (app directory), TypeScript, Tailwind CSS for styling, and Drizzle ORM with PostgreSQL as the database. Focus on a multi-page structure, robust CRUD operations, and secure API routes.
**Project Setup:**
- Initialize a new Next.js project using `create-next-app` with the App Router enabled.
- Set up TypeScript and Tailwind CSS.
- Integrate Drizzle ORM with PostgreSQL. You will need to define the database schema within Drizzle.
**Database Schema (Drizzle ORM):**
Define the following tables:
1. `users`: id (uuid, primary key), name (text), email (text, unique), password (text), createdAt (timestamp).
2. `businesses`: id (uuid, primary key), userId (uuid, foreign key to users.id), name (text), industry (text), address (text), contactPerson (text), phoneNumber (text), createdAt (timestamp).
3. `inventoryItems`: id (uuid, primary key), businessId (uuid, foreign key to businesses.id), name (text), sku (text, unique), description (text), currentStock (integer), reorderLevel (integer), unit (text), createdAt (timestamp).
4. `orders`: id (uuid, primary key), businessId (uuid, foreign key to businesses.id), customerName (text), customerEmail (text), orderDate (timestamp), dueDate (timestamp), status (text - e.g., 'Pending', 'Processing', 'Shipped', 'Delivered', 'Cancelled'), totalAmount (decimal), createdAt (timestamp).
5. `orderItems`: id (uuid, primary key), orderId (uuid, foreign key to orders.id), inventoryItemId (uuid, foreign key to inventoryItems.id), quantity (integer), pricePerUnit (decimal), createdAt (timestamp).
6. `productionTasks`: id (uuid, primary key), businessId (uuid, foreign key to businesses.id), name (text), description (text), status (text - e.g., 'ToDo', 'InProgress', 'Done'), assignedTo (text), dueDate (timestamp), createdAt (timestamp).
**Application Structure (Next.js App Router):**
Organize the application into distinct pages and components.
**Pages (`app/` directory):**
- `/dashboard`: A central dashboard summarizing key metrics (e.g., total orders, low stock items, tasks in progress). Requires authentication.
- `/inventory`: List all inventory items. Includes functionality to add new items, view details, edit, and delete. Requires authentication.
- `/inventory/[itemId]`: Detail page for a specific inventory item.
- `/orders`: List all orders. Includes functionality to add new orders, view details, edit status, and delete. Requires authentication.
- `/orders/[orderId]`: Detail page for a specific order, showing order items.
- `/production`: List all production tasks. Includes functionality to add new tasks, update status, and delete. Requires authentication.
- `/users/login`: Login page.
- `/users/register`: Registration page.
**Authentication:**
Implement secure user authentication. Use NextAuth.js or a similar library for handling authentication and session management. Protect all routes except login and register.
**API Routes (`app/api/`):**
Create API routes for each entity to handle CRUD operations:
- `/api/inventory`: POST (create), GET (read all).
- `/api/inventory/[itemId]`: GET (read one), PUT (update), DELETE.
- `/api/orders`: POST, GET.
- `/api/orders/[orderId]`: GET, PUT, DELETE.
- `/api/orders/[orderId]/items`: POST (add item to order), GET (list items for an order).
- `/api/production`: POST, GET.
- `/api/production/[taskId]`: GET, PUT, DELETE.
- `/api/auth`: For NextAuth.js integration.
**Frontend Components:**
- Build reusable UI components using React and Tailwind CSS (e.g., forms, tables, buttons, modals).
- Implement client-side logic for forms and dynamic data display.
- Ensure a responsive design that works well on different devices.
**Core Functionality:**
- **Inventory Management:** Implement full CRUD for inventory items. Add logic for `reorderLevel` to flag low-stock items on the dashboard and inventory page.
- **Order Management:** Implement full CRUD for orders. Include functionality to add/remove `orderItems` linked to an order. Update order `status` via the API and UI.
- **Production Task Management:** Implement full CRUD for production tasks. Allow updating task `status`.
- **User Registration & Login:** Secure registration and login flows. Redirect authenticated users to the dashboard.
**Technical Considerations:**
- Use `async/await` for all asynchronous operations, especially database interactions.
- Implement proper error handling for API requests and database operations.
- Ensure data validation on both the client and server sides.
- Use environment variables for sensitive information (e.g., database URL, JWT secret).
- Structure code logically within the `app/` directory (e.g., `app/inventory/page.tsx`, `app/inventory/[itemId]/page.tsx`, `app/api/inventory/route.ts`).
**Deliverable:**
A functional MVP codebase that includes all the specified pages, API routes, database schema, and core functionalities, ready for deployment.