New Project
Minimal template for building full-stack React applications using Next.js, Vercel, and MongoDB.

-> View demo: nextjs.mongodb.com
A minimal, production-ready template for building full-stack React applications with Next.js (App Router), the MongoDB Node.js driver, TypeScript, and Tailwind CSS / shadcn/ui. Use it as a starting point for full-stack apps backed by MongoDB Atlas, with one-click deployment to Vercel.
ping health check)| Layer | Technology |
|---|---|
| Framework | Next.js 16 (App Router), React 19 |
| Language | TypeScript 5 |
| Database | MongoDB (Node.js driver mongodb v7) |
| Styling | Tailwind CSS 3, shadcn/ui, lucide-react |
| Testing | Playwright (end-to-end) |
| Hosting | Vercel |
The home page (app/page.tsx) is a server component. On render it calls
dbConnectionStatus() (db/connection-status.ts), which uses the shared MongoDB client
from lib/mongodb.ts to run a ping command and report whether the database is reachable.
The result is shown as a status badge in the UI.
Loading diagram...
Click the "Deploy" button to clone this repo, create a new Vercel project, setup the MongoDB integration, and provision a new MongoDB database:
Install the dependencies:
npm install
cp .env.example .env
Obtain the database connection string from the Cluster tab on the MongoDB Atlas Dashboard.
Update the .env file with your database connection string:
MONGODB_URI=mongodb+srv://<username>:<password>@<cluster-url>/<database>?retryWrites=true&w=majority
npm run dev
Open http://localhost:3000 with your browser to see the result.
You can start editing the page by modifying app/page.tsx. The page auto-updates as you edit the file.
Create a .env file from the example (cp .env.example .env) and set:
| Name | Required | Example | Description |
|---|---|---|---|
MONGODB_URI | Yes | mongodb+srv://user:pass@cluster0.example.mongodb.net/nextjs_template?retryWrites=true&w=majority | MongoDB connection string used by the app and the end-to-end tests |
app/ — Next.js App Router pages, layout, and global styles (app/page.tsx is the home page)db/connection-status.ts — server-side MongoDB connection health checklib/mongodb.ts — MongoDB client singleton (sets the appName connection metadata)components/ui/ — shadcn/ui componentstests/e2e/ — Playwright end-to-end tests.github/workflows/ci.yml — CI pipeline (build + e2e against MongoDB)AGENTS.md / EDD.md — guidance for AI agents and the MongoDB data modelEnd-to-end tests use Playwright and run against a real MongoDB
instance. They require MONGODB_URI to be set and the Playwright browser installed.
# one-time: install the browsernpx playwright install --with-deps chromium# run the end-to-end suite (starts the app automatically)MONGODB_URI="mongodb://localhost:27017/nextjs_template" npm run test:e2e
Expected result: the suite renders the home page and asserts the status badge shows
Database connected. The same suite runs in CI on every push and pull request via
GitHub Actions, using a mongo service container.
.env (cp .env.example .env) and set MONGODB_URI, then restart the dev server.PORT before running the tests.npx playwright install --with-deps chromium.To learn more about MongoDB, check out the MongoDB documentation:
To learn more about Next.js, take a look at the following resources:
Commit and push your code changes to your GitHub repository to automatically trigger a new deployment.