A full-stack application built using Next.js App Router, implementing JWT Authentication and Product CRUD operations using modern technologies like Prisma, MongoDB, Redux Toolkit, and TanStack Query.
- β‘ Next.js (App Router + API Routes)
- π¦ TypeScript
- ποΈ MongoDB Atlas
- π Prisma ORM
- π§ Redux Toolkit (Auth State)
- π¦ TanStack Query (Server State)
- π¨ Tailwind CSS + shadcn/ui
βββ π prisma/
β βββ π schema.prisma
βββ π public/
β βββ πΌοΈ file.svg
β βββ πΌοΈ globe.svg
β βββ πΌοΈ next.svg
β βββ πΌοΈ vercel.svg
β βββ πΌοΈ window.svg
βββ π src/
β βββ π app/
β β βββ π (auth)/
β β β βββ π login/
β β β β βββ π page.tsx
β β β βββ π register/
β β β βββ π page.tsx
β β βββ π admin/
β β β βββ π layout.tsx
β β β βββ π page.tsx
β β βββ π api/
β β β βββ π auth/
β β β β βββ π [...nextauth]/
β β β β βββ π route.ts
β β β βββ π login/
β β β β βββ π route.ts
β β β βββ π products/
β β β β βββ π [id]/
β β β β β βββ π route.ts
β β β β βββ π route.ts
β β β βββ π register/
β β β βββ π route.ts
β β βββ π favicon.ico
β β βββ π¨ globals.css
β β βββ π layout.tsx
β β βββ π page.tsx
β βββ π components/
β β βββ π ui/ #shadcn UI Components
β β β βββ π button.tsx
β β β βββ π card.tsx
β β β βββ π dialog.tsx
β β β βββ π input.tsx
β β β βββ π label.tsx
β β β βββ π magic-card.tsx
β β β βββ π pagination.tsx
β β β βββ π switch.tsx
β β β βββ π table.tsx
β β βββ π DynamicInput.tsx
β β βββ π ProductDialog.tsx
β β βββ π Table.tsx
β βββ π generated/
β βββ π hooks/
β β βββ π useProducts.ts
β βββ π layout/
β β βββ π Navbar.tsx
β βββ π lib/
β β βββ π auth.ts
β β βββ π axios.ts
β β βββ π jwt.ts
β β βββ π prisma.ts
β β βββ π utils.ts
β βββ π reducer/
β β βββ π product.rducer.ts
β βββ π services/
β β βββ π helpers/
β β β βββ π provider/
β β β β βββ π QueryProvider.tsx
β β β β βββ π ReduxProvider.tsx
β β β βββ π global.helper.ts
β β β βββ π redux.ts
β β βββ π jsons/
β β β βββ π fields/
β β β β βββ π auth.input.ts
β β β β βββ π product.input.ts
β β β βββ π lottie/
β β βββ π validatons/
β β βββ π loginSchema.ts
β β βββ π productSchema.ts
β β βββ π registerSchema.ts
β βββ π store/
β β βββ π slices/
β β β βββ π auth.slice.ts
β β βββ π store.ts
β βββ π type/
β β βββ π interface/
β β βββ π type/
β β βββ π auth.type.ts
β β βββ π components.type.ts
β β βββ π global.type.ts
β β βββ π product.type.ts
β β βββ π redux.type.ts
β βββ π proxy.ts
βββ βοΈ .gitignore
βββ π README.md
βββ βοΈ components.json
βββ π eslint.config.mjs
βββ π next.config.ts
βββ βοΈ package-lock.json
βββ βοΈ package.json
βββ π postcss.config.mjs
βββ βοΈ tsconfig.json
- User Registration
- User Login
- JWT Token Generation
- Secure Route Handling
- Create Product
- Get All Products
- Update Product
- Delete Product
- name
- email (unique)
- phone
- password
- name
- desc
- price
- NoSQL database β flexible schema
- Easy to scale
- Fast for CRUD operations
- Works well with JSON-based apps
- Go to MongoDB Atlas
- Create a free cluster
- Create database user (username & password)
- Allow IP access (
0.0.0.0/0for development) - Copy connection string
DATABASE_URL="mongodb+srv://user:pass@cluster/db"
- Type-safe queries
- Auto-generated database client
- Cleaner and readable code
- Reduces runtime errors
npm install prisma @prisma/client
npx prisma init
DATABASE_URL="your_mongodb_connection_string"
generator client {
provider = "prisma-client-js"
}
datasource db {
provider = "mongodb"
url = env("DATABASE_URL")
}
model User {
id String @id @default(auto()) @map("_id") @db.ObjectId
name String
email String @unique
phone String
password String
products Product[]
}
model Product {
id String @id @default(auto()) @map("_id") @db.ObjectId
name String
price Float
description String
isPublish Boolean @default(false)
createdAt DateTime @default(now())
userId String @db.ObjectId
user User @relation(fields: [userId], references: [id])
}
npx prisma generate
π Prisma works as a bridge between your API and MongoDB, making database operations simple and type-safe.
- Built-in backend inside Next.js
- No need for separate server
- Easy integration with frontend
- Scalable structure
/api/register
/api/login
/api/products
/api/products/[id]
- Create new user
- Store hashed password
- Return success message
- Validate user credentials
- Generate JWT token
- Return token + status Example Response:
{
"statusCode": 200,
"message": "Login successful",
"token": "JWT_TOKEN",
"user: {} //user details
}
- Fetch all products
- Create new product
- Update product
- Delete product
- Stores user data & JWT token
- Handles login/logout globally
- Centralized state management
- Fetch & cache API data
- Auto refetching
- Keeps UI in sync with server
- Tailwind CSS β Utility-first styling
- shadcn/ui β Reusable UI components
- Protects private routes
- Validates JWT token
- Redirects unauthorized users
Made with β€οΈ by Tanmay Shil GitHub: @TanmayShil