> ## Documentation Index
> Fetch the complete documentation index at: https://pavan-c90e8846.mintlify.site/llms.txt
> Use this file to discover all available pages before exploring further.

# AI Chat Assistant and Analytics Dashboard in File Transfer Pavan

> Explore the AI chat widget and Recharts analytics dashboard in File Transfer Pavan. Get instant help, track uploads, monitor downloads, and access admin insights.

File Transfer Pavan surfaces two AI-powered interfaces. The AI Chat Assistant answers questions and guides users through features, while the Analytics Dashboard visualizes upload and download data with Recharts. This page explains how both systems work and how you can use them.

## AI Chat Assistant

The AI Chat Assistant lives in a floating widget on every page. You can ask it about features, troubleshooting steps, file sharing recommendations, and pricing. The widget supports quick replies, markdown rendering, and streaming responses from a Supabase Edge Function.

### How It Loads for Performance

The chat widget is not loaded immediately. Instead, it uses `requestIdleCallback` to defer initialization until the browser is idle, with a 3000 ms fallback timeout.

```tsx theme={null}
// Inside App.tsx
const DeferredAIChatWidget = () => {
  const [show, setShow] = useState(false);
  useEffect(() => {
    if ('requestIdleCallback' in window) {
      const id = requestIdleCallback(() => setShow(true), { timeout: 3000 });
      return () => cancelIdleCallback(id);
    } else {
      const id = setTimeout(() => setShow(true), 2000);
      return () => clearTimeout(id);
    }
  }, []);
  if (!show) return null;
  return (
    <Suspense fallback={null}>
      <AIChatWidget />
    </Suspense>
  );
};
```

The chat is also lazy-loaded via `React.lazy()`, so its JavaScript is fetched in a separate chunk only when the browser signals idle time.

<Tip>
  Because the chat loads only when the browser is idle, it adds zero impact to initial page load and keeps your Largest Contentful Paint fast.
</Tip>

### Chat Components

The chat lives in `src/components/chat/` and is built with Framer Motion, Lucide icons, and shadcn/ui. Quick replies cover uploads, size limits, secure sharing, pricing, file expiration, and PIN access. Responses are streamed token by token from the `ai-chat` Supabase Edge Function.

## Analytics Dashboard

The Analytics Dashboard visualizes your file activity. You can toggle between a 7-day and 30-day view. It tracks views, downloads, and trending patterns.

<Steps>
  <Step title="Log in and open the Dashboard">
    Log in to your account and visit `/dashboard`. The analytics section loads automatically under the **Analytics** tab.
  </Step>

  <Step title="Review upload statistics">
    The dashboard shows total files uploaded, total storage used, and categorization by file type and upload date.
  </Step>

  <Step title="Check download analytics">
    Every download increments `download_count` on the `uploaded_files` table. Per-file download totals are shown alongside the download trend line.
  </Step>

  <Step title="Explore user analytics">
    Admins can view total users and active users from the admin panel. End users see their own file activity only.
  </Step>

  <Step title="Monitor system health">
    Admins can open the **System Health Monitor** inside the admin dashboard to review storage usage and database stats.
  </Step>
</Steps>

### Recharts Visualizations

The dashboard uses Recharts for data visualization.

<CardGroup cols={2}>
  <Card title="Bar Charts" icon="bar-chart">
    Show uploads over time grouped by day or date range.
  </Card>

  <Card title="Line Charts" icon="trending-up">
    Show download trends across the selected 7-day or 30-day window.
  </Card>

  <Card title="Pie Charts" icon="pie-chart">
    Can be used to break down file types by volume or count.
  </Card>

  <Card title="Stat Cards" icon="activity">
    Surface totals for views, downloads, and percentage trends at a glance.
  </Card>
</CardGroup>

### File Download Tracking

When someone downloads a file, two things happen:

1. `download_count` is incremented on the `uploaded_files` row.
2. An event is recorded in the `file_analytics` table with the event type `download`, timestamp, IP address, and user agent.

The `file_analytics` table also records `view` events, so you can distinguish a page view from an actual download. The `get_user_file_analytics` RPC function returns this data grouped by date for charting.

## Admin Analytics Panel

Admins have access to an extended analytics panel inside `AdminDashboard.tsx`. It surfaces six management modules.

<CardGroup cols={2}>
  <Card title="User Management Stats" icon="users">
    Track total signups, active sessions, and user growth over time.
  </Card>

  <Card title="File Moderation Queue" icon="shield">
    Review and approve or remove files flagged for moderation.
  </Card>

  <Card title="System Health Monitor" icon="heart-pulse">
    Review storage usage, database connection health, and edge function status.
  </Card>

  <Card title="Bulk Notifications" icon="megaphone">
    Send notifications to all users or targeted segments.
  </Card>

  <Card title="Payment and Billing" icon="credit-card">
    Manage premium plan purchases and refund status inside Razorpay flows.
  </Card>

  <Card title="Audit Logs" icon="clipboard-list">
    Review every admin action stored in the `audit_logs` table, including action type, target, and details.
  </Card>
</CardGroup>


This documentation is built and hosted on [Mintlify](https://mintlify.com), a developer documentation platform.