Skip to content

srujankothuri/shopflow

Repository files navigation

ShopFlow Dashboard

⚑ ShopFlow

E-Commerce Operations Hub with Smart Automation Rules Engine

πŸ”— Live Demo β€’ Features β€’ Tech Stack β€’ Getting Started β€’ Architecture

Next.js TypeScript Prisma PostgreSQL Tailwind Auth.js


🎯 What is ShopFlow?

ShopFlow is a full-stack e-commerce admin dashboard that goes beyond basic CRUD. It features a visual automation rules engine that lets store owners create IF/THEN rules to automate operations β€” like flagging high-value orders, auto-tagging VIP customers, applying discounts, and sending notifications.

Demo Credentials: admin@shopflow.com / admin123


✨ Features

πŸ“Š Analytics Dashboard

Real-time overview with revenue charts, order status distribution, key metrics, recent orders, and an activity feed β€” all powered by server-side Prisma aggregations.

Dashboard

Dashboard

πŸ“¦ Product Management

Full CRUD with image previews, category management, SKU tracking, stock alerts (highlighted in red when low), status management (Active/Draft/Archived), search, and CSV export.

Products

πŸ›’ Order Management

Complete order pipeline with status progression (Pending β†’ Processing β†’ Shipped β†’ Delivered), one-click status updates, order creation dialog with live total calculation, and CSV export.

Orders

πŸ‘₯ Customer Management

Customer profiles with expandable inline order history, total spend tracking, tag system (Regular/VIP/Wholesale/Flagged), and CSV export.

Customers

πŸš€ Automation Rules Engine (USP)

The standout feature β€” a visual rule builder with:

  • 5 Trigger Types: Order Placed, Status Changed, Low Stock, High Value Order, Repeat Customer
  • Nested AND/OR Conditions: Build complex condition trees with multiple groups
  • 5 Action Types: Send Email, Tag Customer, Flag Order, Update Status, Apply Discount
  • One-Click Templates: Pre-built rules for common scenarios
  • Rule Execution Engine: Evaluates rules against live data in real-time
  • Full Audit Log: Every execution logged with trigger data, actions performed, timestamps, and success/failure status
  • Test Mode: Manually test rules against the latest order data

Automation Rules

πŸ“Έ Rule Builder Wizard Rule Builder

πŸŒ™ Dark Mode

Full dark/light theme toggle with smooth transitions across all components.

Dark Mode

πŸ“± Responsive Design

Mobile-friendly with a collapsible sidebar and hamburger menu.

πŸ” Authentication

Email/password registration + Google OAuth with session management via Auth.js v5 (JWT strategy).


πŸ— Architecture

β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
β”‚                     FRONTEND                                  β”‚
β”‚  Next.js 16 (App Router) β€’ TypeScript β€’ Tailwind β€’ shadcn/ui β”‚
β”‚                                                                β”‚
β”‚  β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β” β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β” β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β” β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”         β”‚
β”‚  β”‚Dashboard β”‚ β”‚Products  β”‚ β”‚ Orders   β”‚ β”‚Customers β”‚         β”‚
β”‚  β”‚Analytics β”‚ β”‚  CRUD    β”‚ β”‚Pipeline  β”‚ β”‚ History  β”‚         β”‚
β”‚  β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜ β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜ β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜ β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜         β”‚
β”‚  β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”          β”‚
β”‚  β”‚        Automation Rules Visual Builder           β”‚          β”‚
β”‚  β”‚   Triggers β†’ Conditions (AND/OR) β†’ Actions       β”‚          β”‚
β”‚  β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜          β”‚
β”œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€
β”‚                      API LAYER                                β”‚
β”‚  Next.js API Routes (RESTful)                                 β”‚
β”‚  /products β€’ /orders β€’ /customers β€’ /categories               β”‚
β”‚  /rules β€’ /rules/[id]/execute β€’ /rules/[id]/logs β€’ /export   β”‚
β”œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€
β”‚                  RULE EXECUTION ENGINE                         β”‚
β”‚  β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”    β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”    β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”   β”‚
β”‚  β”‚   Condition    │───▢│    Action     │───▢│  Audit Log   β”‚   β”‚
β”‚  β”‚   Evaluator    β”‚    β”‚   Executor    β”‚    β”‚  (RuleLog)   β”‚   β”‚
β”‚  β”‚ (AND/OR tree)  β”‚    β”‚ (DB + Email)  β”‚    β”‚              β”‚   β”‚
β”‚  β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜    β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜    β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜   β”‚
β”œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€
β”‚                     DATABASE                                  β”‚
β”‚  PostgreSQL (Neon) + Prisma 7 ORM                             β”‚
β”‚  8 Tables: User, Product, Category, Order, OrderItem,        β”‚
β”‚            Customer, Rule, RuleLog                             β”‚
β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜

