A full-stack, production-ready fashion web application built with Next.js, featuring secure authentication, global state management via Context API, MongoDB cloud database, and seamless image handling with ImageKit.io.
- Overview
- Live Demo
- Features
- Tech Stack
- Project Structure
- Getting Started
- Authentication Flow
- Context API Architecture
- Database Schema
- Image Upload with ImageKit.io
- Deployment
- API Routes
- Contributing
- License
Refashion is a modern fashion platform where users can browse, upload, and manage outfit/product listings. The app is built for real-world production use β with a secure authentication system, cloud-stored images, and a persistent MongoDB backend.
π https://refashion.vercel.app (update with your actual URL)
- π Secure Authentication β JWT-based login/signup with hashed passwords (bcrypt), protected routes, and persistent sessions
- π Context API β Global state management for user sessions, cart, and UI state without Redux overhead
- ποΈ MongoDB Atlas β Cloud-hosted NoSQL database for users, products, and orders
- πΌοΈ ImageKit.io β Real-time image optimization, transformation, and CDN delivery for all uploaded images
- π± Responsive Design β Mobile-first UI that works seamlessly on all screen sizes
- β‘ Next.js App Router β File-based routing with server-side rendering (SSR) and static generation (SSG)
- π‘οΈ Protected API Routes β Middleware-secured endpoints with token validation
- π Real-time Updates β Instant UI refresh on state changes via Context
- π Production Ready β Environment-based config, error boundaries, and optimized builds
| Layer | Technology |
|---|---|
| Framework | Next.js 14+ (App Router) |
| Language | JavaScript / TypeScript |
| Authentication | JWT + bcryptjs |
| Database | MongoDB Atlas via Mongoose |
| Image CDN | ImageKit.io |
| State Management | React Context API |
| Styling | Tailwind CSS |
| Deployment | Vercel |
| Package Manager | npm / yarn |
refashion/
βββ app/
β βββ (auth)/
β β βββ login/
β β β βββ page.jsx
β β βββ signup/
β β βββ page.jsx
β βββ (dashboard)/
β β βββ profile/
β β βββ listings/
β βββ api/
β β βββ auth/
β β β βββ login/route.js
β β β βββ signup/route.js
β β β βββ logout/route.js
β β βββ products/
β β β βββ route.js
β β β βββ [id]/route.js
β β βββ imagekit/
β β βββ auth/route.js
β βββ layout.jsx
β βββ page.jsx
β
βββ components/
β βββ auth/
β β βββ LoginForm.jsx
β β βββ SignupForm.jsx
β βββ ui/
β β βββ Navbar.jsx
β β βββ Footer.jsx
β β βββ ImageUploader.jsx
β βββ products/
β βββ ProductCard.jsx
β βββ ProductGrid.jsx
β
βββ context/
β βββ AuthContext.jsx β User session & auth state
β βββ CartContext.jsx β Cart items & totals
β βββ AppContext.jsx β Global UI state
β
βββ lib/
β βββ mongodb.js β MongoDB connection helper
β βββ auth.js β JWT helpers (sign, verify)
β βββ imagekit.js β ImageKit SDK setup
β
βββ models/
β βββ User.js
β βββ Product.js
β βββ Order.js
β
βββ middleware.js β Route protection
βββ .env.local β Environment variables (never commit)
βββ next.config.js
βββ README.md
Make sure you have the following installed:
- Node.js v18 or higher
- npm v9+ or yarn
- A MongoDB Atlas account β Create one free
- An ImageKit.io account β Create one free
# 1. Clone the repository
git clone https://github.com/your-username/refashion.git
# 2. Navigate into the project
cd refashion
# 3. Install dependencies
npm installCreate a .env.local file in the root of your project and add the following:
# βββ App ββββββββββββββββββββββββββββββββββββββββββ
NEXT_PUBLIC_APP_URL=http://localhost:3000
# βββ MongoDB Atlas ββββββββββββββββββββββββββββββββ
MONGODB_URI=mongodb+srv://<username>:<password>@cluster0.mongodb.net/refashion?retryWrites=true&w=majority
# βββ JWT Authentication βββββββββββββββββββββββββββ
JWT_SECRET=your_super_secret_jwt_key_here
JWT_EXPIRES_IN=7d
# βββ ImageKit.io ββββββββββββββββββββββββββββββββββ
NEXT_PUBLIC_IMAGEKIT_PUBLIC_KEY=your_imagekit_public_key
IMAGEKIT_PRIVATE_KEY=your_imagekit_private_key
NEXT_PUBLIC_IMAGEKIT_URL_ENDPOINT=https://ik.imagekit.io/your_imagekit_id
β οΈ Never commit.env.localto version control. It is already included in.gitignore.
# Development server
npm run dev
# Production build
npm run build
npm run start
# Lint
npm run lintOpen http://localhost:3000 in your browser.
Refashion uses a JWT-based stateless authentication system:
User submits credentials
β
βΌ
POST /api/auth/login
β
βΌ
Validate with MongoDB (bcrypt compare)
β
βΌ
Sign JWT (server-side)
β
βΌ
Set HttpOnly Cookie βββΊ Client browser
β
βΌ
AuthContext reads cookie βββΊ Global user state
β
βΌ
middleware.js checks token βββΊ Protects private routes
Security measures applied:
- Passwords hashed with bcrypt (salt rounds: 12)
- JWT stored in HttpOnly cookies (not localStorage) to prevent XSS
- CSRF protection via SameSite cookie policy
- Protected API routes validated via
middleware.json every request - Tokens expire automatically after the configured duration
Three context providers wrap the app to manage global state:
// app/layout.jsx
<AppProvider>
<AuthProvider>
<CartProvider>
{children}
</CartProvider>
</AuthProvider>
</AppProvider>| Context | Manages |
|---|---|
AuthContext |
Logged-in user object, login/logout functions, loading state |
CartContext |
Cart items, add/remove/clear, total price calculation |
AppContext |
Theme, modal state, notifications, global UI flags |
Usage example:
import { useAuth } from "@/context/AuthContext";
export default function Navbar() {
const { user, logout } = useAuth();
return (
<nav>
{user ? (
<button onClick={logout}>Logout</button>
) : (
<a href="/login">Login</a>
)}
</nav>
);
}{
name: { type: String, required: true },
email: { type: String, required: true, unique: true },
password: { type: String, required: true }, // bcrypt hashed
avatar: { type: String }, // ImageKit URL
role: { type: String, enum: ["user", "admin"], default: "user" },
createdAt: { type: Date, default: Date.now }
}{
title: { type: String, required: true },
description: { type: String },
price: { type: Number, required: true },
images: [{ url: String, fileId: String }], // ImageKit data
category: { type: String },
seller: { type: ObjectId, ref: "User" },
createdAt: { type: Date, default: Date.now }
}Images are securely uploaded via a client β server authentication β ImageKit flow:
Client selects image
β
βΌ
GET /api/imagekit/auth β Server generates upload signature
β
βΌ
ImageKit SDK uploads directly from client using signature
β
βΌ
ImageKit returns { url, fileId }
β
βΌ
URL saved to MongoDB Product document
Key ImageKit features used:
- Automatic image optimization β WebP conversion, compression
- Transformations on-the-fly β resize, crop, quality tuning via URL params
- CDN delivery β fast global image loading
- Secure uploads β server-generated signatures prevent unauthorized uploads
Example transformation URL:
https://ik.imagekit.io/your_id/product.jpg?tr=w-400,h-400,fo-auto
# Install Vercel CLI
npm install -g vercel
# Deploy
vercelThen add all environment variables from .env.local in your Vercel Dashboard β Project β Settings β Environment Variables.
- All
.envvariables added to hosting platform - MongoDB Atlas IP whitelist set to
0.0.0.0/0(or Vercel IPs) -
next.config.jsincludes ImageKit domain inimages.domains -
npm run buildcompletes with no errors - Auth cookies use
secure: trueandsameSite: "strict"in production
| Method | Endpoint | Auth Required | Description |
|---|---|---|---|
POST |
/api/auth/signup |
β | Register a new user |
POST |
/api/auth/login |
β | Login and receive JWT cookie |
POST |
/api/auth/logout |
β | Clear auth cookie |
GET |
/api/auth/me |
β | Get current user details |
GET |
/api/products |
β | Fetch all products |
POST |
/api/products |
β | Create a new product listing |
GET |
/api/products/[id] |
β | Fetch a single product |
PUT |
/api/products/[id] |
β | Update a product |
DELETE |
/api/products/[id] |
β | Delete a product |
GET |
/api/imagekit/auth |
β | Get ImageKit upload signature |
Contributions are welcome! Please follow these steps:
# 1. Fork the repo
# 2. Create a feature branch
git checkout -b feature/your-feature-name
# 3. Commit your changes
git commit -m "feat: add your feature description"
# 4. Push to your fork
git push origin feature/your-feature-name
# 5. Open a Pull RequestPlease follow Conventional Commits for commit messages.
This project is licensed under the MIT License β see the LICENSE file for details.
Built with β€οΈ using Next.js, MongoDB, and ImageKit.io
β Star this repo if you found it helpful!