# hiaayush30/socially architecture

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

- Interactive diagram: https://gitdiagram.com/hiaayush30/socially
- Repository: https://github.com/hiaayush30/socially

## Overview

##### Project Type and Purpose
- A Next.js front-end (src/app + src/components) serving both static and server-rendered pages.
- Next.js API routes under src/app/api providing the backend microservices.
- Prisma for ORM and migrations (prisma/schema.prisma + prisma/migrations).
- NextAuth for authentication (src/app/api/auth).
- UploadThing for media uploads (src/app/api/uploadThing + src/lib/uploadThing).
- A relational database (Postgres, MySQL, or similar) behind Prisma.
- External services: OAuth identity providers, cloud storage for images.

##### File Structure
- Top-level files: package.json, next.config.ts, tsconfig.json, lint/build configs.
- prisma/: database schema + migrations.
- public/: static assets.
- src/app/: Next.js “app router” pages—with nested (auth) and (protected) folders to enforce authentication boundaries.
- src/app/api/: segmented route handlers per domain (post, user, auth, health, uploadThing).
- src/components/: shared UI React components (landing, dashboard, profile, UI primitives).
- src/lib/: low-level abstractions (db connection, uploadThing setup, utility functions).
- src/types/: TypeScript definitions (API responses, NextAuth, Prisma schema types).

##### Relationships & Data Flows
- User → Next.js Page (SSR or CSR) → if data needed, Next.js calls internal API Route
- API Route → Prisma Client → Database → returns JSON
- Frontend JS consumes JSON, renders UI
- File upload: Frontend → UploadThing client lib → API Route issues signed upload URL → client → cloud storage → store image key in DB via another API call.
- Auth: Frontend → NextAuth client → API Route (/api/auth) → NextAuth callback → DB (sessions, users) → issue JWT/cookie → subsequent requests carry session.

##### Architectural Patterns & Design Principles
- Separation of concerns: UI vs API vs Data layer
- JAMstack-style (pre-rendered pages + API microservices)
- “App router” file-based routing in Next.js
- Prisma for type-safe DB access and migrations
- Modular API routes (domain-driven grouping: post, user, uploadThing)

## Diagram (Mermaid)

