Skip to content

Threads, Next.js 13 app that skyrocketed to 100 million sign-ups in less than 5 days, and dethroned giants like Twitter, ChatGPT, and TikTok to become the fastest-growing app ever! πŸš€

License

Notifications You must be signed in to change notification settings

ladunjexa/nextjs13-threads

Repository files navigation

Next.js 13 Threads

Latest release Stars Fork GitHub commits Pull requests

demo

ladunjexa License Top Language Contributors Release PRs deployment Known Vulnerabilities

🌐 Live Demo

Explore the live demonstration of the project: nextjs13-threads

πŸ“ Description

Threads web application, a social media platform that allows users to share their thoughts, with their friends and family. Threads is a full-stack web application built with TypeScript using Next.js 13 with Server Side Rendering. It uses MongoDB as a database, and Clerk as an authentication provider. It also uses UploadThing to upload images to the cloud. The application is styled with Tailwind CSS and Shadcn components.

Folder Structure
nextjs13-threads/
β”œβ”€β”€ app/
β”œ   β”œβ”€β”€ favicon.ico
β”œ   β”œβ”€β”€ globals.css
β”œ   β”œβ”€β”€ (auth)/
β”œ   β”œ   β”œβ”€β”€ onboarding/
β”œ   β”œ   β”œ   └── page.tsx
β”œ   β”œ   β”œβ”€β”€ sign-in/[[...sign-in]]/
β”œ   β”œ   β”œ   └── page.tsx
β”œ   β”œ   β”œβ”€β”€ sign-up/[[...sign-up]]/
β”œ   β”œ   β”œ   └── page.tsx
β”œ   β”œ   └── layout.tsx
β”œ   β”œβ”€β”€ (root)/
β”œ   β”œ   β”œβ”€β”€ layout.tsx
β”œ   β”œ   β”œβ”€β”€ page.tsx
β”œ   β”œ   β”œβ”€β”€ activity/
β”œ   β”œ   β”œ   └── page.tsx
β”œ   β”œ   β”œβ”€β”€ communities/
β”œ   β”œ   β”œ   β”œβ”€β”€ [id]/
β”œ   β”œ   β”œ   β”œ   └── page.tsx
β”œ   β”œ   β”œ   └── page.tsx
β”œ   β”œ   β”œβ”€β”€ create-thread/
β”œ   β”œ   β”œ   └── page.tsx
β”œ   β”œ   β”œβ”€β”€ edit-thread/[id]/
β”œ   β”œ   β”œ   └── page.tsx
β”œ   β”œ   β”œβ”€β”€ explore/
β”œ   β”œ   β”œ   └── page.tsx
β”œ   β”œ   β”œβ”€β”€ profile/
β”œ   β”œ   β”œ   β”œβ”€β”€ [id]/
β”œ   β”œ   β”œ   β”œ   └── page.tsx
β”œ   β”œ   β”œ   └── edit/
β”œ   β”œ   β”œ       └── page.tsx
β”œ   β”œ   β”œβ”€β”€ search/
β”œ   β”œ   β”œ   └── page.tsx
β”œ   β”œ   └── thread/
β”œ   β”œ       β”œβ”€β”€ [id]/
β”œ   β”œ       β”œ   └── page.tsx
β”œ   β”œ       └── reactions/[id]/
β”œ   β”œ           └── page.tsx
β”œ   └── api/
β”œ       β”œβ”€β”€ uploadthing/
β”œ       β”œ   └── page.tsx
β”œ       └── webhook/clerk/
β”œ              └── route.tsx
β”œβ”€β”€ components/
β”œ   β”œβ”€β”€ atoms/
β”œ   β”œ   β”œβ”€β”€ CommunityCard.tsx
β”œ   β”œ   β”œβ”€β”€ ThreadCard.tsx
β”œ   β”œ   └── UserCard.tsx
β”œ   β”œβ”€β”€ cards/
β”œ   β”œ   β”œβ”€β”€ EditThread.tsx
β”œ   β”œ   β”œβ”€β”€ FollowUser.tsx
β”œ   β”œ   └── ReactThread.tsx
β”œ   β”œβ”€β”€ forms/
β”œ   β”œ   β”œβ”€β”€ AccountProfile.tsx
β”œ   β”œ   β”œβ”€β”€ Comment.tsx
β”œ   β”œ   β”œβ”€β”€ DeleteThread.tsx
β”œ   β”œ   └── PostThread.tsx
β”œ   β”œβ”€β”€ shared/
β”œ   β”œ   β”œβ”€β”€ Bottombar.tsx
β”œ   β”œ   β”œβ”€β”€ Topbar.tsx
β”œ   β”œ   β”œβ”€β”€ LeftSidebar.tsx
β”œ   β”œ   β”œβ”€β”€ RightSidebar.tsx
β”œ   β”œ   β”œβ”€β”€ Pagination.tsx
β”œ   β”œ   β”œβ”€β”€ Searchbar.tsx
β”œ   β”œ   β”œβ”€β”€ ProfileHeader.tsx
β”œ   β”œ   └── ThreadsTab.tsx
β”œ   └── ui/ (generated by shadcn/ui)
β”œ       β”œβ”€β”€ button.tsx
β”œ       β”œβ”€β”€ form.tsx
β”œ       β”œβ”€β”€ input.tsx
β”œ       β”œβ”€β”€ label.tsx
β”œ       β”œβ”€β”€ tabs.tsx
β”œ       └── textarea.tsx
β”œβ”€β”€ constants/
β”œ   └── index.js
β”œβ”€β”€ lib/
β”œ   β”œβ”€β”€ mongoose.ts
β”œ   β”œβ”€β”€ uploadthing.ts
β”œ   β”œβ”€β”€ utils.ts
β”œ   β”œβ”€β”€ actions/
β”œ   β”œ   β”œβ”€β”€ community.actions.ts
β”œ   β”œ   β”œβ”€β”€ thread.actions.ts
β”œ   β”œ   └── user.actions.ts
β”œ   β”œβ”€β”€ models/
β”œ   β”œ   β”œβ”€β”€ community.model.ts
β”œ   β”œ   β”œβ”€β”€ thread.model.ts
β”œ   β”œ   └── user.model.ts
β”œ   └── validations/
β”œ       β”œβ”€β”€ thread.ts
β”œ       └── user.ts
β”œβ”€β”€ public/
β”œ   β”œβ”€β”€ next.svg
β”œ   β”œβ”€β”€ vercel.svg
β”œ   └── assets/
β”œ       └── [[...]].svg
β”œβ”€β”€ components.json
β”œβ”€β”€ middleware.ts
β”œβ”€β”€ next.config.ts
β”œβ”€β”€ package.json
β”œβ”€β”€ postcss.config.js
β”œβ”€β”€ tailwind.config.js
β”œβ”€β”€ tailwind.config.js (meaningless)
└── tsconfig.ts
Dive into each folder and see what they contain

