# ftanborn/tan-link architecture

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

- Interactive diagram: https://gitdiagram.com/ftanborn/tan-link
- Repository: https://github.com/ftanborn/tan-link

## Overview

##### Project type and purpose
- This is a full-stack, server-centric Next.js application (built with Next’s App Router) that provides user profiles and link dashboards.
- Key features from the file tree and README:
- Frontend pages under src/app (Home, Auth flows, Dynamic profiles via [slug], Dashboard).
- A serverless API route for Cloudinary uploads (src/app/api/cloudinary/route.ts).
- Client-side state via React Contexts (AuthContext, ThemeContext, TourContext, ProfileThemeContext).
- Integration with Firebase (src/config/firebase.ts) for auth/data and Cloudinary for media.
- Analytics service and custom hooks for tracking.

##### File structure
- Top-level Next.js config: next.config.ts, tsconfig.json, package.json, public/
- src/app (Next.js pages and layouts)
- /api/cloudinary (backend serverless function)
- /auth (login, register, setup-username flows)
- /dashboard (appearance, links, profile, stats sub-pages)
- /[slug] (public user profiles)
- /r (possibly redirect short links)
- Shared error, loading, not-found handlers and global layout.
- src/components (reusable UI elements organized by feature)
- src/context (React Context providers for auth, theme, guided tours)
- src/services & src/hooks (analytics, API wrappers, custom React hooks)
- src/config (Firebase init) and src/theme (provider)

##### README
- Confirms Next.js App Router usage, dev commands, and deployment target (Vercel).

##### Details
- Dynamic route handling ([slug] → renders ProfileComponent).
- Static assets served from public/.
- Build/config files (next.config.ts) in a “Project Config” note.

## Diagram (Mermaid)

