# arjuncodess/analyzr architecture

> Architecture diagram of the GitHub repository arjuncodess/analyzr, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2025-01-05). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/arjuncodess/analyzr
- Repository: https://github.com/arjuncodess/analyzr

## Overview

##### Main Components

a. Client-Side Components:
- Website with Tracking Script (public/tracking-script.js)
- Analyzr Dashboard (Next.js Frontend)

b. Server-Side Components:
- Next.js API Routes
- Supabase Database
- Discord Integration Service

**[Client Layer]**

**[API Layer]**

**[Service Layer]**

**[Data Layer]**

##### Detailed Component Breakdown

a. Client Layer:
- Next.js frontend with key pages:
- Dashboard (/app/dashboard)
- Authentication (/app/(auth))
- Site Analytics (/app/site/[website])
- Settings (/app/settings)

b. API Layer:
- Two main API routes:
- /api/track (for analytics tracking)
- /api/events (for custom events)

c. Service Layer:
- Analytics Service (actions/fetchAnalytics.ts)
- User Management (hooks/useUser.ts)
- Page Speed Metrics (actions/pageSpeedMetrics.ts)
- Discord Client (lib/discord-client.ts)

d. Data Layer:
- Supabase Database (config/supabase.ts)
- Data models for:
- User data
- Analytics events
- Custom events
- Website configurations

##### Flow Representations

- Data flow from client websites through the tracking script
- API request/response paths
- Discord notification flow
- Database interactions

##### Component Interactions

- How tracking script data flows to the database
- How the dashboard retrieves and displays analytics
- How custom events trigger Discord notifications
- How performance metrics are collected and processed

##### Additional Elements

Include:
- Version/environment indicators
- Security boundaries
- Error handling paths
- Caching mechanisms

##### Technical Stack Indicators

- Next.js 13+ (App Router)
- Supabase
- Discord API
- Edge Functions
- shadcn/ui components

## Diagram (Mermaid)

```mermaid
graph TB
    subgraph Client["Client Layer"]
        TS["Tracking Script"]:::client
        Dashboard["Dashboard Page"]:::client
        Auth["Authentication Page"]:::client
        SiteAnalytics["Site Analytics Page"]:::client
        Settings["Settings Page"]:::client
    end

    subgraph API["API Layer"]
        TrackAPI["/api/track"]:::api
        EventsAPI["/api/events"]:::api
    end

    subgraph Services["Service Layer"]
        Analytics["Analytics Service"]:::service
        UserMgmt["User Management"]:::service
        PageSpeed["Page Speed Metrics"]:::service
        Discord["Discord Client"]:::service
        ActiveUsers["Active Users Service"]:::service
        Views["Views Service"]:::service
    end

    subgraph Components["Core Components"]
        direction TB
        AnalyticsComp["Analytics Components"]:::component
        DiscordComp["Discord Integration Components"]:::component
        SiteMgmtComp["Site Management Components"]:::component
    end

    subgraph Data["Data Layer"]
        Supabase[(Supabase DB)]:::database
    end

    %% Connections
    TS --> TrackAPI
    TrackAPI --> Analytics
    EventsAPI --> Discord
    Dashboard --> Analytics
    SiteAnalytics --> Analytics
    Analytics --> Supabase
    UserMgmt --> Supabase
    PageSpeed --> Analytics
    Discord --> DiscordComp
    ActiveUsers --> Supabase
    Views --> Supabase

    %% Click Events
    click TS "https://github.com/arjuncodess/analyzr/blob/main/public/tracking-script.js"
    click Dashboard "https://github.com/arjuncodess/analyzr/blob/main/app/dashboard/page.tsx"
    click Auth "https://github.com/arjuncodess/analyzr/blob/main/app/(auth)/sign-in/page.tsx"
    click SiteAnalytics "https://github.com/arjuncodess/analyzr/blob/main/app/site/[website]/page.tsx"
    click Settings "https://github.com/arjuncodess/analyzr/blob/main/app/settings/page.tsx"
    click TrackAPI "https://github.com/arjuncodess/analyzr/blob/main/app/api/track/route.ts"
    click EventsAPI "https://github.com/arjuncodess/analyzr/blob/main/app/api/events/route.ts"
    click Analytics "https://github.com/arjuncodess/analyzr/blob/main/actions/fetchAnalytics.ts"
    click UserMgmt "https://github.com/arjuncodess/analyzr/blob/main/hooks/useUser.ts"
    click PageSpeed "https://github.com/arjuncodess/analyzr/blob/main/actions/pageSpeedMetrics.ts"
    click Discord "https://github.com/arjuncodess/analyzr/blob/main/lib/discord-client.ts"
    click ActiveUsers "https://github.com/arjuncodess/analyzr/blob/main/actions/fetchActiveUsers.ts"
    click Views "https://github.com/arjuncodess/analyzr/blob/main/actions/fetchViews.ts"
    click Supabase "https://github.com/arjuncodess/analyzr/blob/main/config/supabase.ts"
    click AnalyticsComp "https://github.com/arjuncodess/analyzr/blob/main/components/analytics-card.tsx"
    click DiscordComp "https://github.com/arjuncodess/analyzr/blob/main/components/discord-message.tsx"
    click SiteMgmtComp "https://github.com/arjuncodess/analyzr/blob/main/components/site-settings.tsx"

    %% Styling
    classDef client fill:#2563eb,color:white
    classDef api fill:#16a34a,color:white
    classDef service fill:#ca8a04,color:white
    classDef component fill:#9333ea,color:white
    classDef database fill:#db2777,color:white

    %% Legend
    subgraph Legend
        Client_["Client Components"]:::client
        API_["API Endpoints"]:::api
        Service_["Services"]:::service
        Component_["UI Components"]:::component
        Database_["Database"]:::database
    end
```
