# sashenjayathilaka/tik-tok-clone architecture

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

- Interactive diagram: https://gitdiagram.com/sashenjayathilaka/tik-tok-clone
- Repository: https://github.com/sashenjayathilaka/tik-tok-clone

## Overview

##### Project type and purpose
- This is a full-stack web application: a TikTok clone built with Next.js (React.js) for the client/UI, Tailwind CSS for styling, and Firebase for backend services (authentication, database, and storage).
- Purpose: allow users to sign in via Google, upload short videos, view and comment on videos, and manage their profiles – mimicking TikTok’s key features.

##### File structure
- Top-level config: `.eslintrc.json`, `next.config.js`, `tailwind.config.js`, `postcss.config.js` → project configuration for linting, Next.js settings, and CSS.
- `pages/`: Next.js routing folder.
- `pages/index.js` → homepage feed.
- `pages/auth/signin.js` → sign-in page.
- `pages/detail/[id].js` → video detail pages.
- `pages/pin/create.js` → video upload page.
- `pages/user/[id].js` → user profile pages.
- `pages/api/hello.js` → example API route (could be extended).
- `components/`: reusable UI pieces (Header, LeftHandSide, RightHandSide, Btns, Post, Comments, VideoDetail, etc.).
- `hooks/useSelectFile.js`: custom hook for file selection and preview.
- `firebase/firebase.js`: initializes and exports Firebase services (Auth, Firestore, Storage).
- `utils/constants.js`: constant values such as collection names or URLs.
- `styles/globals.css`: global CSS with Tailwind directives.
- `package.json` / `package-lock.json`: project dependencies (Next.js, React, Tailwind, Firebase).

##### README for additional insights
- Tech stack explicitly lists Next.js, React.js, Tailwind CSS, and Firebase.
- Features: video uploading, Google authentication, profile management.
- Deployment target: Vercel (Next.js’s recommended platform).

##### Main components
a. Client (Browser)
- React/Next.js frontend with pages and components, styled by Tailwind CSS.
- Communicates over HTTPS to Next.js serverless endpoints or directly to Firebase.
b. Next.js (Vercel)
- Server-Side Rendering / Static Generation of pages.
- API routes (`/api/*`) as serverless functions—optional middle-tier for business logic.
c. Firebase Services
- Authentication (Google Sign-In).
- Firestore (NoSQL database) for storing user profiles, video metadata, comments, likes.
- Storage Buckets for video file uploads and retrieval.
d. External Services
- Google OAuth / Identity Provider.
- Vercel CDN for static asset delivery.
e. Third-party libraries
- Tailwind CSS for styling.
- React Player or HTML5 video element for playback (depending on implementation).

##### Relationships and data flow
- User loads the Next.js page (SSR or SSG) served by Vercel.
- On sign-in, frontend hits Firebase Auth with Google OAuth → Firebase returns JWT tokens.
- Authenticated client fetches video metadata from Firestore via Firebase SDK (directly or via Next.js API route).
- When uploading:
- Client selects file (`useSelectFile` hook) → files uploaded to Firebase Storage.
- On upload success, metadata (video URL, user ID, description, tags) is written to Firestore.
- Comments / Likes: client reads/writes to Firestore.
- Video streaming is served directly from Firebase Storage/CDN.

##### Architectural patterns and design principles
- Jamstack style: pre-rendered pages + client-side hydration; serverless backend.
- Componentized UI → maintainable React component hierarchy.
- Single Page Application (SPA) navigation via Next.js router.
- Separation of concerns:
- Presentation (components)
- Data access (Firebase JS SDK in firebase/firebase.js)
- Business logic in API routes (if extended).
- Hooks for encapsulating stateful logic (`useSelectFile`).

## Diagram (Mermaid)

