You are an expert full-stack developer tasked with building a comprehensive Minimum Viable Product (MVP) for a personal finance management application called 'Financial Restart' (Finansal Yeniden Başlangıç). The application should be built using Next.js App Router (app/ directory), with a focus on multi-page structure and robust CRUD functionality. Utilize Drizzle ORM for database schema management and interaction with PostgreSQL. The application needs to support multiple user roles (e.g., regular user, potentially admin in the future). Ensure the prompt generates a complete backend API using Next.js API routes and a functional frontend based on the provided database schema.
**Database Schema (Drizzle for PostgreSQL):**
1. **Users Table:**
* `id`: UUID (primary key)
* `email`: TEXT (unique, not null)
* `password`: TEXT (not null) - Hashed
* `name`: TEXT
* `createdAt`: TIMESTAMP (default now())
* `updatedAt`: TIMESTAMP (default now())
2. **Transactions Table:**
* `id`: UUID (primary key)
* `userId`: UUID (foreign key to Users, not null)
* `type`: ENUM ('income', 'expense') (not null)
* `description`: TEXT
* `amount`: DECIMAL (not null)
* `category`: TEXT
* `date`: DATE (not null)
* `createdAt`: TIMESTAMP (default now())
* `updatedAt`: TIMESTAMP (default now())
3. **Debts Table:**
* `id`: UUID (primary key)
* `userId`: UUID (foreign key to Users, not null)
* `name`: TEXT (e.g., 'Student Loan', 'Truck Loan') (not null)
* `originalAmount`: DECIMAL (not null)
* `currentAmount`: DECIMAL (not null)
* `interestRate`: DECIMAL (e.g., 0.05 for 5%)
* `dueDate`: DATE
* `createdAt`: TIMESTAMP (default now())
* `updatedAt`: TIMESTAMP (default now())
4. **EmergencyFund Table:**
* `id`: UUID (primary key)
* `userId`: UUID (foreign key to Users, not null)
* `targetAmount`: DECIMAL (not null)
* `currentAmount`: DECIMAL (default 0)
* `createdAt`: TIMESTAMP (default now())
* `updatedAt`: TIMESTAMP (default now())
**Project Structure & Requirements:**
1. **Next.js App Router (`app/` directory):**
* Implement a multi-page structure. Key pages should include:
* `/dashboard`: Overview of finances (income, expenses, debt status, emergency fund progress).
* `/transactions`: List, add, edit, delete transactions.
* `/debts`: List, add, edit, delete debts. Include a basic repayment calculation feature.
* `/emergency-fund`: Set target, track contributions.
* `/auth/login`: User login page.
* `/auth/signup`: User registration page.
* Use React Server Components where appropriate for data fetching and static content, and Client Components for interactive elements.
2. **Drizzle ORM & PostgreSQL:**
* Set up Drizzle ORM with PostgreSQL. Define the schema provided above within Drizzle's TypeScript syntax.
* Create a `db/` directory for Drizzle schema and configuration.
* Implement database connection and operations within API routes.
3. **API Routes (`app/api/...` or `app/api/` for older structure compatibility if needed, but prefer app router conventions):**
* Create RESTful API endpoints for all CRUD operations for `Transactions`, `Debts`, and `EmergencyFund` tables.
* Implement authentication middleware (e.g., using NextAuth.js or custom JWT handling) to protect API routes and ensure users can only access their own data.
* Example API endpoints:
* `POST /api/transactions` (Create)
* `GET /api/transactions` (Read all for user)
* `GET /api/transactions/[id]` (Read single)
* `PUT /api/transactions/[id]` (Update)
* `DELETE /api/transactions/[id]` (Delete)
* Similar endpoints for `debts` and `emergency-fund`.
* Implement endpoints for user registration (`/api/auth/signup`) and login (`/api/auth/login`).
4. **Frontend Implementation:**
* Build responsive UI components using a UI library like Tailwind CSS and Shadcn/ui (or similar component library). Focus on clarity and ease of use.
* Implement forms for adding/editing data with client-side validation before API submission.
* Display data fetched from the API dynamically. Include basic charts or visual indicators for financial overview (e.g., spending by category, progress bars for goals).
5. **Authentication:**
* Implement secure user registration and login. Use bcrypt for password hashing.
* Manage user sessions securely (e.g., using HTTP-only cookies).
6. **Error Handling:**
* Implement robust error handling on both frontend and backend. Provide informative error messages to the user.
7. **Deployment Considerations:**
* Ensure the codebase is structured for easy deployment on platforms like Vercel or similar.
**Do not generate:**
* A static landing page only.
* A simple SPA without proper routing or backend logic.
* Any third-party integrations beyond core database and authentication for MVP.
* Complex UI animations or unnecessary features not core to MVP functionality.