How shameeri312/next14-restapis works
Project type and purpose
• This is a full-stack React application built with Next.js (v13+), using the “app” directory (app router).
• It provides a user-authentication flow (under app/api/(auth)) and a dashboard for managing blogs and categories (under app/api/(dashboard)).
• The README confirms it was bootstrapped with Create-Next-App and runs a dev server on port 3000.
File structure
Top-level files and directories:
• .env, next.config.mjs, tsconfig.json – configuration for environment variables, Next.js, and TypeScript.
• package.json / pnpm-lock.yaml – dependencies, scripts, and lockfile.
• app/ – the Next.js “app router” folder containing both UI and server-route code:
– app/page.tsx & app/layout.tsx – root UI components (React Server and Client components).
– app/globals.css, tailwind.config.ts, postcss.config.mjs – global styling with Tailwind CSS.
– app/api/(auth)/users/route.ts – API route for user auth operations.
– app/api/(dashboard)/blogs… and app/api/(dashboard)/category… – CRUD API routes for blogs and categories.
– app/lib/db.ts – database client instantiation (e.g., Prisma or other).
– app/lib/modals/*.ts – TypeScript model definitions for User, Blog, and Category.
• middlewares/api/authMiddleware.ts – custom middleware to protect API routes.
• middleware.ts – Next.js root middleware (runs on every request if enabled).
README for additional insights
• Confirms Next.js features (Font optimization, hot reloading).
Elements
• Of API routes (app/api/(auth), app/api/(dashboard))
• Middleware layer (authMiddleware.ts, middleware.ts) positioned between API and DB
• Static Asset Server (public/)
– Browser → Next.js Server (page render)
– Browser → API routes (data fetch)
– API routes → Middleware → Database
– Next.js Server → Static Asset Server
Final advice
• Be thorough: break out each API sub-route as a component if the dashboard grows into microservices.
• If deploying on Vercel, note the serverless function boundary around each /api route.