Skip to content

shubh-Rocks/refashion

Folders and files

NameName
Last commit message
Last commit date

Latest commit

Β 

History

5 Commits
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 

Repository files navigation

πŸ‘— Refashion

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.


πŸ“Œ Table of Contents


🧾 Overview

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.


πŸš€ Live Demo

πŸ”— https://refashion.vercel.app (update with your actual URL)


✨ Features

  • πŸ” 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

πŸ› οΈ Tech Stack

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

πŸ“ Project Structure

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

🏁 Getting Started

Prerequisites

Make sure you have the following installed:


Installation

# 1. Clone the repository
git clone https://github.com/your-username/refashion.git

# 2. Navigate into the project
cd refashion

# 3. Install dependencies
npm install

Environment Variables

Create 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.local to version control. It is already included in .gitignore.


Running the App

# Development server
npm run dev

# Production build
npm run build
npm run start

# Lint
npm run lint

Open http://localhost:3000 in your browser.


πŸ” Authentication Flow

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.js on every request
  • Tokens expire automatically after the configured duration

🌐 Context API Architecture

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>
  );
}

πŸ—„οΈ Database Schema

User Model

{
  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 }
}

Product Model

{
  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 }
}

πŸ–ΌοΈ Image Upload with ImageKit.io

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

🚒 Deployment

Deploy to Vercel (Recommended)

# Install Vercel CLI
npm install -g vercel

# Deploy
vercel

Then add all environment variables from .env.local in your Vercel Dashboard β†’ Project β†’ Settings β†’ Environment Variables.

Manual Checklist Before Deploying

  • All .env variables added to hosting platform
  • MongoDB Atlas IP whitelist set to 0.0.0.0/0 (or Vercel IPs)
  • next.config.js includes ImageKit domain in images.domains
  • npm run build completes with no errors
  • Auth cookies use secure: true and sameSite: "strict" in production

πŸ“‘ API Routes

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

🀝 Contributing

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 Request

Please follow Conventional Commits for commit messages.


πŸ“„ License

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!

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Releases

Packages

Contributors

Languages