API App

One backend-only Next.js app with admin and public routes.

This project now runs as a single API service. Next.js route handlers act as routers, controllers coordinate requests, services enforce business rules, repositories talk to MongoDB, and the shared workspace packages own the database connection and models.

DeploymentNext.js + Node.js route handlers
ArchitectureMVC with repository and service layers
Routing`/api/admin/*` and `/api/public/*`
DatabaseMongoDB via shared Mongoose package

MVC Flow

  • Route handler receives the HTTP request.
  • Controller reads params and JSON input.
  • Service validates and enforces rules.
  • Repository executes Mongoose queries.
  • Shared package owns the Mongo models and connection cache.
  • Responses come back as JSON-safe plain objects.

Route Namespaces

  • `/api/admin/*` is for internal admin operations.
  • Users, categories, and product CRUD live there.
  • Those routes can later be protected by auth or role checks.
  • `/api/public/*` is for frontend or mobile clients.
  • Only published product data is exposed there.
  • This keeps your public contract separate from admin internals.

Core API

GET/api/admin/health

Checks admin API health and MongoDB connectivity.

GET/api/admin/users

Lists admin users with populated managed category relationships.

POST/api/admin/users

Creates a user and links it to categories through ObjectId references.

PATCH/api/admin/users/:id

Updates role, email, name, and managed category relationships.

GET/api/admin/categories

Lists categories with optional parent category population.

POST/api/admin/categories

Creates a category and can attach it to another category as a parent.

GET/api/admin/products

Lists products with populated category and creator references.

POST/api/admin/products

Creates a product and links it to both a category and the admin user who created it.

GET/api/public/health

Checks public API health and confirms the backend is reachable.

GET/api/public/products

Returns published products and supports filtering by category slug.

GET/api/public/products/:slug

Returns one published product for client applications.