# geekyharsh05/redditz architecture

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

- Interactive diagram: https://gitdiagram.com/geekyharsh05/redditz
- Repository: https://github.com/geekyharsh05/redditz

## Overview

##### Project type and purpose
- This is a full‑stack social‑media web application (“Redditz”) built with Next.js App Router, React/TypeScript, Tailwind CSS, Prisma (PostgreSQL), Kinde Authentication, and UploadThing for file uploads.
- The front‑end provides pages for posts, communities (routes under `/app/post` and `/app/r`), user settings, and global UI components. The back‑end is implemented as Next.js server components, API routes, and server actions that talk to the database and third‑party services.

##### Main components
a. Client Browser (React/Next.js UI)
- Pages and client components (`app/page.tsx`, `app/post/[id]/page.tsx`, `components/ui/*`, custom components under `app/components/`)
- Theme and Auth providers (`app/providers/theme-provider.tsx`, `app/providers/auth-provider.tsx`)
b. Next.js Server Layer
- Server‑side rendering & API Routes (`app/api/*`, `route.ts`)
- Server Actions (`app/actions/*.ts`)
- Utilities (`utils/*`, `lib/utils.ts`)
c. Database
- Prisma Client calling PostgreSQL (`lib/db.ts`, `prisma/schema.prisma`)
d. External Services
- Authentication Service (Kinde Auth via `app/api/auth/[kindeAuth]/route.ts`)
- File Upload Service (UploadThing via `app/api/uploadthing/*.ts`)
e. Static Assets & CDN
- Public folder (`public/`), global CSS (`app/globals.css`, Tailwind config)

##### Relationships and data flow
- User → Browser UI → Next.js Router (App Router) → Server Components or API Routes
- Server Actions & API Routes → Prisma (`lib/db.ts`) → PostgreSQL
- File Upload Requests → UploadThing service → storage backend
- Auth flows → Kinde Auth endpoints → Next.js session state
- Theme toggles and user settings stored client‑side (Context) or persisted via server actions

##### Architectural patterns and design principles
- **App Router**: file‑based routing under `app/` with server vs client components distinction
- **Server Actions**: colocated action files (`app/actions`) that run on the server and mutate data
- **Atomic Design**: reusable UI primitives in `components/ui` and project‑specific compositions in `app/components`
- **Separation of Concerns**: UI vs data access (`lib/db.ts`), business logic in actions vs presentation
- **Third‑party integrations**: externalize auth and file storage to managed services

##### Essential architectural elements
- Separate **UI layer** from **business logic** and **data persistence**
- How **server actions** replace traditional REST endpoints for mutations
- Integration points with **Kinde Auth** and **UploadThing**
- File‑based routing and component hierarchy of the Next.js App Router

## Diagram (Mermaid)