πŸ›  Tech Stack

Category Technology
Framework Next.js 16 (App Router, Server Components)
Language TypeScript (end-to-end type safety)
Database PostgreSQL via Neon (serverless)
ORM Prisma 7 with Neon adapter
Authentication Auth.js v5 (Credentials + Google OAuth)
UI Components shadcn/ui + Tailwind CSS v4
Charts Recharts (Bar, Pie, Responsive)
Rule Engine Custom-built JSON condition tree evaluator
Email Resend (with simulation fallback)
Deployment Vercel (frontend) + Neon (database)
Containerization Docker + Docker Compose

πŸš€ Getting Started

Prerequisites

  • Node.js 18+
  • PostgreSQL database (Neon free tier recommended)

Installation

# Clone the repository
git clone https://github.com/srujankothuri/shopflow.git
cd shopflow

# Install dependencies
npm install

# Set up environment variables
cp .env.example .env
# Edit .env with your credentials

# Generate Prisma client and push schema
npx prisma generate
npx prisma db push

# Seed with demo data (22 products, 15 customers, 96 orders, 4 rules)
npx prisma db seed

# Start development server
npm run dev

Environment Variables

DATABASE_URL="postgresql://..."        # Neon connection string
AUTH_SECRET="..."                       # Generate with: npx auth secret
AUTH_URL="http://localhost:3000"        # Your app URL
AUTH_GOOGLE_ID=""                       # Google OAuth (optional)
AUTH_GOOGLE_SECRET=""                   # Google OAuth (optional)
RESEND_API_KEY=""                       # For email actions (optional)

Docker

docker-compose up

πŸ“ Project Structure

src/
β”œβ”€β”€ app/
β”‚   β”œβ”€β”€ (auth)/                  # Auth pages (no sidebar layout)
β”‚   β”‚   β”œβ”€β”€ login/
β”‚   β”‚   └── register/
β”‚   β”œβ”€β”€ (dashboard)/             # Dashboard layout (with sidebar)
β”‚   β”‚   └── dashboard/
β”‚   β”‚       β”œβ”€β”€ products/        # Products CRUD page
β”‚   β”‚       β”œβ”€β”€ orders/          # Orders management page
β”‚   β”‚       β”œβ”€β”€ customers/       # Customers page with history
β”‚   β”‚       β”œβ”€β”€ rules/           # Automation rules page
β”‚   β”‚       └── settings/        # Settings page
β”‚   └── api/                     # REST API endpoints
β”‚       β”œβ”€β”€ products/[id]/
β”‚       β”œβ”€β”€ orders/[id]/
β”‚       β”œβ”€β”€ customers/[id]/
β”‚       β”œβ”€β”€ categories/
β”‚       β”œβ”€β”€ rules/[id]/
β”‚       β”‚   β”œβ”€β”€ execute/         # Manual rule testing
β”‚       β”‚   └── logs/            # Rule execution logs
β”‚       β”œβ”€β”€ export/              # CSV export endpoint
β”‚       └── register/
β”œβ”€β”€ components/
β”‚   β”œβ”€β”€ dashboard/               # Stats cards, charts, activity feed
β”‚   β”œβ”€β”€ products/                # Product dialog
β”‚   β”œβ”€β”€ orders/                  # Order creation dialog
β”‚   β”œβ”€β”€ customers/               # Customer dialog
β”‚   β”œβ”€β”€ rules/                   # Rule builder, logs viewer, templates
β”‚   β”œβ”€β”€ layout/                  # Sidebar, header
β”‚   β”œβ”€β”€ providers/               # Auth + theme providers
β”‚   └── ui/                      # shadcn/ui primitives
└── lib/
    β”œβ”€β”€ auth.ts                  # NextAuth configuration
    β”œβ”€β”€ db.ts                    # Prisma client singleton
    β”œβ”€β”€ dashboard.ts             # Dashboard aggregation queries
    β”œβ”€β”€ rule-engine.ts           # Rule evaluation + execution engine
    β”œβ”€β”€ email.ts                 # Resend email integration
    └── utils.ts                 # Utility functions

