How sashenjayathilaka/tik-tok-clone works
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).