```mermaid
flowchart TD
    %% Frontend Layer
    subgraph "Frontend (Client/UI)"
        direction TB
        HomePage["Home Page<br/>(app/page.tsx)"]:::frontend
        PostPage["Post Detail Page<br/>(app/post/[id]/page.tsx)"]:::frontend
        CommunityPage["Community Listing Page<br/>(app/r/[id]/page.tsx)"]:::frontend
        CreateCommunityPage1["Create Community (nested)<br/>(app/r/[id]/create/page.tsx)"]:::frontend
        CreateCommunityPage2["Create Community (root)<br/>(app/r/create/page.tsx)"]:::frontend
        SettingsPage["Settings Page<br/>(app/settings/page.tsx)"]:::frontend
        RootLayout["Root Layout<br/>(app/layout.tsx)"]:::frontend
        GlobalCSS["Global CSS<br/>(app/globals.css)"]:::frontend
        TailwindConfig["Tailwind Config<br/>(tailwind.config.ts)"]:::frontend
        UIPrimitives["UI Primitives<br/>(components/ui/*)"]:::frontend
        AppComponents["Project Components<br/>(app/components/*)"]:::frontend
        ThemeProvider["Theme Context<br/>(app/providers/theme-provider.tsx)"]:::frontend
        AuthProvider["Auth Context<br/>(app/providers/auth-provider.tsx)"]:::frontend
    end

    %% Backend Layer
    subgraph "Backend (Next.js Server)"
        direction TB
        ServerActions["Server Actions<br/>(app/actions/*)"]:::backend
        AuthRoutes["Auth API Routes<br/>(app/api/auth/*)"]:::backend
        UploadRoutes["UploadThing API<br/>(app/api/uploadthing/*)"]:::backend
        UtilsLayer["Utilities & Helpers<br/>(lib/utils.ts, utils/*)"]:::backend
    end

    %% Database Layer
    DBClient["Prisma Client<br/>(lib/db.ts)"]:::db
    DBSchema["Prisma Schema<br/>(prisma/schema.prisma)"]:::db

    %% Static Assets
    PublicAssets["Public Assets<br/>(public/)"]:::frontend
    Manifest["Manifest<br/>(app/manifest.json)"]:::frontend

    %% External Services
    KindeAuth((Kinde Auth Service)):::external
    UploadThingSvc((UploadThing Service)):::external

    %% Connections
    HomePage -->|"navigate/fetch"| ServerActions
    PostPage -->|"fetchPost()"| ServerActions
    CommunityPage -->|"fetchCommunity()"| ServerActions
    CreateCommunityPage1 -->|"createCommunity()"| ServerActions
    CreateCommunityPage2 -->|"createCommunity()"| ServerActions
    SettingsPage -->|"updateSettings()"| ServerActions
    ServerActions -->|"SQL queries"| DBClient
    DBClient -->|"reads schema"| DBSchema
    AuthRoutes -->|"token exchange"| KindeAuth
    UploadRoutes -->|"file upload"| UploadThingSvc
    ServerActions -->|"use utils"| UtilsLayer
    HomePage -->|"styles"| GlobalCSS
    RootLayout -->|"layout CSS"| TailwindConfig
    AppComponents -->|"use primitives"| UIPrimitives
    ThemeProvider -->|"context"| HomePage
    AuthProvider -->|"session"| HomePage
    ServerActions -->|"auth checks"| UtilsLayer

    %% Click Events
    click HomePage "https://github.com/geekyharsh05/redditz/blob/main/app/page.tsx"
    click PostPage "https://github.com/geekyharsh05/redditz/blob/main/app/post/[id]/page.tsx"
    click CommunityPage "https://github.com/geekyharsh05/redditz/blob/main/app/r/[id]/page.tsx"
    click CreateCommunityPage1 "https://github.com/geekyharsh05/redditz/blob/main/app/r/[id]/create/page.tsx"
    click CreateCommunityPage2 "https://github.com/geekyharsh05/redditz/blob/main/app/r/create/page.tsx"
    click SettingsPage "https://github.com/geekyharsh05/redditz/blob/main/app/settings/page.tsx"
    click RootLayout "https://github.com/geekyharsh05/redditz/blob/main/app/layout.tsx"
    click GlobalCSS "https://github.com/geekyharsh05/redditz/blob/main/app/globals.css"
    click TailwindConfig "https://github.com/geekyharsh05/redditz/blob/main/tailwind.config.ts"
    click UIPrimitives "https://github.com/geekyharsh05/redditz/tree/main/components/ui"
    click AppComponents "https://github.com/geekyharsh05/redditz/tree/main/app/components"
    click ThemeProvider "https://github.com/geekyharsh05/redditz/blob/main/app/providers/theme-provider.tsx"
    click AuthProvider "https://github.com/geekyharsh05/redditz/blob/main/app/providers/auth-provider.tsx"
    click ServerActions "https://github.com/geekyharsh05/redditz/tree/main/app/actions"
    click AuthRoutes "https://github.com/geekyharsh05/redditz/tree/main/app/api/auth"
    click UploadRoutes "https://github.com/geekyharsh05/redditz/tree/main/app/api/uploadthing"
    click UtilsLayer "https://github.com/geekyharsh05/redditz/blob/main/lib/utils.ts"
    click DBClient "https://github.com/geekyharsh05/redditz/blob/main/lib/db.ts"
    click DBSchema "https://github.com/geekyharsh05/redditz/blob/main/prisma/schema.prisma"
    click PublicAssets "https://github.com/geekyharsh05/redditz/tree/main/public/"
    click Manifest "https://github.com/geekyharsh05/redditz/blob/main/app/manifest.json"

    %% Styles
    classDef frontend fill:#D0E8FF,stroke:#0366D6,color:#0366D6
    classDef backend fill:#DFF7DF,stroke:#28A745,color:#28A745
    classDef db fill:#FFF4D0,stroke:#FFC107,color:#A67C00
    classDef external fill:#FFE8D6,stroke:#FF6F00,color:#BF360C
```