πŸ”§ How the Rules Engine Works

Event Occurs (e.g., Order Placed)
         β”‚
         β–Ό
β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
β”‚  Fetch Active Rules  β”‚  ← Filter by trigger type, sort by priority
β”‚  for this Trigger    β”‚
β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”¬β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜
          β”‚
          β–Ό
β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
β”‚  Evaluate Conditions β”‚  ← AND/OR tree evaluation against event data
β”‚  (per rule)          β”‚
β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”¬β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜
          β”‚
    β”Œβ”€β”€β”€β”€β”€β”΄β”€β”€β”€β”€β”€β”
    β”‚           β”‚
 PASS        FAIL
    β”‚           β”‚
    β–Ό           β–Ό
β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”  β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”
β”‚Execute β”‚  β”‚  Log   β”‚
β”‚Actions β”‚  β”‚SKIPPED β”‚
β””β”€β”€β”€β”¬β”€β”€β”€β”€β”˜  β””β”€β”€β”€β”€β”€β”€β”€β”€β”˜
    β”‚
    β–Ό
β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
β”‚  Log Execution       β”‚  ← Status, actions run, trigger data snapshot
β”‚  (Audit Trail)       β”‚
β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜
  1. User creates a rule via the 3-step visual wizard (trigger β†’ conditions β†’ actions)
  2. Rule is stored as JSON in PostgreSQL (conditions as nested AND/OR tree, actions as array)
  3. When an event occurs (e.g., order created via API), the engine fetches all active rules for that trigger
  4. Conditions are evaluated using a recursive tree evaluator supporting AND/OR logic across groups
  5. If conditions pass, actions execute sequentially (DB updates, customer tagging, email notifications)
  6. Every execution is logged with full context β€” trigger data snapshot, actions performed, timestamps, success/failure

πŸ“ Key Design Decisions

Decision Rationale
JSON conditions over relational tables Flexible nested AND/OR groups without complex self-referencing joins
JWT sessions over DB sessions Faster auth checks, no extra database table needed
Server Components for dashboard Stats computed server-side with Prisma aggregations β€” zero client-side data fetching on initial load
Event-driven rule execution Rules fire on API events (order creation); easily extensible to webhooks and cron triggers
Audit trail for every execution Production-grade observability β€” debug failed rules, track automation history
CSV export via API route Stream large datasets without loading everything into browser memory
Simulation mode for emails App works without Resend API key; emails log to console in dev

🀝 Contributing

# Fork the repo
# Create your feature branch
git checkout -b feature/amazing-feature

# Commit your changes
git commit -m "feat: add amazing feature"

# Push to the branch
git push origin feature/amazing-feature

# Open a Pull Request

πŸ‘€ Author

Venkata Srujan Kothuri


πŸ“„ License

This project is open source under the MIT License.


Built with ❀️ using Next.js, Prisma, and TypeScript

About

Full-stack e-commerce operations hub with a visual automation rules engine. Built with Next.js 16, Prisma 7, PostgreSQL, TypeScript, and Tailwind CSS.

Topics

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors