Create a full-stack Next.js application using the App Router (app directory). The application, named 'Family Finance Shield' (Aile Finans Kalkanı), should allow users to securely manage and monitor their family's finances to prevent scams and fraud, targeting older adults and their adult children. The application must support distinct roles for 'Parent' and 'Child' users.
**Database Schema (using Drizzle ORM with PostgreSQL):**
1. **`users` table:**
* `id` (UUID, Primary Key)
* `email` (VARCHAR, Unique, Not Null)
* `passwordHash` (VARCHAR, Not Null)
* `role` (ENUM: 'PARENT', 'CHILD', Not Null)
* `createdAt` (TIMESTAMP, Default NOW())
* `updatedAt` (TIMESTAMP, Default NOW())
2. **`accounts` table:**
* `id` (UUID, Primary Key)
* `userId` (UUID, Foreign Key to `users.id`, Not Null)
* `accountName` (VARCHAR, Not Null) // e.g., 'Checking Account', 'Savings Account', 'Credit Card'
* `accountType` (VARCHAR, Not Null) // e.g., 'BANK', 'INVESTMENT', 'CREDIT_CARD'
* `currentBalance` (DECIMAL(19, 4), Default 0.00)
* `createdAt` (TIMESTAMP, Default NOW())
* `updatedAt` (TIMESTAMP, Default NOW())
3. **`transactions` table:**
* `id` (UUID, Primary Key)
* `accountId` (UUID, Foreign Key to `accounts.id`, Not Null)
* `description` (VARCHAR, Not Null)
* `amount` (DECIMAL(19, 4), Not Null) // Positive for income, negative for expenses
* `transactionDate` (DATE, Not Null)
* `isSuspicious` (BOOLEAN, Default FALSE)
* `createdAt` (TIMESTAMP, Default NOW())
* `updatedAt` (TIMESTAMP, Default NOW())
4. **`alerts` table:**
* `id` (UUID, Primary Key)
* `userId` (UUID, Foreign Key to `users.id`, Not Null)
* `message` (TEXT, Not Null)
* `alertType` (VARCHAR, Not Null) // e.g., 'SUSPICIOUS_TRANSACTION', 'LOW_BALANCE', 'UNUSUAL_ACTIVITY'
* `relatedTransactionId` (UUID, Foreign Key to `transactions.id`, Nullable)
* `isRead` (BOOLEAN, Default FALSE)
* `createdAt` (TIMESTAMP, Default NOW())
5. **`family_members` table:** (To link Parent and Child users)
* `id` (UUID, Primary Key)
* `parentId` (UUID, Foreign Key to `users.id`, Not Null)
* `childId` (UUID, Foreign Key to `users.id`, Not Null)
* `createdAt` (TIMESTAMP, Default NOW())
* UNIQUE (`parentId`, `childId`)
**Application Structure & Features:**
**1. Authentication:**
* Implement secure user registration and login for both Parent and Child roles.
* Use NextAuth.js or similar for robust authentication.
* Password hashing with bcrypt.
* Implement role-based access control (RBAC) to ensure Parents can only manage their own accounts and Children can only view linked Parent accounts (if permissions are granted).
**2. User Management:**
* **Parent Dashboard (`/dashboard/parent`):**
* Overview of all linked accounts (bank, investment, credit card).
* Summary of total assets and liabilities.
* Recent transactions feed.
* List of generated alerts.
* Option to add/manage linked accounts.
* Option to invite/manage child users to view finances.
* **Child Dashboard (`/dashboard/child`):**
* View only the finances of Parent accounts they have been granted access to.
* See summarized financial status and alerts for the Parent.
* Can potentially send secure messages to the Parent.
* **Account Management (`/dashboard/parent/accounts`, `/dashboard/parent/accounts/[id]`):**
* CRUD operations for adding, editing, and deleting financial accounts.
* Manual input for account details and balance.
* (Future: Integration with Plaid or similar for automated bank feeds).
* **Transaction Management (`/dashboard/parent/accounts/[accountId]/transactions`, `/dashboard/parent/accounts/[accountId]/transactions/[id]`):**
* CRUD operations for individual transactions.
* Ability to mark transactions as suspicious.
* Categorization of transactions (manual for MVP).
* **Alerts & Notifications (`/dashboard/alerts`):**
* Display a list of all generated alerts (system-generated and potentially manually created).
* Mark alerts as read.
* Provide details about the alert, linking to relevant transactions if applicable.
* **Family Management (`/dashboard/parent/family`):**
* Invite a Child user via email.
* Manage permissions for Child users (e.g., view only, specific accounts).
**3. API Routes (within `app/api/`):**
* Implement API routes for all CRUD operations for users, accounts, transactions, and alerts.
* Ensure all API endpoints are protected and enforce role-based authorization.
* Example: `POST /api/accounts` (Create Account), `GET /api/accounts/[id]` (Get Account Details), `PUT /api/transactions/[id]` (Update Transaction), `DELETE /api/accounts/[id]` (Delete Account).
**4. Core Logic & Features:**
* **Suspicious Transaction Detection (Basic MVP):** Implement a simple rule-based system for the MVP. E.g., flag transactions exceeding a certain amount (configurable by user), or multiple large transactions within a short period. Alerts should be generated and stored in the `alerts` table.
* **Data Visualization (Basic):** Use a charting library (e.g., Chart.js, Recharts) to display simple charts on the dashboard: total assets over time, expense breakdown by category (basic manual categorization).
* **Security:** Prioritize security at all levels: input validation, parameterized queries (handled by Drizzle), proper session management, protection against common web vulnerabilities (XSS, CSRF).
**5. Frontend (using React Server Components and Client Components):**
* Build a multi-page application structure using the Next.js App Router.
* Create reusable UI components (e.g., forms, tables, cards, navigation).
* Implement client-side form validation and state management where necessary.
* Ensure a responsive design for various screen sizes.
*