```mermaid
flowchart TB
    %% Frontend Layer
    subgraph "Client Browser" 
        direction TB
        FE1["Next.js Frontend (App Router)"]:::frontend
    end

    subgraph "Frontend Code" 
        direction TB
        RL["Root Layout"]:::frontend
        GS["Global Styles"]:::frontend
        subgraph "Public Routes" 
            direction TB
            PP["Landing Page"]:::frontend
            LP["Login Page"]:::frontend
            SP["Signup Page"]:::frontend
        end
        subgraph "Protected Routes" 
            direction TB
            PL["Protected Layout"]:::frontend
            DBP["Dashboard Page"]:::frontend
            ALP["All Posts List"]:::frontend
            RCP["Recommendations Panel"]:::frontend
            SPP["Side Profile Panel"]:::frontend
            PPg["Profile Page"]:::frontend
            UIP["User Info Panel"]:::frontend
            LO["Logout Button"]:::frontend
        end
        subgraph "Shared UI Components" 
            direction TB
            MT["Mode Toggle"]:::frontend
            GP["Global Providers"]:::frontend
            CP["Create Post UI"]:::frontend
            UP["Upload Image UI"]:::frontend
            DP["Dashboard Primitives"]:::frontend
            LH["Landing Header & Hero"]:::frontend
            EP["Edit Profile Button"]:::frontend
            GU["General UI Primitives"]:::frontend
        end
    end

    FE1 -->|renders| RL
    RL -->|imports| GS
    RL -->|routes to| PP
    RL -->|routes to| LP
    RL -->|routes to| SP
    RL -->|routes to| PL
    PL --> DBP
    DBP --> ALP
    DBP --> RCP
    DBP --> SPP
    PL --> PPg
    PPg --> UIP
    PL --> LO
    FE1 -->|uses| GP
    GP --> MT
    GP --> GU
    CP --> DP
    UP --> DP
    LH --> PP

    click RL "https://github.com/hiaayush30/socially/blob/master/src/app/layout.tsx"
    click GS "https://github.com/hiaayush30/socially/blob/master/src/app/globals.css"
    click PP "https://github.com/hiaayush30/socially/blob/master/src/app/page.tsx"
    click LP "https://github.com/hiaayush30/socially/blob/master/src/app/(auth)/login/page.tsx"
    click SP "https://github.com/hiaayush30/socially/blob/master/src/app/(auth)/signup/page.tsx"
    click SP "https://github.com/hiaayush30/socially/blob/master/src/app/(auth)/signup/form.tsx"
    click PL "https://github.com/hiaayush30/socially/blob/master/src/app/(protected)/layout.tsx"
    click DBP "https://github.com/hiaayush30/socially/blob/master/src/app/(protected)/dashboard/page.tsx"
    click ALP "https://github.com/hiaayush30/socially/blob/master/src/app/(protected)/dashboard/allPosts.tsx"
    click RCP "https://github.com/hiaayush30/socially/blob/master/src/app/(protected)/dashboard/recommendations.tsx"
    click SPP "https://github.com/hiaayush30/socially/blob/master/src/app/(protected)/dashboard/sideProfile.tsx"
    click PPg "https://github.com/hiaayush30/socially/blob/master/src/app/(protected)/profile/[userId]/page.tsx"
    click UIP "https://github.com/hiaayush30/socially/blob/master/src/app/(protected)/profile/[userId]/UserInfo.tsx"
    click LO "https://github.com/hiaayush30/socially/blob/master/src/app/(protected)/logoutButton.tsx"
    click MT "https://github.com/hiaayush30/socially/blob/master/src/components/ModeToggle.tsx"
    click GP "https://github.com/hiaayush30/socially/blob/master/src/components/Providers.tsx"
    click CP "https://github.com/hiaayush30/socially/blob/master/src/components/createPost.tsx"
    click UP "https://github.com/hiaayush30/socially/blob/master/src/components/uploadImage.tsx"
    click DP "https://github.com/hiaayush30/socially/blob/master/src/components/dashboard/post.tsx"
    click DP "https://github.com/hiaayush30/socially/blob/master/src/components/dashboard/postSeketon.tsx"
    click DP "https://github.com/hiaayush30/socially/blob/master/src/components/dashboard/LoadMore.tsx"
    click LH "https://github.com/hiaayush30/socially/blob/master/src/components/landing/Header.tsx"
    click LH "https://github.com/hiaayush30/socially/blob/master/src/components/landing/Hero.tsx"
    click EP "https://github.com/hiaayush30/socially/blob/master/src/components/profile/editProfileButton.tsx"
    click GU "https://github.com/hiaayush30/socially/blob/master/src/components/ui/button.tsx"
    click GU "https://github.com/hiaayush30/socially/blob/master/src/components/ui/dropdown-menu.tsx"
    click GU "https://github.com/hiaayush30/socially/blob/master/src/components/ui/sonner.tsx"

    %% Backend API Layer
    subgraph "API Routes" 
        direction TB
        subgraph "Auth Domain" 
            direction TB
            NA["NextAuth Handler"]:::api
            NO["NextAuth Options"]:::api
            REG["Register Endpoint"]:::api
        end
        subgraph "Post Domain" 
            direction TB
            CPo["Create Post"]:::api
            LPos["List Posts"]:::api
            LPo["Like Post"]:::api
            RPo["Retweet Post"]:::api
        end
        subgraph "User Domain" 
            direction TB
            FU["Fetch User"]:::api
            SU["Search Users"]:::api
            RU["Random Users"]:::api
        end
        subgraph "UploadThing Domain" 
            direction TB
            UTC["Upload Core"]:::api
            UTR["Upload Route"]:::api
            DI["Delete Image"]:::api
        end
        HC["Health Check"]:::api
        MW["Middleware Auth Guard"]:::middleware
    end

    FE1 -->|HTTPS /api/*| NA
    FE1 -->|HTTPS /api/auth/register| REG
    FE1 -->|HTTPS /api/post/*| CPo
    FE1 -->|HTTPS /api/user/*| FU
    FE1 -->|HTTPS /api/uploadThing/*| UTR
    FE1 -->|HTTPS /api/health| HC
    NA -->|uses| NO
    CPo -->|calls| LPos
    UTR -->|calls| UTC
    NA -->|guards| MW

    click NA "https://github.com/hiaayush30/socially/blob/master/src/app/api/auth/[...nextauth]/route.ts"
    click NO "https://github.com/hiaayush30/socially/blob/master/src/app/api/auth/[...nextauth]/options.ts"
    click REG "https://github.com/hiaayush30/socially/blob/master/src/app/api/auth/register/route.ts"
    click CPo "https://github.com/hiaayush30/socially/blob/master/src/app/api/(post)/post/route.ts"
    click LPos "https://github.com/hiaayush30/socially/blob/master/src/app/api/(post)/posts/route.ts"
    click LPo "https://github.com/hiaayush30/socially/blob/master/src/app/api/(post)/like/route.ts"
    click RPo "https://github.com/hiaayush30/socially/blob/master/src/app/api/(post)/retweet/route.ts"
    click FU "https://github.com/hiaayush30/socially/blob/master/src/app/api/(user)/user/route.ts"
    click SU "https://github.com/hiaayush30/socially/blob/master/src/app/api/(user)/searchUser/route.ts"
    click RU "https://github.com/hiaayush30/socially/blob/master/src/app/api/(user)/randomUsers/route.ts"
    click UTC "https://github.com/hiaayush30/socially/blob/master/src/app/api/(uploadThing)/uploadthing/core.ts"
    click UTR "https://github.com/hiaayush30/socially/blob/master/src/app/api/(uploadThing)/uploadthing/route.ts"
    click DI "https://github.com/hiaayush30/socially/blob/master/src/app/api/(uploadThing)/deleteImage/route.ts"
    click HC "https://github.com/hiaayush30/socially/blob/master/src/app/api/health/route.ts"
    click MW "https://github.com/hiaayush30/socially/blob/master/src/middleware.ts"

    %% Data Layer
    subgraph "Data & ORM" 
        direction TB
        PC["Prisma Client"]:::db
        SC["Schema Definition"]:::db
        MG["Migrations"]:::db
    end
    subgraph "Utilities" 
        direction TB
        DBU["DB Setup"]:::db
        UT["UploadThing SDK"]:::db
        GUt["General Utils"]:::db
    end

    PC -->|reads| SC
    PC -->|applies| MG
    PC -->|queried by| CPo
    DBU --> PC
    UT --> UTC
    GUt --> PC

    click SC "https://github.com/hiaayush30/socially/blob/master/prisma/schema.prisma"
    click MG "https://github.com/hiaayush30/socially/tree/master/prisma/migrations/"
    click DBU "https://github.com/hiaayush30/socially/blob/master/src/lib/db.ts"
    click UT "https://github.com/hiaayush30/socially/blob/master/src/lib/uploadThing.ts"
    click GUt "https://github.com/hiaayush30/socially/blob/master/src/lib/utils.ts"

    %% Database Instance
    DB[(Relational Database)]:::db
    PC -->|connects to| DB

    %% External Services
    subgraph "External Services" 
        direction TB
        OAUTH["OAuth Providers"]:::external
        STORAGE["Cloud Storage/CDN"]:::external
        HOST["Vercel Hosting"]:::external
    end

    NA -->|dotted| OAUTH
    UTR -->|dotted| STORAGE
    FE1 -->|dashed| HOST

    %% Config & Types
    CFG["Config & Tooling"]:::middleware
    TD["Type Definitions"]:::middleware

    FE1 --> CFG
    PC --> TD

    click CFG "https://github.com/hiaayush30/socially/blob/master/next.config.ts"
    click CFG "https://github.com/hiaayush30/socially/blob/master/tsconfig.json"
    click CFG "https://github.com/hiaayush30/socially/blob/master/eslint.config.mjs"
    click CFG "https://github.com/hiaayush30/socially/blob/master/package.json"
    click TD "https://github.com/hiaayush30/socially/blob/master/src/types/apiResponse.ts"
    click TD "https://github.com/hiaayush30/socially/blob/master/src/types/next-auth.d.ts"
    click TD "https://github.com/hiaayush30/socially/blob/master/src/types/schema.ts"

    %% Styles
    classDef frontend fill:#cce5ff,stroke:#3366cc,color:#000
    classDef api fill:#d4edda,stroke:#28a745,color:#000
    classDef db fill:#ffe5b4,stroke:#ff9900,color:#000
    classDef external fill:#e2e3e5,stroke:#6c757d,color:#000
    classDef middleware fill:#f8d7da,stroke:#dc3545,color:#000
```