app/

(auth)/ - (root)/ - (api)/

In the app directory, nested folders are normally mapped to URL paths. However, you can mark a folder as a Route Group to prevent the folder from being included in the route's URL path.

This allows you to organize your route segments and project files into logical groups without affecting the URL path structure.

For example,

components/

atoms/ - cards/ - forms/ - shared/ - ui/

The components directory contains all the components used in the application. The components are grouped into atoms, cards, forms, shared and ui. the ui folder generated by shadcn/ui package and contains all the required shadcn components that used in the application.

constants/

index.js

This is a JavaScript code contains all the constants used in the application, specifically the Sidebar Navigation (sidebarLinks), Profile Tabs (profileTabs) and Community Tabs (communityTabs) constants.

lib/

actions/ - models/ - validations/ - mongoose.ts - uploadthing.ts - utils.ts

The lib folder holds crucial components for Threads App:

  • actions: Manage actions for Community, Thread, and User entities using Mongoose for database interaction.
  • models: Define mongoose schemas for Community, Thread, and User entities.
  • validations: Provide validation schemas with Zod for Thread and User data.
  • mongoose.ts: Establishes and manages MongoDB connections for the application.
  • uploadthing.ts: Offers a React utility for simplified file uploads to UploadThing.
  • utils.ts: Contains various reusable utility functions.