```mermaid
flowchart TD
    %% External Client
    Browser["Client Browser"]:::external

    %% Client Layer
    subgraph "Client Layer"
        subgraph "Pages"
            Index["Homepage Feed"]:::frontend
            Signin["Sign-In Page"]:::frontend
            DetailPage["Video Detail Page"]:::frontend
            UploadPage["Video Upload Page"]:::frontend
            UserProfile["User Profile Page"]:::frontend
            AppEntry["App Entry (_app.js)"]:::frontend
        end
        subgraph "UI Components"
            Header["Header & Navigation"]:::frontend
            LeftSidebar["Left Sidebar"]:::frontend
            RightSidebar["Right Sidebar"]:::frontend
            Btns["Button Controls"]:::frontend
            PostComp["Video/Post Display"]:::frontend
            CustomPosts["Custom Post Layout"]:::frontend
            DetailFeed["Detail Feed"]:::frontend
            VideoDetailComp["Video Detail & Comments Panel"]:::frontend
            CreateVideo["Create/Upload Video Form"]:::frontend
            CommentsComp["Comments List & Input"]:::frontend
            TagsComp["Tags Display"]:::frontend
            UserProfileCard["User Profile Card"]:::frontend
            Skeleton["Generic Skeleton"]:::frontend
            UploadSkeleton["Upload Skeleton"]:::frontend
            IconsOther["Icon Set (Other)"]:::frontend
            IconsTelegram["Icon Set (Telegram)"]:::frontend
            LinksComp["Links"]:::frontend
        end
        subgraph "State & Helpers"
            UseSelect["useSelectFile Hook"]:::frontend
        end
        subgraph "Utilities & Styling"
            Constants["Constants"]:::frontend
            GlobalsCSS["globals.css"]:::frontend
            TailwindConfig["tailwind.config.js"]:::frontend
            PostCSSConfig["postcss.config.js"]:::frontend
            NextConfig["next.config.js"]:::frontend
            ESLintConfig[".eslintrc.json"]:::frontend
        end
        subgraph "Static Assets"
            Public["public/"]:::frontend
        end
    end

    %% Serverless Layer
    subgraph "Serverless API Layer"
        APIHello["Example API Route"]:::backend
    end

    %% Data Layer
    subgraph "Firebase Services"
        Auth["Firebase Auth"]:::cloud
        Firestore["Firestore"]:::cloud
        Storage["Storage"]:::cloud
    end

    %% Deployment
    subgraph "Deployment & CDN"
        Vercel["Vercel CDN"]:::external
        GoogleOAuth["Google OAuth"]:::external
    end

    %% Connections
    Browser -->|"loads pages"| Index
    Browser --> Signin
    Browser --> DetailPage
    Browser --> UploadPage
    Browser --> UserProfile
    Browser --> AppEntry

    Index --> Header
    Index --> LeftSidebar
    Index --> RightSidebar
    Index --> PostComp
    Index --> CustomPosts

    DetailPage --> DetailFeed
    DetailPage --> VideoDetailComp
    DetailPage --> CommentsComp

    UploadPage --> CreateVideo
    UploadPage --> UploadSkeleton

    UserProfile --> UserProfileCard

    AppEntry --> GlobalsCSS
    AppEntry --> UseSelect

    UseSelect --> Storage

    Browser -->|"calls API"| APIHello
    APIHello --> Firestore

    Browser -->|"auth, data, storage"| Auth
    Browser --> Firestore
    Browser --> Storage

    Auth --> GoogleOAuth
    Storage --> Vercel
    GlobalsCSS --> Vercel

    %% Click Events
    click Index "https://github.com/sashenjayathilaka/tik-tok-clone/blob/master/pages/index.js"
    click Signin "https://github.com/sashenjayathilaka/tik-tok-clone/blob/master/pages/auth/signin.js"
    click DetailPage "https://github.com/sashenjayathilaka/tik-tok-clone/blob/master/pages/detail/[id].js"
    click UploadPage "https://github.com/sashenjayathilaka/tik-tok-clone/blob/master/pages/pin/create.js"
    click UserProfile "https://github.com/sashenjayathilaka/tik-tok-clone/blob/master/pages/user/[id].js"
    click AppEntry "https://github.com/sashenjayathilaka/tik-tok-clone/blob/master/pages/_app.js"
    click APIHello "https://github.com/sashenjayathilaka/tik-tok-clone/blob/master/pages/api/hello.js"
    click Header "https://github.com/sashenjayathilaka/tik-tok-clone/blob/master/components/Header.js"
    click LeftSidebar "https://github.com/sashenjayathilaka/tik-tok-clone/blob/master/components/LeftHandSide.js"
    click RightSidebar "https://github.com/sashenjayathilaka/tik-tok-clone/blob/master/components/RightHandSide.js"
    click Btns "https://github.com/sashenjayathilaka/tik-tok-clone/blob/master/components/Btns.js"
    click PostComp "https://github.com/sashenjayathilaka/tik-tok-clone/blob/master/components/Post.js"
    click CustomPosts "https://github.com/sashenjayathilaka/tik-tok-clone/blob/master/components/CustomPosts.js"
    click DetailFeed "https://github.com/sashenjayathilaka/tik-tok-clone/blob/master/components/detailsPage/DetailFeed.js"
    click VideoDetailComp "https://github.com/sashenjayathilaka/tik-tok-clone/blob/master/components/detailsPage/VideoDetail.js"
    click CreateVideo "https://github.com/sashenjayathilaka/tik-tok-clone/blob/master/components/CreateVideo.js"
    click CommentsComp "https://github.com/sashenjayathilaka/tik-tok-clone/blob/master/components/Comments.js"
    click TagsComp "https://github.com/sashenjayathilaka/tik-tok-clone/blob/master/components/Tags.js"
    click UserProfileCard "https://github.com/sashenjayathilaka/tik-tok-clone/blob/master/components/UserProfile.js"
    click Skeleton "https://github.com/sashenjayathilaka/tik-tok-clone/blob/master/components/Skeleton/Skeleton.js"
    click UploadSkeleton "https://github.com/sashenjayathilaka/tik-tok-clone/blob/master/components/Skeleton/UploadeSkeleton.js"
    click IconsOther "https://github.com/sashenjayathilaka/tik-tok-clone/blob/master/components/icon/Other.js"
    click IconsTelegram "https://github.com/sashenjayathilaka/tik-tok-clone/blob/master/components/icon/Telegram.js"
    click LinksComp "https://github.com/sashenjayathilaka/tik-tok-clone/blob/master/components/Links.js"
    click UseSelect "https://github.com/sashenjayathilaka/tik-tok-clone/blob/master/hooks/useSelectFile.js"
    click Constants "https://github.com/sashenjayathilaka/tik-tok-clone/blob/master/utils/constants.js"
    click GlobalsCSS "https://github.com/sashenjayathilaka/tik-tok-clone/blob/master/styles/globals.css"
    click TailwindConfig "https://github.com/sashenjayathilaka/tik-tok-clone/blob/master/tailwind.config.js"
    click PostCSSConfig "https://github.com/sashenjayathilaka/tik-tok-clone/blob/master/postcss.config.js"
    click NextConfig "https://github.com/sashenjayathilaka/tik-tok-clone/blob/master/next.config.js"
    click ESLintConfig "https://github.com/sashenjayathilaka/tik-tok-clone/blob/master/.eslintrc.json"
    click Public "https://github.com/sashenjayathilaka/tik-tok-clone/tree/master/public/"

    %% Styles
    classDef frontend fill:#B3CDE3,stroke:#000,stroke-width:1px
    classDef backend fill:#CCEBC5,stroke:#000,stroke-width:1px
    classDef cloud fill:#FBB4AE,stroke:#000,stroke-width:1px
    classDef external fill:#DECBE4,stroke:#000,stroke-width:1px
```
