DEV Community

Haseebullah
Haseebullah

Posted on

How I Structure Small-Business Web Projects with Next.js, Node.js and MongoDB

Most small businesses don't need a microservices architecture. They need a website that loads fast, an admin area they can actually use, and data they can trust. Over the past few years of building web apps for shops, cafes and other small businesses, I've settled on a simple structure that keeps projects maintainable without over-engineering them.

The stack

  • Next.js (React) for the public site and the admin dashboard
  • Node.js + Express.js for an API when the project needs one beyond Next.js API routes
  • MongoDB for flexible product/catalogue data, or MySQL when the data is strongly relational (invoices, ledgers)

Folder structure

my-shop/
├── app/                 # Next.js routes (public pages + /admin)
│   ├── (site)/          # home, products, contact
│   └── admin/           # protected dashboard
├── components/          # shared UI
├── lib/
│   ├── db.js            # single database connection
│   ├── auth.js          # session / role helpers
│   └── validators.js    # input validation schemas
├── models/              # data models (Product, Order, Customer)
└── services/            # business logic (orders, payments, stock)
Enter fullscreen mode Exit fullscreen mode

The key idea: pages call services, services call models. Pages never talk to the database directly. That makes it painless to add a mobile app or desktop client later, because the business logic already lives in one place.

Reuse one database connection

In serverless or hot-reload environments it's easy to open a new MongoDB connection on every request. Cache it:

// lib/db.js
import mongoose from 'mongoose';

let cached = global._mongo || { conn: null, promise: null };
global._mongo = cached;

export async function connectDB() {
  if (cached.conn) return cached.conn;
  if (!cached.promise) {
    cached.promise = mongoose.connect(process.env.MONGODB_URI);
  }
  cached.conn = await cached.promise;
  return cached.conn;
}
Enter fullscreen mode Exit fullscreen mode

Validate everything at the edge

Small-business admins will paste prices with currency symbols, leave fields empty and upload huge images. Validate on the server with a schema library (Zod, Joi or similar) before anything reaches the database, and return friendly error messages the admin can understand.

Build the admin panel for non-technical users

  • Use the client's vocabulary ("Orders", "Stock"), not developer terms
  • Keep the most common task (adding a product, checking today's orders) on the first screen
  • Add simple role checks so staff can't change prices or delete records

SEO is part of the build, not an afterthought

Because I also work in digital marketing, I treat SEO as a development requirement:

  • Server-render product and category pages
  • Generate unique titles and meta descriptions from product data
  • Add structured data (Product, LocalBusiness) where it fits
  • Create a sitemap automatically on build

Wrapping up

None of this is fancy, and that's the point. A predictable structure means the next developer (or future you) can open the project and understand it in minutes, and the business owner gets software that keeps working.


I'm Haseebullah, a software developer building websites, web apps, mobile apps and custom business software, with a background in digital marketing and graphic design. You can find my projects on my developer portfolio.

Top comments (0)