public/

assets/ - next.svg - vercel.svg

The public directory contains the media used in the application. The assets folder contains all the images used in the application.

πŸ“– Table of Contents

Table of Contents

✨ Technologies Used

Threads is built using the following technologies:
  • TypeScript: TypeScript is a typed superset of JavaScript that compiles to plain JavaScript.
  • Next.js: Next.js is a React framework for building server-side rendered and statically generated web applications.
  • Tailwind CSS: Tailwind CSS is a utility-first CSS framework for rapidly building custom user interfaces.
  • Shadcn: Shadcn is a collection of Tailwind CSS components.
  • Clerk: Clerk is a developer-first authentication API that handles all the logic for user sign up, sign in, and more.
  • UploadThing: UploadThing is a simple, fast, and reliable file uploader for your website.
  • MongoDB: MongoDB is a general purpose, document-based, distributed database built for modern application developers and for the cloud era.
  • Mongoose: Mongoose is a MongoDB object modeling tool designed to work in an asynchronous environment.
  • Zod: Zod is a TypeScript-first schema declaration and validation library.
  • svix: Svix is a webhook proxy that allows you to receive webhooks locally.
  • Vercel: Vercel is a cloud platform for frontend developers, providing the frameworks, workflows, and infrastructure to build a faster, more personalized Web.

Technologies Used

🧰 Get Started

To get this project up and running in your development environment, follow these step-by-step instructions.

πŸ“‹ Prerequisites

In order to install and run this project locally, you would need to have the following installed on your local machine.

βš™οΈ Installation and Run Locally

Step 0:

Note ‼️ the application uses Clerk for Authentication and User Management, therefore, you need to create Clerk account here and sets the CLERK_PUBLISHABLE_KEY and CLERK_SECRET_KEY environment variables in .env file. Also, the different URLs for the Clerk sign-in, sign-up, after sign-in and after sign-up pages.

Note ‼️ the application uses a MongoDB database, therefore, you need to create a database and connect it to the application, for this, change the MONGODB_URL environment variable in .env file located in server folder.

Note ‼️ the application uses a UploadThing Cloud, therefore, you need to create UploadThing account here and sets the UPLOADTHING_SECRET and UPLOADTHING_APP_ID environment variables in .env file.

After following all the instructions above, we'll want to create a new webhook on Clerk. To do this, go to the Clerk Dashboard, click on the "Webhooks" tab, and then click "Add Endpoint". For the Endpoint URL, enter http://<PASTE-YOUR-LINK-HERE>/api/webhook/clerk. For the evetnts, select the "organization", "organizationDomain", "organizationInvitation" and "organizationMembership". Then click "Create" to create the webhook. get the signing secret and set it as CLERK_WEBHOOK_SECRET environment variable in .env file.

Step 1:

Download or clone this repo by using the link below:

git clone https://github.com/ladunjexa/nextjs13-threads.git

Step 2:

Execute the following command in the root directory of the downloaded repo in order to install dependencies:

npm install

Step 3:

Execute the following command in order to run the development server locally:

npm run dev

Step 4:

Open http://localhost:3000 with your browser to see the result.

πŸ“œ Scripts

All scripts are defined in the package.json file. Here is a list of all scripts:

Script Action
npm install Installs dependencies
npm run dev Starts local dev server at localhost:3000
npm run build Build your production site to ./dist/
npm run start Start your production site locally
npm run lint Run ESLint

πŸ”’ Environment Variables

Environment variables[^10] can be used for configuration. They must be set before running the app.

Environment variables are variables that are set in the operating system or shell, typically used to configure programs.

Threads uses Clerk, UploadThing, and MongoDB as external services. You need to create an account on each of these services and get the required credentials to run the app.

Create a .env file in the root directory of the project and add the following environment variables:

NEXT_PUBLIC_CLERK_PUBLISHABLE_KEY=<CLERK_PUBLISHABLE_KEY>
CLERK_SECRET_KEY=<CLERK_SECRET_KEY>
NEXT_CLERK_WEBHOOK_SECRET=<CLERK_WEBHOOK_SECRET>

