Back to templates

Template details

MongoDB Atlas Forum

A full-stack Next.js template with MongoDB, Better Auth, and a Hacker News-style post and voting system.

About this template

MongoDB Atlas Forum is a full-stack Next.js template that pairs a native MongoDB driver with Better Auth to deliver a Hacker News-style post submission and voting application. It ships as a deployable starter for React applications that need email/password authentication, server actions, and optimistic UI updates out of the box.

What is MongoDB Atlas Forum?

MongoDB Atlas Forum is a Next.js 15 App Router template for building a community news feed where users sign up, submit posts, and vote. It takes user credentials and post data as input, stores them in MongoDB via the native Node.js driver, and outputs a responsive, server-rendered feed with real-time vote updates. The template is maintained by the MongoDB Developer team and deploys directly to Vercel with a one-click button that provisions a MongoDB Atlas database and sets required environment variables.

What makes MongoDB Atlas Forum stand out?

  • Authentication with Better Auth — email/password login and signup pages, session management stored in MongoDB, and form validation for password requirements and email format.
  • Hacker News-style post system — users submit posts and vote, with ordering driven by vote counts.
  • Optimistic updates — React's useOptimistic hook updates the UI immediately on vote or submission, then reconciles with the server.
  • Server actions — form handling runs through Next.js server actions without client-side API calls.
  • Modern UI stack — shadcn/ui components styled with Tailwind CSS, Lucide React icons, and Sonner notifications; mobile-first with dark mode support.
  • MongoDB native driver — direct queries with a npm run setup-indexes script for production index creation and a real-time database connection status indicator.
  • Caching and pagination — Next.js unstable_cache with revalidation and URL-based pagination.
  • TypeScript and Zod — type-safe forms via React Hook Form and Zod schemas, with ESLint configured.
  • Included pages — home feed, login, signup, and Better Auth API routes.

Who is it for?

  • Full-stack React developers who want a working reference for wiring Better Auth sessions to a MongoDB-backed user store.
  • Teams prototyping a community or link-sharing site who need voting, pagination, and submission flows without building auth from scratch.
  • Developers learning Next.js server actions and useOptimistic who prefer a small, readable codebase over a large production app.
  • MongoDB Atlas users who want a Vercel-deployable starter that provisions an Atlas cluster through the integration.

What can you do with MongoDB Atlas Forum?

  • Launch a link-sharing community: deploy the template, point it at an Atlas cluster, and start collecting posts and votes immediately.
  • Study server-action patterns: read lib/actions.ts and lib/posts.ts to see form submissions, caching, and revalidation working together.
  • Adapt the data layer: swap the posts schema in lib/schemas.ts to model a different content type while keeping the auth and voting infrastructure.

How does MongoDB Atlas Forum work?

  1. Deploy to Vercel using the clone button (which creates the project, sets up the MongoDB Atlas integration, and adds the BETTER_AUTH_SECRET), or clone the repository and run npm install.
  2. Copy .env.example to .env and fill in MONGODB_URI, MONGODB_DB, BETTER_AUTH_URL, and a BETTER_AUTH_SECRET of at least 32 characters.
  3. Optionally run npm run setup-indexes, then npm run dev and open localhost:3000.

FAQ

Do I need a MongoDB account to run this template?

Yes. Local setup requires a MongoDB connection string, typically from an Atlas cluster, entered as MONGODB_URI in the .env file. The Vercel deploy button provisions an Atlas database automatically, but running locally means supplying your own cluster credentials.

How long must the Better Auth secret be?

The template's environment example states the BETTER_AUTH_SECRET must be at least 32 characters. The Vercel deploy flow links to a random secret generator for this value, and the BETTER_AUTH_URL should match the server origin.

Does this template use the MongoDB ORM or the native driver?

It uses the native Node.js MongoDB driver rather than an ORM such as Mongoose. An optional npm run setup-indexes script is provided to create database indexes, which the template describes as optional for production use.

Is the template TypeScript-based?

Yes. It is written in TypeScript, uses Zod for validation schemas, and includes ESLint. The stack lists Next.js 15 App Router, React Hook Form, Zod, shadcn/ui, and Tailwind CSS.

Screenshot of MongoDB Atlas Forum