```mermaid
flowchart TD
    subgraph "Client (Browser)"
        subgraph "Next.js Frontend (App Pages & Layouts)"
            NF["src/app"]:::frontend
            GL["layout.tsx"]:::frontend
            ER["error.tsx"]:::frontend
            LD["loading.tsx"]:::frontend
            NFN["not-found.tsx"]:::frontend
            HP["Home Page"]:::frontend
            subgraph "Auth Flows"
                LG["Login Page"]:::frontend
                RG["Register Page"]:::frontend
                SU["Setup Username Page"]:::frontend
            end
            subgraph "Dynamic User Profiles"
                PGL["Profile Layout"]:::frontend
                PG["Profile Page"]:::frontend
                PC["ProfileComponent"]:::frontend
            end
            RD["Link Redirect (/r)"]:::frontend
            subgraph "Dashboard"
                DL["Dashboard Layout"]:::frontend
                AP["Appearance Page"]:::frontend
                LP["Links Page"]:::frontend
                PP["Profile Settings Page"]:::frontend
                SP["Stats Page"]:::frontend
            end
        end
        subgraph "React Context Providers"
            AC["AuthContext"]:::frontend
            TC["ThemeContext"]:::frontend
            PTC["ProfileThemeContext"]:::frontend
            TOC["TourContext"]:::frontend
            TP["ThemeProvider"]:::frontend
        end
        SPub["public/"]:::frontend
    end

    subgraph "Server Layer"
        SSR["Next.js SSR"]:::api
        APIR["API Route: /api/cloudinary"]:::api
    end

    subgraph "Data Layer"
        FB["Firebase Auth & Database"]:::external
        CLD["Cloudinary"]:::external
        AN["Analytics Service"]:::external
    end

    subgraph "Project Config"
        NC["next.config.ts"]:::config
        TSC["tsconfig.json"]:::config
        ESL[".eslintrc.json"]:::config
        PRE[".prettierrc.js"]:::config
        PKG["package.json"]:::config
    end

    %% Connections
    NF -->|renders pages via SSR| SSR
    HP --> SSR
    LG --> SSR
    RG --> SSR
    SU --> SSR
    PG --> SSR
    RD --> SSR
    DL --> SSR
    AP --> SSR
    LP --> SSR
    PP --> SSR
    SP --> SSR

    NF -->|static assets| SPub

    AC --> NF
    TC --> NF
    PTC --> NF
    TOC --> NF
    TP --> NF

    NF -->|client reads/writes| FB
    SSR -->|server reads/writes| FB

    APIR -->|uploads| CLD
    NF -->|calls upload API| APIR

    NF -->|sends events| AN

    NC --> SSR
    TSC --> SSR
    ESL --> SSR
    PRE --> SSR
    PKG --> SSR

    %% Click Events
    click NF "https://github.com/ftanborn/tan-link/tree/main/src/app"
    click GL "https://github.com/ftanborn/tan-link/blob/main/src/app/layout.tsx"
    click ER "https://github.com/ftanborn/tan-link/blob/main/src/app/error.tsx"
    click LD "https://github.com/ftanborn/tan-link/blob/main/src/app/loading.tsx"
    click NFN "https://github.com/ftanborn/tan-link/blob/main/src/app/not-found.tsx"
    click HP "https://github.com/ftanborn/tan-link/blob/main/src/app/page.tsx"
    click LG "https://github.com/ftanborn/tan-link/blob/main/src/app/auth/login/page.tsx"
    click RG "https://github.com/ftanborn/tan-link/blob/main/src/app/auth/register/page.tsx"
    click SU "https://github.com/ftanborn/tan-link/blob/main/src/app/auth/setup-username/page.tsx"
    click PGL "https://github.com/ftanborn/tan-link/blob/main/src/app/[slug]/layout.tsx"
    click PG "https://github.com/ftanborn/tan-link/blob/main/src/app/[slug]/page.tsx"
    click PC "https://github.com/ftanborn/tan-link/blob/main/src/app/[slug]/ProfileComponent.tsx"
    click RD "https://github.com/ftanborn/tan-link/blob/main/src/app/r/page.tsx"
    click DL "https://github.com/ftanborn/tan-link/blob/main/src/app/dashboard/layout.tsx"
    click AP "https://github.com/ftanborn/tan-link/blob/main/src/app/dashboard/appearance/page.tsx"
    click LP "https://github.com/ftanborn/tan-link/blob/main/src/app/dashboard/links/page.tsx"
    click PP "https://github.com/ftanborn/tan-link/blob/main/src/app/dashboard/profile/page.tsx"
    click SP "https://github.com/ftanborn/tan-link/blob/main/src/app/dashboard/stats/page.tsx"
    click APIR "https://github.com/ftanborn/tan-link/blob/main/src/app/api/cloudinary/route.ts"
    click FB "https://github.com/ftanborn/tan-link/blob/main/src/config/firebase.ts"
    click AC "https://github.com/ftanborn/tan-link/blob/main/src/context/AuthContext.tsx"
    click TC "https://github.com/ftanborn/tan-link/blob/main/src/context/ThemeContext.tsx"
    click PTC "https://github.com/ftanborn/tan-link/blob/main/src/context/ProfileThemeContext.tsx"
    click TOC "https://github.com/ftanborn/tan-link/blob/main/src/context/TourContext.tsx"
    click TP "https://github.com/ftanborn/tan-link/blob/main/src/theme/ThemeProvider.tsx"
    click AN "https://github.com/ftanborn/tan-link/blob/main/src/services/analytics.ts"
    click AN "https://github.com/ftanborn/tan-link/blob/main/src/hooks/useAnalytics.ts"
    click SPub "https://github.com/ftanborn/tan-link/tree/main/public/"
    click NC "https://github.com/ftanborn/tan-link/blob/main/next.config.ts"
    click TSC "https://github.com/ftanborn/tan-link/blob/main/tsconfig.json"
    click ESL "https://github.com/ftanborn/tan-link/blob/main/.eslintrc.json"
    click PRE "https://github.com/ftanborn/tan-link/blob/main/.prettierrc.js"
    click PKG "https://github.com/ftanborn/tan-link/blob/main/package.json"

    %% Styles
    classDef frontend fill:#D1E8FF,stroke:#333,stroke-width:1px
    classDef api fill:#D5E8D4,stroke:#333,stroke-width:1px
    classDef external fill:#F8CECC,stroke:#333,stroke-width:1px
    classDef config fill:#FFF2CC,stroke:#333,stroke-width:1px
```
