Your task is to develop a full-stack Minimum Viable Product (MVP) application called 'Debt Saver' using Next.js 14 with the App Router (app/ directory), Drizzle ORM for database interactions, and a PostgreSQL database. The application should be a multi-page web application with robust CRUD functionalities for managing user financial data.
Project Setup:
1. Initialize a new Next.js 14 project using `create-next-app` with TypeScript, Tailwind CSS, and App Router enabled.
2. Set up Drizzle ORM to connect to a PostgreSQL database. Provide clear instructions for `drizzle.config.ts` and `schema.ts`.
3. Implement basic authentication (e.g., using NextAuth.js if simple or just local session management for MVP) to allow users to register and log in.
Database Schema (Drizzle ORM):
Create the following Drizzle schema files and tables:
* User Table (`users`):
* `id`: Primary key, UUID.
* `email`: String, unique.
* `passwordHash`: String.
* `createdAt`: Timestamp.
* `updatedAt`: Timestamp.
* Income Table (`incomes`):
* `id`: Primary key, UUID.
* `userId`: Foreign key to `users.id`.
* `amount`: Numeric.
* `source`: String (e.g., 'Salary', 'Freelance').
* `date`: Date.
* `createdAt`: Timestamp.
* Expense Table (`expenses`):
* `id`: Primary key, UUID.
* `userId`: Foreign key to `users.id`.
* `amount`: Numeric.
* `category`: String (e.g., 'Rent', 'Groceries', 'Utilities').
* `date`: Date.
* `isRecurring`: Boolean.
* `createdAt`: Timestamp.
* Debt Table (`debts`):
* `id`: Primary key, UUID.
* `userId`: Foreign key to `users.id`.
* `name`: String (e.g., 'Credit Card A', 'Student Loan').
* `originalAmount`: Numeric.
* `currentAmount`: Numeric.
* `interestRate`: Numeric (decimal percentage).
* `minimumPayment`: Numeric.
* `dueDate`: Date.
* `type`: String (e.g., 'Credit Card', 'Loan').
* `createdAt`: Timestamp.
* Debt Payment Table (`debtPayments`):
* `id`: Primary key, UUID.
* `debtId`: Foreign key to `debts.id`.
* `amount`: Numeric.
* `paymentDate`: Date.
* `createdAt`: Timestamp.
Pages (Multi-Page Structure in `app/` directory):
1. `/` (Homepage):
* A simple landing page welcoming the user.
* Links to Login and Register.
* If logged in, redirects to `/dashboard`.
2. `/register`:
* User registration form (email, password).
* Handles user creation in the `users` table.
3. `/login`:
* User login form (email, password).
* Authenticates user and sets a session.
4. `/dashboard`:
* Displays a summary of the user's current financial situation:
* Total income for the current month.
* Total expenses for the current month.
* Remaining cash flow (Income - Expenses).
* Total credit card debt.
* Overview of upcoming debt payments.
* Links to other sections (Income, Expenses, Debts).
5. `/incomes`:
* Lists all user's incomes.
* Form to add a new income.
* Option to edit/delete existing incomes.
6. `/expenses`:
* Lists all user's expenses.
* Form to add a new expense.
* Option to edit/delete existing expenses.
7. `/debts`:
* Lists all user's debts.
* Form to add a new debt.
* Option to edit/delete existing debts.
* For each debt, display its current status and links to view payment history or make a new payment.
8. `/debts/[id]` (Debt Details Page):
* Displays details of a specific debt.
* Lists all payments made towards this debt.
* Form to record a new payment for this debt.
* Visual representation of debt progress (e.g., a simple progress bar).
9. `/strategy` (Debt Strategy Page):
* Analyzes the user's current debts (amounts, interest rates).
* Suggests a personalized debt repayment strategy (e.g., 'Debt Snowball' or 'Debt Avalanche') based on the entered data.
* Provides a simple explanation of the suggested strategy.
* Displays a projected repayment timeline based on the strategy and available cash flow.
API Routes (`app/api` directory):
Implement RESTful API endpoints for full CRUD operations for each data model, secured with user authentication.
* `app/api/users`: For user registration and authentication (login).
* `app/api/incomes`:
* `GET /api/incomes`: Fetch all incomes for the authenticated user.
* `POST /api/incomes`: Create a new income record.
* `PUT /api/incomes/[id]`: Update an existing income record.
* `DELETE /api/incomes/[id]`: Delete an income record.
* `app/api/expenses`:
* `GET /api/expenses`: Fetch all expenses for the authenticated user.
* `POST /api/expenses`: Create a new expense record.
* `PUT /api/expenses/[id]`: Update an existing expense record.
* `DELETE /api/expenses/[id]`: Delete an expense record.
* `app/api/debts`:
* `GET /api/debts`: Fetch all debts for the authenticated user.
* `POST /api/debts`: Create a new debt record.
* `PUT /api/debts/[id]`: Update an existing debt record.
* `DELETE /api/debts/[id]`: Delete a debt record.
* `app/api/debt-payments`:
* `GET /api/debt-payments?debtId=[id]`: Fetch payments for a specific debt.
* `POST /api/debt-payments`: Record a new payment for a debt.
Styling:
Use Tailwind CSS for styling. Ensure a clean, intuitive, and mobile-responsive UI.
Important Considerations for AI:
* Emphasize the multi-page structure within the `app/` directory.
* Ensure Drizzle schema defines relationships correctly.
* API routes must use server actions or traditional API routes (`route.ts`) and interact with Drizzle for database operations.
* Security: Basic authentication (e.g., checking session/user ID) should be applied to all authenticated API routes and pages.
* Data validation on forms and API endpoints.