# ritammaity55/fynk architecture

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

- Interactive diagram: https://gitdiagram.com/ritammaity55/fynk
- Repository: https://github.com/ritammaity55/fynk

## Overview

##### Project type and purpose
- This is a full-stack social-media web application (“Fynk”) built with Next.js (App Router), React, TypeScript, Tailwind CSS, Prisma (PostgreSQL), Clerk (auth), and UploadThing (file uploads).
- Purpose: allow users to sign up/log in, create and view posts (with media), follow other users, receive notifications, and perform CRUD operations via a seamless, real-time UX.

##### File structure
- Top-level:
- `src/app/` – Next.js App Router pages and route-handlers (server components, API routes under `api/`).
- `src/actions/` – server-side business logic (Post, User, Profile, Notification actions).
- `src/components/` & `src/components/ui/` – reusable React components and UI primitives.
- `src/lib/` – shared utilities (`prisma.ts`, `uploadthing.ts`, `utils.ts`).
- `prisma/schema.prisma` – DB schema definition.
- Config files: `next.config.mjs`, `tailwind.config.ts`, `postcss.config.mjs`, `tsconfig.json`.
- Public assets under `public/`.
- Middlewares: `src/middleware.ts`.

##### README for additional insights
- Frontend: server and client components, dynamic/static routing, caching and revalidation.
- Backend: Next.js Route Handlers under `src/app/api/`, Prisma for DB, Clerk for auth, UploadThing for media.
- Deployment: Vercel, Netlify, AWS.

##### Main components
a. Frontend (Next.js App Router)
- Pages (Server Components)
- Client Components (e.g., `CreatePost`, `PostCard`, `Navbar`)
- UI library & theming (Tailwind, Shadcn UI)
b. API / Backend layer
- Next.js Route Handlers under `src/app/api/*`
- Server Actions (`src/actions/*.action.ts`) invoked by React components/forms
- Middleware (e.g., authentication, session)
c. Database
- PostgreSQL (connected via Prisma ORM)
d. Authentication & Authorization
- Clerk (external service for user sign-up/sign-in)
e. File Upload service
- UploadThing (external service for handling uploads)
f. Deployment / Hosting
- Vercel (or equivalent) for hosting serverless functions & static assets

##### Relationships & interactions
- Frontend pages/components → invoke Server Actions or call Route Handlers (via fetch API) → Process logic (in `src/actions` or route code) → Prisma ORM → Postgres.
- Authentication flows: Frontend ↔ Clerk SDK → Clerk service → returns session tokens → backend middleware validates.
- File uploads: Frontend uses `lib/uploadthing.ts` → UploadThing API → stores media and returns URLs → persisted via Prisma in Postgres.
- Real-time & optimistic updates: Client components subscribe/refresh after mutations.
- Deployment: code is deployed to Vercel, static assets to CDN.

##### Architectural patterns & principles
- Component separation: Server vs Client components in Next.js
- Route Handlers instead of a monolithic REST API
- Layered architecture: Presentation (React) → Application (Actions/Route Handlers) → Domain (Prisma models) → Infrastructure (DB, Clerk, UploadThing)
- Caching & revalidation strategies (ISR/SSR) for performance

##### What to label and highlight
- Call paths (e.g., “Client component → calls POST /api/tasks → invokes task.action.ts → Prisma.createTask()”).
- Middleware/authentication guard between UI and API.
- File upload flow separately (UI → lib/uploadthing → UploadThing → storage URL → Prisma).

##### Final checklist
- All major components (Frontend, API, DB, Auth, Upload service)
- Labels that map back to directory names and key files
- Annotations for architectural patterns (Server vs Client components, caching)

## Diagram (Mermaid)

