You are an expert AI assistant tasked with generating the complete codebase for a single-page application (SPA) called 'Veri Gizliliği Kalkanı' (Data Privacy Shield). This application is a B2B SaaS platform designed to help organizations ensure the privacy and security of their sensitive data when working with third-party AI and data analytics firms. The core problem it addresses is the lack of transparency and control organizations have over how their data is used by external AI providers, mirroring concerns raised by events like NYC hospitals dropping Palantir due to ethical and privacy scrutiny.
**1. PROJECT OVERVIEW**
* **Purpose:** To provide a robust, transparent, and secure platform for organizations to monitor, manage, and audit the usage of their data by third-party AI and data analytics firms.
* **Problem Solved:** Organizations lack visibility into how external AI partners access and utilize their sensitive data, leading to potential privacy breaches, regulatory non-compliance (e.g., KVKK, GDPR), and reputational damage. This platform aims to bridge that gap by offering real-time monitoring, granular control, and clear audit trails.
* **Value Proposition:** Empowering organizations with complete control and transparency over their data when collaborating with AI firms, ensuring compliance, mitigating risks, and building trust.
**2. TECH STACK**
* **Frontend Framework:** React.js (using functional components and hooks)
* **Styling:** Tailwind CSS for rapid UI development and consistent design.
* **State Management:** Zustand for efficient and simple global state management. Local state will be managed with `useState` and `useReducer` where appropriate.
* **Routing:** React Router DOM for client-side navigation within the SPA.
* **UI Components:** Utilize headless UI components for accessibility and customizability (e.g., Headless UI). Consider a charting library like Chart.js or Recharts for data visualization.
* **Build Tool:** Vite for fast development server and build performance.
* **API Communication:** Axios for making HTTP requests to a mock API or a future backend.
* **Form Handling:** React Hook Form for efficient and declarative form management.
**3. CORE FEATURES (User Flow)**
* **A. Data Access & Usage Logging Dashboard:**
* **User Flow:** Upon login, the user lands on the main dashboard. The dashboard displays key metrics: total data access events, recent activities, number of monitored AI partners, and security alerts. A prominent section shows a real-time log of data access events, including timestamp, AI partner name, data category accessed, and user/system initiating the access. Users can filter logs by date range, AI partner, and data type. Clicking on a log entry provides more detail.
* **Details:** This is the central hub for monitoring. It should provide immediate insights into data interactions.
* **B. AI Partner Management:**
* **User Flow:** Users navigate to the 'AI Partners' section. They can add a new AI partner by filling out a form (Name, Contact Info, Data Usage Policy URL, Integration Type). Existing partners are listed, with options to view details, edit information, or revoke access/monitoring. Each partner has a dedicated sub-page showing their specific access logs and compliance status.
* **Details:** Manages the list of third-party AI firms the organization is working with and wants to monitor.
* **C. Policy Configuration:**
* **User Flow:** Users go to 'Policy Settings'. They can define or upload their organization's data usage policies. They can also configure specific rules, e.g., 'Prevent access to PII data for Partner X after 6 PM'. The system flags any partner activity that potentially violates these configured policies.
* **Details:** Allows organizations to set granular rules and policies that govern data access by AI partners.
* **D. Anomaly Detection & Alerts:**
* **User Flow:** The system automatically analyzes log data for suspicious patterns (e.g., unusually high data volume access, access outside business hours, access to sensitive categories by a partner not authorized for them). When an anomaly is detected, an alert is generated and displayed on the dashboard and in the 'Alerts' section. Users receive email notifications for critical alerts.
* **Details:** Proactive security feature that flags potentially risky data access behavior.
* **E. Compliance Reporting:**
* **User Flow:** Users access the 'Reports' section. They can generate pre-defined reports (e.g., Monthly Access Summary, Partner Compliance Report, Audit Trail Report) or create custom reports by selecting date ranges, partners, and data types. Reports can be downloaded in CSV or PDF format.
* **Details:** Provides evidence of data governance and compliance for internal audits and external regulators.
**4. UI/UX DESIGN**
* **Layout:** A clean, modern, and intuitive dashboard interface. A persistent sidebar navigation for accessing different sections (Dashboard, AI Partners, Policy Settings, Reports, Alerts). The main content area will display the relevant information for the selected section. Responsive design is crucial, ensuring usability on various screen sizes (desktop, tablet, mobile).
* **Color Palette:** Primary: Deep Blue (#1a202c - dark, trustworthy). Secondary: Teal/Cyan (#4fd1c5 - modern, techy). Accent: Orange/Yellow (#f6ad55 - for alerts and calls to action). Neutral: Grays for text and backgrounds (#e2e8f0, #cbd5e0, #f7fafc).
* **Typography:** Use a clean, readable sans-serif font like Inter or Roboto. Clear hierarchy using font sizes and weights.
* **Responsive Rules:** Mobile-first approach. Sidebar collapses into a hamburger menu on smaller screens. Tables should adapt (e.g., horizontal scrolling, or collapsing columns) to fit smaller viewports.
* **Components:** Utilize consistent padding, margins, and border-radius. Focus on clarity and information density without feeling cluttered.
**5. DATA MODEL (Mock Data Structure)**
* **`aiPartner` Object:**
* `id`: string (UUID)
* `name`: string
* `contactEmail`: string
* `dataPolicyUrl`: string (optional)
* `integrationDate`: ISO string
* `status`: 'active' | 'inactive' | 'pending'
* **`dataAccessLog` Object:**
* `id`: string (UUID)
* `timestamp`: ISO string
* `partnerId`: string (references `aiPartner.id`)
* `dataCategory`: string (e.g., 'Patient Records', 'Financial Data', 'User Behavior', 'PII')
* `action`: 'read' | 'write' | 'delete'
* `sourceIp`: string (optional)
* `details`: string (optional, e.g., specific record ID accessed)
* **`policy` Object:**
* `id`: string (UUID)
* `name`: string
* `description`: string
* `rules`: array of rule objects (e.g., `{ type: 'time_restriction', start: '22:00', end: '06:00', targetPartnerId: 'all' | partnerId }`)
* **`alert` Object:**
* `id`: string (UUID)
* `timestamp`: ISO string
* `logId`: string (references `dataAccessLog.id`, optional)
* `partnerId`: string (references `aiPartner.id`, optional)
* `type`: 'anomaly' | 'policy_violation' | 'unauthorized_access'
* `message`: string
* `status`: 'new' | 'acknowledged' | 'resolved'
* **Global State (Zustand):** Store lists of `aiPartners`, `dataAccessLogs`, `policies`, `alerts`. Also manage UI state like loading indicators, current filters, and user authentication status.
**6. COMPONENT BREAKDOWN**
* **`App.jsx`:** Main application component, sets up routing.
* **`Layout.jsx`:** Contains the persistent sidebar and main content area.
* **`Sidebar.jsx`:** Navigation menu component.
* **`DashboardPage.jsx`:** Main dashboard view. Contains `StatsGrid`, `RecentLogs`, `AlertsSummary`.
* **`StatsGrid.jsx`:** Displays key metrics cards.
* **`RecentLogs.jsx`:** Displays a table/list of recent data access logs.
* **`AlertsSummary.jsx`:** Shows a summary of active alerts.
* **`AIPartnersPage.jsx`:** Manages the AI partner list.
* **`AIPartnerList.jsx`:** Renders the table of AI partners.
* **`AIPartnerForm.jsx`:** Form for adding/editing partners.
* **`AIPartnerDetailView.jsx`:** Displays details for a single partner.
* **`PolicyPage.jsx`:** Manages policy configuration.
* **`PolicyList.jsx`:** Displays configured policies.
* **`PolicyForm.jsx`:** Form for creating/editing policies.
* **`ReportsPage.jsx`:** Handles report generation.
* **`ReportGenerator.jsx`:** UI for selecting report parameters.
* **`ReportViewer.jsx`:** Displays generated reports (potentially using a charting library).
* **`AlertsPage.jsx`:** Displays all generated alerts.
* **`AlertList.jsx`:** Renders the alert table.
* **`Table.jsx`:** Generic reusable table component.
* **`Modal.jsx`:** Generic modal component for forms or detailed views.
* **`Button.jsx`:** Reusable button component.
* **`Input.jsx`:** Reusable input component.
* **`LoadingSpinner.jsx`:** Displays a loading indicator.
**7. ANIMATIONS & INTERACTIONS**
* **Page Transitions:** Subtle fade-in/fade-out transitions between pages using `Framer Motion` or CSS transitions.
* **Hover Effects:** Slight scale-up or background color change on interactive elements (buttons, table rows).
* **Loading States:** Use `LoadingSpinner` components within tables or sections while data is being fetched. Skeleton loaders can enhance perceived performance.
* **Micro-interactions:** Subtle animations on form validation feedback, successful save confirmations (e.g., a small checkmark animation).
* **Chart Interactions:** Tooltips on hover for chart data points.
**8. EDGE CASES**
* **Empty States:** When lists (AI Partners, Logs, Alerts) are empty, display user-friendly messages encouraging action (e.g., 'No AI partners added yet. Click here to add one.').
* **Error Handling:** Gracefully handle API errors (e.g., network issues, server errors). Display user-friendly error messages. Implement retry mechanisms where appropriate.
* **Validation:** Use `react-hook-form` for robust form validation (e.g., email format, required fields, URL validation). Provide clear inline error messages.
* **Accessibility (a11y):** Ensure proper ARIA attributes, keyboard navigation support, focus management, and sufficient color contrast. Use semantic HTML elements.
* **Data Volume:** The `dataAccessLog` can grow very large. Ensure frontend performance by implementing pagination for tables and potentially virtualized scrolling for very long lists.
**9. SAMPLE DATA**
```json
[
{
"id": "a1b2c3d4-e5f6-7890-1234-567890abcdef",
"name": "Quantum AI Labs",
"contactEmail": "contact@quantuma.com",
"dataPolicyUrl": "https://quantuma.com/data-policy",
"integrationDate": "2023-10-01T10:00:00Z",
"status": "active"
},
{
"id": "f0e9d8c7-b6a5-4321-fedc-ba0987654321",
"name": "Insightful Analytics",
"contactEmail": "legal@insightful.com",
"dataPolicyUrl": null,
"integrationDate": "2024-01-15T14:30:00Z",
"status": "active"
}
]
[
{
"id": "log_001",
"timestamp": "2024-05-20T09:15:30Z",
"partnerId": "a1b2c3d4-e5f6-7890-1234-567890abcdef",
"dataCategory": "Patient Records",
"action": "read",
"sourceIp": "192.168.1.100",
"details": "Accessed records for patient ID: XYZ789"
},
{
"id": "log_002",
"timestamp": "2024-05-20T09:18:05Z",
"partnerId": "f0e9d8c7-b6a5-4321-fedc-ba0987654321",
"dataCategory": "User Behavior",
"action": "read",
"sourceIp": "10.0.0.5",
"details": "Analyzed session data for users in last 24h"
},
{
"id": "log_003",
"timestamp": "2024-05-20T11:05:00Z",
"partnerId": "a1b2c3d4-e5f6-7890-1234-567890abcdef",
"dataCategory": "Financial Data",
"action": "read",
"sourceIp": "192.168.1.100",
"details": "Accessed billing records for Q1 2024"
}
]
[
{
"id": "policy_01",
"name": "Strict PII Access Policy",
"description": "PII data access only allowed during business hours (9 AM - 5 PM) and requires explicit approval.",
"rules": [
{ "type": "time_restriction", "start": "09:00", "end": "17:00", "targetDataCategory": "PII" },
{ "type": "partner_allowlist", "allowedPartners": ["partner_id_1", "partner_id_3"], "targetDataCategory": "PII" }
]
}
]
[
{
"id": "alert_001",
"timestamp": "2024-05-20T10:00:00Z",
"partnerId": "a1b2c3d4-e5f6-7890-1234-567890abcdef",
"logId": "log_003",
"type": "policy_violation",
"message": "Partner 'Quantum AI Labs' accessed 'Financial Data' outside of allowed weekend hours.",
"status": "new"
}
]
```
**10. DEPLOYMENT NOTES**
* **Build Command:** `npm run build` (or `yarn build` using Vite).
* **Environment Variables:** Use `.env` files for configuration. Key variables might include `VITE_API_BASE_URL` (for mock API endpoint), `VITE_AUTH_ENABLED` (boolean flag for mock authentication).
* **Static Hosting:** The output of the build command is a set of static files, suitable for hosting on platforms like Vercel, Netlify, AWS S3, or GitHub Pages.
* **Performance Optimizations:** Code splitting (handled by Vite), lazy loading of components and routes, image optimization, and efficient state management are crucial for SPA performance, especially with large datasets.
* **Authentication:** Implement a mock authentication system for the MVP. A simple JWT-based or session-based mock login flow can be created.
* **Mock API:** For the MVP, simulate API calls using `msw` (Mock Service Worker) or simply return hardcoded mock data from local state/functions to mimic API responses. This avoids the need for a backend during initial development.