OpenSocial is a social media app built with Next.js and PostgreSQL. The project is published as an advanced example for developers who want to build apps like Hacker News or Reddit.
- Login with GitHub and Magic Link (email)
- Post
- Comment
- Reply
- Vote (upvote, downvote)
- Bookmark
- Sort posts
- Search posts
- Update post scores using Cron Jobs
- User score "Karma"
- Dark mode
- Mobile friendly
-
Clone the repository:
git clone https://github.com/komzweb/open-social.git cd open-social
-
Install dependencies:
npm install
-
Set up a local PostgreSQL database:
- Install PostgreSQL if you haven't already.
- Start the
psql
command line tool:orpsql -U postgres
psql postgres
- Create a new database:
CREATE DATABASE open_social_dev;
- Exit the
psql
prompt with\q
.
-
Set up environment variables:
You can use the following command to create a
.env.local
file:cp .env.local.example .env.local
- Replace the
DB_URL
with your own values. - You can generate the
AUTH_SECRET
withnpx auth secret
. - You can get the
AUTH_GITHUB_ID
andAUTH_GITHUB_SECRET
by creating an application in the GitHub Developer Settings. - You can get the
AUTH_RESEND_KEY
by creating an account in Resend. - Vercel recommends using a random string of at least 16 characters for the
CRON_SECRET
value. You can create one with a password generator like 1Password. - You can get the
POSTGRES_*
andKV_*
environment variables by creating an account in Vercel. - Replace the
EMAIL_FROM
andEMAIL_SUPPORT
with your own values.
- Replace the
-
Run database migrations:
npm run drizzle:generate npm run drizzle:migrate
If you want to move quickly without migration files during local development, you can use the following command to push the schema to your database:
npm run drizzle:push
-
(Optional) Seed the database with sample data:
npm run db:seed
This command populates your database with sample users, posts, and comments, which can be helpful during development.
-
Run the development server:
npm run dev
-
Open http://localhost:3000 in your browser to view the app.
Before running the app, you may want to customize some aspects:
- Replace the values in
lib/constants.ts
with your own to customize the application name, organization name, and other global constants. - Update
app/apple-icon.png
,app/favicon.ico
,app/manifest.ts
, andapp/layout.tsx
with your application's metadata and icons. - Customize authentication email templates in
lib/auth-send-request.ts
to match your branding.
This project uses Vercel Cron Jobs to update post scores periodically.
- In the local development environment, post scores are not automatically updated. To manually update post scores, run the following command:
curl http://localhost:3000/api/update-post-scores
- The schedule for the Cron Job in the production environment can be set in the
vercel.json
file. Modify it as needed.
- Next.js (App Router)
- Tailwind CSS
- shadcn/ui
- Auth.js
- Resend
- Drizzle ORM (PostgreSQL)
- Vercel Postgres
- Vercel KV
We welcome contributions to the project. Before submitting a pull request, please check existing issues or create a new one to discuss your proposed changes.
This project is released under the MIT License. See the LICENSE file for details.
X/Twitter: @komzweb.