```mermaid
flowchart TD
    %% UI Layer
    subgraph "UI Layer"
        direction TB
        HomePage["Home Page\n(src/app/page.tsx)"]:::frontend
        NotificationsPage["Notifications Page\n(src/app/notifications/page.tsx)"]:::frontend
        ProfilePageServer["Profile Page Server\n(src/app/profile/[username]/page.tsx)"]:::frontend
        ProfilePageClient["Profile Page Client\n(src/app/profile/[username]/ProfilePageClient.tsx)"]:::frontend
        TasksPage["Tasks Page\n(src/app/tasks/page.tsx)"]:::frontend
        CreatePost["CreatePost Component\n(src/components/CreatePost.tsx)"]:::frontend
        PostCard["PostCard Component\n(src/components/PostCard.tsx)"]:::frontend
        Navbar["Navbar\n(src/components/Navbar.tsx)"]:::frontend
        DesktopNavbar["DesktopNavbar\n(src/components/DesktopNavbar.tsx)"]:::frontend
        MobileNavbar["MobileNavbar\n(src/components/MobileNavbar.tsx)"]:::frontend
        UIPrimitives["UI Primitives\n(src/components/ui/)"]:::frontend
    end

    %% API Layer
    subgraph "API Layer"
        direction TB
        Middleware["Auth & Session Middleware\n(src/middleware.ts)"]:::backend
        TasksRoute["Tasks API Route\n(src/app/api/tasks/route.ts)"]:::backend
        UploadRoute["UploadThing Route\n(src/app/api/uploadthing/route.ts)"]:::backend
        UploadCore["UploadThing Core\n(src/app/api/uploadthing/core.ts)"]:::backend
        PostAction["Post Action\n(src/actions/post.action.ts)"]:::backend
        UserAction["User Action\n(src/actions/user.action.ts)"]:::backend
        ProfileAction["Profile Action\n(src/actions/profile.action.ts)"]:::backend
        NotificationAction["Notification Action\n(src/actions/notification.action.ts)"]:::backend
    end

    %% Data Layer
    subgraph "Data Layer"
        direction TB
        PrismaClient["Prisma Client\n(src/lib/prisma.ts)"]:::data
        PrismaSchema["DB Schema\n(prisma/schema.prisma)"]:::data
        Utils["Shared Utils\n(src/lib/utils.ts)"]:::data
        UploadLib["UploadThing SDK\n(src/lib/uploadthing.ts)"]:::data
    end

    %% External Services
    subgraph "External Services"
        direction TB
        ClerkSvc["Clerk Auth Service"]:::external
        UploadSvc["UploadThing Service"]:::external
        Postgres["PostgreSQL"]:::data
        Vercel["Vercel Hosting/CDN"]:::external
    end

    %% UI to API interactions
    HomePage -->|"fetch posts"| TasksRoute
    TasksPage -->|"fetch tasks"| TasksRoute
    NotificationsPage -->|"fetch notifications"| NotificationAction
    ProfilePageServer -->|"fetch profile data"| ProfileAction
    ProfilePageClient -->|"invoke client actions"| ProfileAction
    CreatePost -->|"calls post.action"| PostAction
    PostCard -->|"calls post.action"| PostAction
    Navbar -->|"renders variants"| DesktopNavbar
    Navbar --> DesktopNavbar
    Navbar --> MobileNavbar

    %% API internals
    TasksRoute -->|authenticate| Middleware
    UploadRoute -->|authenticate| Middleware
    Middleware --> ClerkSvc
    TasksRoute -->|calls| UserAction
    TasksRoute -->|calls| PostAction
    UploadRoute -->|uses| UploadCore
    UploadCore --> UploadLib
    PostAction -->|ORM operations| PrismaClient
    UserAction -->|ORM operations| PrismaClient
    ProfileAction -->|ORM operations| PrismaClient
    NotificationAction -->|ORM operations| PrismaClient
    PrismaClient --> PrismaSchema
    PrismaClient --> Postgres

    %% File upload flow
    CreatePost -->|"uses upload lib"| UploadLib
    UploadLib -->|upload to| UploadSvc
    UploadSvc -->|returns URL| UploadCore
    UploadCore -->|persist URL| PrismaClient

    %% Deployment
    TasksRoute --> Vercel
    HomePage --> Vercel
    Vercel --> CDN[(CDN)]:::external

    %% Click Events
    click HomePage "https://github.com/ritammaity55/fynk/blob/main/src/app/page.tsx"
    click NotificationsPage "https://github.com/ritammaity55/fynk/blob/main/src/app/notifications/page.tsx"
    click ProfilePageServer "https://github.com/ritammaity55/fynk/blob/main/src/app/profile/[username]/page.tsx"
    click ProfilePageClient "https://github.com/ritammaity55/fynk/blob/main/src/app/profile/[username]/ProfilePageClient.tsx"
    click TasksPage "https://github.com/ritammaity55/fynk/blob/main/src/app/tasks/page.tsx"
    click CreatePost "https://github.com/ritammaity55/fynk/blob/main/src/components/CreatePost.tsx"
    click PostCard "https://github.com/ritammaity55/fynk/blob/main/src/components/PostCard.tsx"
    click Navbar "https://github.com/ritammaity55/fynk/blob/main/src/components/Navbar.tsx"
    click DesktopNavbar "https://github.com/ritammaity55/fynk/blob/main/src/components/DesktopNavbar.tsx"
    click MobileNavbar "https://github.com/ritammaity55/fynk/blob/main/src/components/MobileNavbar.tsx"
    click UIPrimitives "https://github.com/ritammaity55/fynk/tree/main/src/components/ui/"
    click TasksRoute "https://github.com/ritammaity55/fynk/blob/main/src/app/api/tasks/route.ts"
    click UploadRoute "https://github.com/ritammaity55/fynk/blob/main/src/app/api/uploadthing/route.ts"
    click UploadCore "https://github.com/ritammaity55/fynk/blob/main/src/app/api/uploadthing/core.ts"
    click PostAction "https://github.com/ritammaity55/fynk/blob/main/src/actions/post.action.ts"
    click UserAction "https://github.com/ritammaity55/fynk/blob/main/src/actions/user.action.ts"
    click ProfileAction "https://github.com/ritammaity55/fynk/blob/main/src/actions/profile.action.ts"
    click NotificationAction "https://github.com/ritammaity55/fynk/blob/main/src/actions/notification.action.ts"
    click Middleware "https://github.com/ritammaity55/fynk/blob/main/src/middleware.ts"
    click PrismaClient "https://github.com/ritammaity55/fynk/blob/main/src/lib/prisma.ts"
    click PrismaSchema "https://github.com/ritammaity55/fynk/blob/main/prisma/schema.prisma"
    click UploadLib "https://github.com/ritammaity55/fynk/blob/main/src/lib/uploadthing.ts"
    click Utils "https://github.com/ritammaity55/fynk/blob/main/src/lib/utils.ts"

    %% Styles
    classDef frontend fill:#E0F7FA,stroke:#0277BD,stroke-width:1px
    classDef backend fill:#E8F5E9,stroke:#2E7D32,stroke-width:1px
    classDef data fill:#FFF3E0,stroke:#EF6C00,stroke-width:1px
    classDef external fill:#E1BEE7,stroke:#6A1B9A,stroke-width:1px
```
