Flick Knowledge Base

Repository docs from .qoder/repowiki

Search, browse, and read the generated project wiki without leaving the repo.

Reading
Architecture/Frontend Architecture/Admin Dashboard/Dashboard and Analytics.md
Architecture
Frontend Architecture
Admin Dashboard
Dashboard and Analytics

Dashboard and Analytics

Referenced Files in This Document

  • OverviewPage.tsx
  • TimelineChart.tsx
  • DashboardTab.tsx
  • AdminLayout.tsx
  • tabs.tsx
  • http.ts
  • admin.controller.ts
  • admin.service.ts
  • admin.repo.ts

Table of Contents

Introduction

This document explains the admin dashboard analytics and overview components. It covers:

  • OverviewPage: key metrics display, loading states, and data presentation
  • TimelineChart: vertical bar chart for time-based analytics
  • DashboardTab and AdminLayout: navigation and tab organization
  • Data aggregation patterns and administrative KPI tracking
  • Real-time update considerations and performance characteristics

Project Structure

The admin dashboard is a React application integrated with a backend service. The overview page fetches aggregated metrics from the backend and renders them in cards. Navigation is provided via a sidebar with tab entries. Charts are built using Recharts.

mermaid
graph TB
subgraph "Admin Frontend"
OP["OverviewPage.tsx"]
TC["TimelineChart.tsx"]
DT["DashboardTab.tsx"]
AL["AdminLayout.tsx"]
HT["http.ts"]
end
subgraph "Server Backend"
AC["admin.controller.ts"]
AS["admin.service.ts"]
AR["admin.repo.ts"]
end
OP --> HT
OP --> AC
AC --> AS
AS --> AR
AL --> DT
AL --> tabs["tabs.tsx"]

Diagram sources

  • OverviewPage.tsx
  • TimelineChart.tsx
  • DashboardTab.tsx
  • AdminLayout.tsx
  • tabs.tsx
  • http.ts
  • admin.controller.ts
  • admin.service.ts
  • admin.repo.ts

Section sources

  • OverviewPage.tsx
  • AdminLayout.tsx
  • tabs.tsx
  • http.ts
  • admin.controller.ts
  • admin.service.ts
  • admin.repo.ts

Core Components

  • OverviewPage: Fetches and displays total users, posts, and comments. Uses a dedicated HTTP client and handles loading and error states.
  • TimelineChart: Renders a responsive vertical bar chart from time-range data, supporting dynamic height and tooltips.
  • DashboardTab: Styled navigation link for the admin sidebar, highlighting active routes.
  • AdminLayout: Provides the admin shell with sidebar navigation, mobile menu, and outlet rendering for child pages.
  • Tabs configuration: Centralized list of navigation entries for the admin panel.

Section sources

  • OverviewPage.tsx
  • TimelineChart.tsx
  • DashboardTab.tsx
  • AdminLayout.tsx
  • tabs.tsx

Architecture Overview

The overview page integrates with the backend via a typed HTTP client. The server exposes a route that delegates to a controller and service layer, returning a simple data envelope. The UI renders cards with icons and counts.

mermaid
sequenceDiagram
participant U as "User"
participant OP as "OverviewPage.tsx"
participant AX as "http.ts"
participant AC as "admin.controller.ts"
participant AS as "admin.service.ts"
U->>OP : "Open Dashboard Overview"
OP->>AX : "GET /dashboard/overview"
AX->>AC : "Route request"
AC->>AS : "getDashboardOverview()"
AS-->>AC : "{ users, posts, comments }"
AC-->>AX : "HTTP 200 OK"
AX-->>OP : "Normalized response"
OP-->>U : "Render metrics cards"

Diagram sources

  • OverviewPage.tsx
  • http.ts
  • admin.controller.ts
  • admin.service.ts

Detailed Component Analysis

OverviewPage Implementation

OverviewPage fetches dashboard metrics and renders three summary cards:

  • Total Users
  • Total Posts
  • Total Comments

Key behaviors:

  • Uses a dedicated HTTP client to call the backend endpoint
  • Normalizes responses via interceptors
  • Handles loading state and fallback values
  • Uses Tailwind classes for theming and layout
mermaid
flowchart TD
Start(["Mount OverviewPage"]) --> CallAPI["Call http.get('/dashboard/overview')"]
CallAPI --> Resp{"Response OK?"}
Resp --> |Yes| Normalize["Normalize response via interceptor"]
Normalize --> SetData["Set state with metrics"]
Resp --> |No| HandleErr["Log error and continue"]
SetData --> Render["Render metric cards"]
HandleErr --> Render
Render --> End(["UI Ready"])

Diagram sources

  • OverviewPage.tsx
  • http.ts

Section sources

  • OverviewPage.tsx
  • http.ts
  • http.ts

