# dexctor/gitstats architecture

> Architecture diagram of the GitHub repository dexctor/gitstats, 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/dexctor/gitstats
- Repository: https://github.com/dexctor/gitstats

## Overview

##### Main System Components

a) Client Layer:
- Next.js Frontend (App Router)
- React Components
- Client-side State Management (React Query indicated by QueryProvider)

b) Server Layer:
- Next.js API Routes
- Authentication System (NextAuth.js)
- GitHub API Integration

c) External Services:
- GitHub API
- Authentication Providers

##### Detailed Component Breakdown

a) Frontend Architecture:
- Pages (represented in the src/app directory)
- Components (organized by feature)
- UI Components (shadcn/ui components)
- Hooks and Utilities

b) Backend Architecture:
- API Routes
- Authentication Flow
- GitHub API Integration
- Middleware

##### Data Flow Representation

- Client-Server Communication
- API Calls to GitHub
- Authentication Flow
- State Management Flow

##### Specific Implementation Details

**[Client Layer]**
- Pages (src/app/*)
- Home (/)
- Profile (/profile)
- User Profile (/[username])
- About (/about)

- Components
- Analytics Components
- GitHubStats
- ImpactMetrics
- TechAnalysis

- UI Components
- Button
- Card
- Other UI Elements

- Feature Components
- UserSearch
- UserProfile
- TechStack

**[Server Layer]**
- API Routes
- Authentication (/api/auth/*)
- GitHub Data (/api/github/*)

- Middleware
- Authentication Check

**[External Services]**
- GitHub API
- Auth Providers

##### Important Elements to Highlight

- The Next.js App Router architecture
- Authentication flow with NextAuth.js
- GitHub API integration points
- Data fetching patterns (useGithubUser hook)
- Component hierarchy and relationships
- State management strategy

##### Technical Stack Callouts

Use of:
- Next.js 13+ (App Router)
- TypeScript
- Tailwind CSS
- shadcn/ui components
- NextAuth.js
- React Query

Remember to emphasize the modular nature of the components and how they interact with the GitHub API through the custom hooks and utility functions in the lib directory.

## Diagram (Mermaid)

```mermaid
graph TB
    subgraph Client
        Pages["Pages"]
        Components["Components"]
        StateManagement["State Management"]
        
        subgraph Pages
            Home["Home Page"]:::page
            Profile["Profile Page"]:::page
            UserProfile["User Profile Page"]:::page
            About["About Page"]:::page
        end

        subgraph Components
            Analytics["Analytics Components"]
            UIComponents["UI Components"]
            FeatureComponents["Feature Components"]

            subgraph Analytics
                GitHubStats["GitHub Stats"]:::component
                ImpactMetrics["Impact Metrics"]:::component
                TechAnalysis["Tech Analysis"]:::component
                PerfMetrics["Performance Metrics"]:::component
                TrendAnalysis["Trend Analysis"]:::component
            end

            subgraph UIComponents
                Button["Button"]:::ui
                Card["Card"]:::ui
                Badge["Badge"]:::ui
                Progress["Progress"]:::ui
                Tooltip["Tooltip"]:::ui
            end

            subgraph FeatureComponents
                UserSearch["User Search"]:::component
                UserProfileComp["User Profile"]:::component
                TechStack["Tech Stack"]:::component
                UserComparison["User Comparison"]:::component
            end
        end

        subgraph StateManagement
            QueryProvider["Query Provider"]:::state
            ThemeProvider["Theme Provider"]:::state
            ProvidersWrapper["Providers Wrapper"]:::state
        end
    end

    subgraph Server
        APIRoutes["API Routes"]
        AuthSystem["Authentication System"]
        Middleware["Middleware"]
        
        subgraph APIRoutes
            AuthRoutes["Auth Routes"]:::api
            GitHubRoutes["GitHub Routes"]:::api
        end

        subgraph AuthSystem
            AuthConfig["Auth Configuration"]:::auth
            AuthHook["Auth Hook"]:::auth
        end
    end

    subgraph External
        GitHubAPI["GitHub API"]:::external
        AuthProviders["Auth Providers"]:::external
    end

    subgraph Utils
        GitHubUtils["GitHub Utils"]:::util
        ImpactUtils["Impact Utils"]:::util
        TechAnalysisUtils["Tech Analysis Utils"]:::util
        QualityAnalysisUtils["Quality Analysis Utils"]:::util
    end

    %% Relationships
    Client --> Server
    Server --> External
    Components --> StateManagement
    APIRoutes --> GitHubAPI
    AuthSystem --> AuthProviders
    Components --> Utils
    Middleware --> AuthSystem

    %% Click Events
    click Home "https://github.com/Dexctor/gitstats/blob/main/src/app/page.tsx"
    click Profile "https://github.com/Dexctor/gitstats/blob/main/src/app/profile/page.tsx"
    click UserProfile "https://github.com/Dexctor/gitstats/blob/main/src/app/[username]/page.tsx"
    click About "https://github.com/Dexctor/gitstats/blob/main/src/app/about/page.tsx"
    click AuthConfig "https://github.com/Dexctor/gitstats/blob/main/src/app/api/auth/[...nextauth]/auth-options.ts"
    click AuthRoutes "https://github.com/Dexctor/gitstats/blob/main/src/app/api/auth/[...nextauth]/route.ts"
    click Middleware "https://github.com/Dexctor/gitstats/blob/main/src/middleware.ts"
    click AuthHook "https://github.com/Dexctor/gitstats/blob/main/src/hooks/useAuthRedirect.ts"
    click GitHubRoutes "https://github.com/Dexctor/gitstats/blob/main/src/app/api/github/[username]/route.ts"
    click GitHubUtils "https://github.com/Dexctor/gitstats/blob/main/src/lib/github.ts"
    click GitHubStats "https://github.com/Dexctor/gitstats/blob/main/src/components/GitHubStats.tsx"
    click ImpactMetrics "https://github.com/Dexctor/gitstats/blob/main/src/components/ImpactMetrics.tsx"
    click TechAnalysis "https://github.com/Dexctor/gitstats/blob/main/src/components/TechAnalysis.tsx"
    click PerfMetrics "https://github.com/Dexctor/gitstats/blob/main/src/components/PerformanceMetrics.tsx"
    click TrendAnalysis "https://github.com/Dexctor/gitstats/blob/main/src/components/TrendAnalysis.tsx"
    click Button "https://github.com/Dexctor/gitstats/blob/main/src/components/ui/button.tsx"
    click Card "https://github.com/Dexctor/gitstats/blob/main/src/components/ui/card.tsx"
    click Badge "https://github.com/Dexctor/gitstats/blob/main/src/components/ui/badge.tsx"
    click Progress "https://github.com/Dexctor/gitstats/blob/main/src/components/ui/progress.tsx"
    click Tooltip "https://github.com/Dexctor/gitstats/blob/main/src/components/ui/tooltip.tsx"
    click UserSearch "https://github.com/Dexctor/gitstats/blob/main/src/components/UserSearch.tsx"
    click UserProfileComp "https://github.com/Dexctor/gitstats/blob/main/src/components/UserProfile.tsx"
    click TechStack "https://github.com/Dexctor/gitstats/blob/main/src/components/TechStack.tsx"
    click UserComparison "https://github.com/Dexctor/gitstats/blob/main/src/components/UserComparison.tsx"
    click QueryProvider "https://github.com/Dexctor/gitstats/blob/main/src/components/QueryProvider.tsx"
    click ThemeProvider "https://github.com/Dexctor/gitstats/blob/main/src/components/ThemeProvider.tsx"
    click ProvidersWrapper "https://github.com/Dexctor/gitstats/blob/main/src/components/Providers.tsx"
    click ImpactUtils "https://github.com/Dexctor/gitstats/blob/main/src/lib/impact-utils.ts"
    click TechAnalysisUtils "https://github.com/Dexctor/gitstats/blob/main/src/lib/tech-analysis.ts"
    click QualityAnalysisUtils "https://github.com/Dexctor/gitstats/blob/main/src/lib/quality-analysis.ts"

    %% Styles
    classDef page fill:#2563eb,color:white
    classDef component fill:#4ade80,color:black
    classDef ui fill:#f97316,color:white
    classDef state fill:#8b5cf6,color:white
    classDef api fill:#06b6d4,color:white
    classDef auth fill:#eab308,color:black
    classDef external fill:#64748b,color:white
    classDef util fill:#ec4899,color:white

    %% Legend
    subgraph Legend
        L1["Page"]:::page
        L2["Component"]:::component
        L3["UI Element"]:::ui
        L4["State Management"]:::state
        L5["API Route"]:::api
        L6["Auth Component"]:::auth
        L7["External Service"]:::external
        L8["Utility"]:::util
    end
```