NEXT_PUBLIC_CLERK_SIGN_IN_URL=/sign-in
NEXT_PUBLIC_CLERK_SIGN_UP_URL=/sign-up
NEXT_PUBLIC_CLERK_AFTER_SIGN_IN_URL=/onboarding
NEXT_PUBLIC_CLERK_AFTER_SIGN_UP_URL=/

MONGODB_URL=<MONGODB_URL>

UPLOADTHING_SECRET=<UPLOADTHING_SECRET>
UPLOADTHING_APP_ID=<UPLOADTHING_APP_ID>

πŸš€ Deployment

Deploy to production (manual)

You can create an optimized production build with the following command:

npm run build

Deploy on Vercel (recommended)

The easiest way to deploy this Next.js app is to use the Vercel Platform.

Deploy with Vercel

Deploy on Netlify

You can also deploy this Next.js app with Netlify.

Deploy with Netlify

Check out Next.js deployment documentation for more details.

πŸ’‘ Features

Threads web application comes with the following features:

  • CRUD Threads, Communities and Profiles
  • Like Threads
  • Multi-level Comment Threads
  • Follow Profiles
  • Search Profiles and Communities
  • Activity Feed (Likes, Comments, Follows)
  • Explore Feed (Threads of Followed Profiles)
  • Profile Tabs (Threads, Followers, Following)
  • Community Tabs (Threads, Members, Requests)
  • Suggested Communities and Profiles
  • Thread Likes Page (Profiles that liked a Thread)

and much more...

In terms of technical features, Threads web application comes with the following features:

  • TypeScripted Codebase with Next.js
  • Authentication with Clerk
  • User Management with Clerk
  • Organization Management with Clerk
  • File Upload with UploadThing
  • Server Side Rendering with Next.js
  • MongoDB Database
  • Mongoose ODM
  • Zod Validation
  • Shadcn Components
  • Tailwind CSS
  • Svix Webhook Proxy
  • Vercel Deployment

and much more..

🀳 Screenshots

Sign In

SignIn

Sign Up

SignUp

Onboarding

Onboarding

Home

Home

Explore

Explore

Search

Search

Activity

Activity

Create Thread

CreateThread

Communities

Communities

My Profile

Profile FollowersTab

Edit Profile

EditProfile

User Profile

UserProfile

Create Organization

CreateOrg

Community Profile

ComProfile

Thread Page

ThreadPage

Thread Likes Page

ThreadLikesPage

πŸ”§ Contributing

contributors

Contributions are what make the open source community such an amazing place to learn, inspire, and create. Any contributions you make are greatly appreciated.

To fix a bug or enhance an existing module, follow these steps:

  1. Fork the repo
  2. Create a new branch (git checkout -b improve-feature)
  3. Make the appropriate changes in the files
  4. Commit your changes (git commit -am 'Improve feature')
  5. Push to the branch (git push origin improve-feature)
  6. Create a Pull Request πŸŽ‰

πŸ“© Bug / Feature Request

If you find a bug (failure of a module to execute its intended function), kindly open an issue here by including the issue with a title and clear description.

If you'd like to request a new function, feel free to do so by opening an issue here. Please include sample queries and their corresponding results.

πŸ’Ž Acknowledgements

I'd like to express my gratitude to the following people who helped me with this project and made it possible:

πŸ“š References

Adrian Hajdin. (2023). Build and Deploy a Full Stack MERN Next.js 13 Threads App | React, Next JS, TypeScript, MongoDB. YouTube.

πŸ“ž Contact Us

Telegram LinkedIn Instagram Discord

πŸ“‹ License

Threads is open source software licensed as MIT and is free to use β€” See LICENSE for more details.

About

Threads, Next.js 13 app that skyrocketed to 100 million sign-ups in less than 5 days, and dethroned giants like Twitter, ChatGPT, and TikTok to become the fastest-growing app ever! πŸš€

Topics

Resources

License

Stars

Watchers

Forks

Sponsor this project

 

Packages

No packages published