TimelineChart Component

TimelineChart visualizes time-based intervals per expression category:

  • Accepts an object mapping categories to [start, end] tuples
  • Transforms data into a vertical stacked bar layout
  • Computes chart domain from maximum end time
  • Responsive container adjusts height based on number of categories
  • Includes grid, axes, tooltip, and transparent offset bars
mermaid
flowchart TD
Inp["expressions: Record<string, [number,number]>"] --> Map["Map to array with {expression,startGap,duration,end}"]
Map --> Max["Compute max end time"]
Max --> Domain["Set X-axis domain [0, max]"]
Domain --> Render["Render vertical BarChart with stacks"]
Render --> Out["ResponsiveContainer output"]

Diagram sources

  • TimelineChart.tsx
  • TimelineChart.tsx

Section sources

  • TimelineChart.tsx

DashboardTab and Navigation Organization

DashboardTab wraps NavLink to provide consistent styling and active state handling. AdminLayout composes the sidebar, mobile menu, and outlet area. The tabs configuration centralizes navigation entries.

mermaid
graph LR
tabs["tabs.tsx"] --> DT["DashboardTab.tsx"]
DT --> AL["AdminLayout.tsx"]
AL --> Outlet["<Outlet />"]

Diagram sources

  • tabs.tsx
  • DashboardTab.tsx
  • AdminLayout.tsx

Section sources

  • DashboardTab.tsx
  • AdminLayout.tsx
  • tabs.tsx

Data Aggregation Patterns and Administrative KPI Tracking

The backend currently returns placeholder metrics for users, posts, and comments. The service method logs and returns a fixed structure. Future enhancements can:

  • Query database aggregates for counts
  • Add filters for time windows
  • Introduce caching for frequent reads
  • Expose additional KPIs (e.g., growth rates, engagement)
mermaid
classDiagram
class AdminService {
+getDashboardOverview() Promise~Object~
}
class AdminController {
+getOverview() HttpResponse
}
class AdminRepo {
<<adapter>>
}
AdminController --> AdminService : "calls"
AdminService --> AdminRepo : "delegates"

Diagram sources

  • admin.controller.ts
  • admin.service.ts
  • admin.repo.ts

Section sources

  • admin.controller.ts
  • admin.service.ts
  • admin.repo.ts

Real-Time Updates and Filtering

  • Real-time updates: Not implemented in current OverviewPage; consider integrating WebSocket updates or polling for live metrics.
  • Filtering: No filter controls exist yet; add date range pickers and category selectors to TimelineChart for richer analytics.

[No sources needed since this section provides general guidance]

Dependency Analysis

The frontend depends on:

  • Axios-based HTTP client with interceptors for normalization and token injection
  • Recharts for visualization
  • React Router for navigation

The backend depends on:

  • Express controllers and services
  • Repository adapters for data access
mermaid
graph TB
OP["OverviewPage.tsx"] --> HT["http.ts"]
HT --> AC["admin.controller.ts"]
AC --> AS["admin.service.ts"]
AS --> AR["admin.repo.ts"]
AL["AdminLayout.tsx"] --> DT["DashboardTab.tsx"]
DT --> tabs["tabs.tsx"]
TC["TimelineChart.tsx"] --> recharts["Recharts"]

Diagram sources

  • OverviewPage.tsx
  • http.ts
  • admin.controller.ts
  • admin.service.ts
  • admin.repo.ts
  • AdminLayout.tsx
  • DashboardTab.tsx
  • tabs.tsx
  • TimelineChart.tsx

Section sources

  • http.ts
  • admin.controller.ts
  • admin.service.ts
  • admin.repo.ts

Performance Considerations

  • Use virtualization for large datasets in future analytics tables
  • Debounce or throttle chart interactions (e.g., tooltips, zoom)
  • Cache frequently accessed overview metrics with appropriate TTL
  • Lazy-load charts and heavy components to reduce initial bundle size
  • Monitor network latency and implement retry/backoff for API calls

[No sources needed since this section provides general guidance]

Troubleshooting Guide

Common issues and resolutions:

  • Unauthorized access: Session validation redirects to sign-in and clears invalid tokens
  • 401 responses: Automatic token refresh via interceptor queues requests until refreshed
  • Network failures: Errors are logged; ensure base URLs and credentials are configured correctly
  • Empty metrics: UI falls back to zero values; verify backend endpoint returns expected shape

Section sources

  • AdminLayout.tsx
  • http.ts
  • OverviewPage.tsx

Conclusion

The admin dashboard provides a solid foundation for analytics with a concise overview page, reusable navigation, and a flexible chart component. Extending the backend with real aggregates, adding filtering and real-time updates, and enhancing the chart with interactivity will elevate the system to a production-ready analytics hub.