Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
98 changes: 89 additions & 9 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,18 +15,51 @@ Welcome to the open-source Next.js E-Commerce Storefront with Admin Panel projec

- [x] [**Next.js 14**](https://nextjs.org) App Router and React Server Components.
- [x] Custom dynamic `Sitemap.xml` generation.
- [x] Admin dashboard with products, orders, and payments.
- [x] Admin dashboard with products, orders, payments, and comprehensive reports.
- [x] File uploads using `next-cloudinary`.
- [x] Authentication using `middleware.ts` and `httpOnly` cookies.
- [x] Storefront with blog, products, and categories.
- [x] Storefront with blog, products, categories, and advanced filtering.
- [x] Database-Stored blogs powered by **MDX** templates.
- [x] Email verification and invoices using [react-email-tailwind-templates](https://github.com/sesto-dev/react-email-tailwind-templates).
- [x] [**TailwindCSS**](https://tailwindcss.com/) for utility-first CSS.
- [x] UI built with [**Radix**](https://www.radix-ui.com/) and stunning UI components, all thanks to [**shadcn/ui**](https://ui.shadcn.com/).
- [x] Type-Validation with **Zod**.
- [x] [**Next Metadata API**](https://nextjs.org/docs/api-reference/metadata) for SEO handling.
- [x] **Advanced Product Filtering** with search, price range, categories, brands, and sorting.
- [x] **Cross-Sell Product Suggestions** on product pages and cart.
- [x] **Admin Reports Dashboard** with order analytics and top-selling products.
- [x] **Responsive Design** optimized for mobile, tablet, and desktop.
- [ ] Comprehensive implementations for i18n.

## 📁 Project Structure

This project follows a monorepo structure with two separate applications:

```
next-prisma-tailwind-ecommerce/
├── apps/
│ ├── admin/ # Admin dashboard application
│ │ ├── src/
│ │ │ ├── app/ # Next.js App Router pages
│ │ │ ├── components/ # Reusable UI components
│ │ │ ├── lib/ # Utility functions and Prisma client
│ │ │ └── types/ # TypeScript type definitions
│ │ └── prisma/ # Database schema and migrations
│ └── storefront/ # Customer-facing storefront
│ ├── src/
│ │ ├── app/ # Next.js App Router pages
│ │ ├── components/ # UI components and layouts
│ │ ├── hooks/ # Custom React hooks
│ │ ├── lib/ # Utility functions
│ │ └── state/ # Global state management
│ └── prisma/ # Database schema
├── packages/ # Shared packages
│ ├── mail/ # Email templates and utilities
│ ├── oauth/ # OAuth providers
│ └── ... # Other shared utilities
└── README.md
```

## 2️⃣ Why are there 2 apps in the app folder?

This project is made up of 2 separate apps ( admin and storefront ) which should be deployed separately. If you are deploying with Vercel you should create 2 different apps.
Expand All @@ -35,6 +68,30 @@ This project is made up of 2 separate apps ( admin and storefront ) which should

Under the general tab there is a Root Directory option, for the admin app you should put in "apps/admin" and for the storefront app you should put in "apps/storefront".

## 🆕 Recent Updates

### Advanced Product Filtering
- **Text Search**: Search across product titles, descriptions, and keywords
- **Price Range**: Filter products by minimum and maximum price
- **Category & Brand Filters**: Filter by specific categories and brands
- **Availability Toggle**: Show only available products
- **Sorting Options**: Sort by price (high/low), title (A-Z/Z-A), and featured products
- **URL Synchronization**: All filters are reflected in the URL for bookmarking and sharing

### Cross-Sell Product Suggestions
- **Product Page Integration**: "You might also like" section on product detail pages
- **Cart Page Integration**: "Frequently bought together" suggestions on cart page
- **Smart Aggregation**: Combines cross-sell products from all cart items
- **Deduplication**: Removes duplicate suggestions and items already in cart
- **Admin Management**: Full CRUD operations for managing cross-sell relationships

### Admin Reports Dashboard
- **Order Analytics**: View orders grouped by date with revenue and status breakdown
- **Top-Selling Products**: Track most popular products with sales metrics
- **Date Range Filtering**: Filter reports by custom date ranges
- **Category & Brand Filters**: Analyze performance by specific categories or brands
- **Summary Cards**: Quick overview of total revenue, orders, and average order value

## 🔐 Authentication

The authentication is handled using JWT tokens stored in cookies and verified inside the `middleware.ts` file. The middleware function takes in the HTTP request, reads the `token` cookie and if the JWT is successfully verified, it sets the `X-USER-ID` header with the userId as the value, otherwise the request is sent back with 401 status.
Expand Down Expand Up @@ -69,12 +126,24 @@ Get all dependencies sorted.
bun install
```

Generate prisma client schema.

```sh
bun run db:generate
```

Bring your database to life with pushing the database schema.

```bash
bun run db:push
```

Seed the database with dummy data.

```bash
bun run db:seed
```

```sh
bun run dev
```
Expand All @@ -83,6 +152,15 @@ bun run dev

Prisma ORM can use any PostgreSQL database. [Supabase is the easiest to work with.](https://www.prisma.io/docs/guides/database/supabase) Simply set `DATABASE_URL` in your `.env` file to work.

### Database Schema Features

- **Products**: Full product management with images, pricing, inventory, and metadata
- **Cross-Sell Relationships**: Many-to-many self-relations for product recommendations
- **Categories & Brands**: Hierarchical organization of products
- **Orders & Payments**: Complete order management with status tracking
- **User Management**: Authentication and profile management
- **Cart System**: Persistent cart with local storage and authenticated sync

### `bun run db`

This project exposes a package.json script for accessing prisma via `bun run db:<command>`. You should always try to use this script when interacting with prisma locally.
Expand All @@ -91,12 +169,14 @@ This project exposes a package.json script for accessing prisma via `bun run db:

Make changes to your database by modifying `prisma/schema.prisma`.

## 🛸 How to Deploy the Project

Follow the deployment guides for [Vercel](https://create.t3.gg/en/deployment/vercel), [Netlify](https://create.t3.gg/en/deployment/netlify) and [Docker](https://create.t3.gg/en/deployment/docker) for more information.

## 📄 License
## 🔌 API Endpoints

This project is MIT-licensed and is free to use and modify for your own projects. Check the [LICENSE](./LICENSE) file for details.
### Storefront APIs
- **Products**: `GET /api/products` - List products with filtering and pagination
- **Product Details**: `GET /api/products/[id]` - Get single product details
- **Cross-Sell**: `GET /api/products/[id]/cross-sell` - Get cross-sell products
- **Cart**: `GET/POST /api/cart` - Manage shopping cart

Created by [Amirhossein Mohammadi](https://github.com/sesto-dev).
### Admin APIs
- **Reports**: `GET /api/reports/overview` - Dashboard analytics
- **Cross-Sell Management**: Full CRUD for cross-sell relationships
Binary file modified apps/admin/bun.lockb
100644 → 100755
Binary file not shown.
4 changes: 4 additions & 0 deletions apps/admin/next.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,4 +9,8 @@ module.exports = {
},
],
},
env: {
JWT_SECRET_KEY: process.env.JWT_SECRET_KEY,
DATABASE_URL: process.env.DATABASE_URL,
},
}
4 changes: 4 additions & 0 deletions apps/admin/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@
"next-themes": "^0.3.0",
"nodemailer": "^6.9.15",
"react": "18.3.1",
"react-day-picker": "^9.10.0",
"react-dom": "18.3.1",
"react-hook-form": "^7.53.0",
"react-hot-toast": "^2.4.1",
Expand All @@ -74,5 +75,8 @@
"tailwindcss": "3.4.13",
"tailwindcss-animate": "^1.0.7",
"typescript": "5.6.3"
},
"prisma": {
"seed": "bun run prisma/seed.ts"
}
}
Loading