Skip to content

newelle-dev/vapetrack-ph

Folders and files

NameName
Last commit message
Last commit date

Latest commit

Β 

History

91 Commits
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 

Repository files navigation

VapeTrack PH - Sales & Inventory Management SaaS

Next.js Supabase TypeScript Tailwind CSS License

A mobile-first Progressive Web App (PWA) built specifically for Philippine vape shops. Eliminates manual logbooks and spreadsheets with real-time inventory tracking, sales analytics, and staff accountabilityβ€”all accessible from any device with zero hardware dependencies.


🎯 What It Does

VapeTrack PH is a multi-tenant SaaS platform that enables vape shop owners to:

  • βœ… Track inventory in real-time across multiple branches and variants (flavors, nicotine levels, colors)
  • βœ… Process sales in under 30 seconds with an optimized Point of Sale interface
  • βœ… Monitor profits accurately with automated capital vs. revenue calculations
  • βœ… Manage staff access via role-based permissions and PIN authentication
  • βœ… Generate business insights through comprehensive dashboards and reports
  • βœ… Scale operations from single-location to multi-branch seamlessly

Target Market: Small to medium vape shops in the Philippines running on 4G/5G networks.


πŸš€ Day 1 Setup Guide

Prerequisites

Before starting, ensure you have:

Required Software

Tool Version Download Link Purpose
Node.js 20.x LTS or higher nodejs.org Runtime environment
npm 10.x (bundled with Node) β€” Package manager
Git Latest git-scm.com Version control
VS Code Latest code.visualstudio.com Code editor

VS Code Extensions (Recommended)

Install these extensions for optimal developer experience:

# Install via VS Code Quick Open (Ctrl+P / Cmd+P)
ext install bradlc.vscode-tailwindcss          # Tailwind IntelliSense
ext install dbaeumer.vscode-eslint              # ESLint
ext install esbenp.prettier-vscode              # Prettier (code formatting)
ext install usernamehw.errorlens                # Inline error highlighting
ext install mikestead.dotenv                    # .env syntax highlighting
ext install supabase.vscode-supabase            # Supabase integration

Or manually install from VS Code Marketplace:

  • Tailwind CSS IntelliSense (bradlc.vscode-tailwindcss)
  • ESLint (dbaeumer.vscode-eslint)
  • Supabase (supabase.vscode-supabase) - Optional but helpful

Accounts to Create

  1. Supabase Account (Free Tier)

    • Visit: supabase.com
    • Create account and new project
    • Note: Free tier includes 500MB database, 1GB file storage, 2GB bandwidth
  2. Vercel Account (Free Tier) - Deployment only


πŸ“¦ Installation Commands

Step 1: Clone the Repository

# Clone the project
git clone https://github.com/yourusername/vapetrack-ph.git
cd vapetrack-ph

Step 2: Install Dependencies

# Install all packages (~200MB download, 1-2 minutes)
npm install

This installs:

  • Next.js 16 (App Router)
  • Tailwind CSS 4 (styling framework)
  • Supabase JS Client (database SDK)
  • TanStack Query v5 (server state management)
  • Lucide React (icon library)
  • shadcn/ui components (via manual copy)
  • TypeScript 5 (type safety)

Step 3: Configure Environment Variables

# Copy the example environment file
cp .env.example .env.local

Edit .env.local with your Supabase credentials:

# .env.local
NEXT_PUBLIC_SUPABASE_URL=https://your-project.supabase.co
NEXT_PUBLIC_SUPABASE_ANON_KEY=your-anon-key-here
NEXT_PUBLIC_SUPABASE_PUBLISHABLE_DEFAULT_KEY=your-publishable-default-key-here
SUPABASE_SERVICE_ROLE_KEY=your-service-role-key  # Server-side only

Where to find these:

  1. Go to supabase.com/dashboard
  2. Select your project
  3. Click Settings β†’ API
  4. Copy Project URL and anon public key

Step 4: Initialize Supabase Schema

# Option A: Using Supabase CLI (Recommended)
# Install Supabase CLI
npm install supabase --save-dev

# Login to Supabase
npx supabase login

# Link to your project
npx supabase link --project-ref your-project-ref

# Apply database migrations
npx supabase db push

# Generate TypeScript types
npx supabase gen types typescript --project-id your-project-ref > types/database.ts
# Option B: Manual SQL Execution
# 1. Open Supabase Dashboard β†’ SQL Editor
# 2. Copy contents of `./migrations/001_initial_schema.sql`
# 3. Execute the SQL script
# 4. Manually copy `types/database.example.ts` to `types/database.ts`

Step 5: Run Development Server

npm run dev

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

Expected behavior:

  • βœ… Sign-up page loads
  • βœ… Tailwind styles applied (dark theme)
  • βœ… No console errors related to Supabase connection

πŸ› οΈ Technology Stack

Frontend

Technology Version Purpose
Next.js 16.1.6 App Router, RSC, Server Actions
React 19.2 UI library
TypeScript 5.x Type safety
Tailwind CSS 4.0 Utility-first styling
shadcn/ui Latest Component library (copy-paste)
TanStack Query 5.x Server state management
Lucide React Latest Icon library (2000+ icons)
Zustand 5.x Client state (cart, UI)

Backend & Database

Technology Purpose
Supabase PostgreSQL database + Auth + Realtime
PostgreSQL Primary database (v15)
Row Level Security (RLS) Multi-tenant data isolation
Postgres Functions Complex transactions (RPCs)

Infrastructure

Service Purpose Free Tier
Vercel Hosting + Edge Network 100GB bandwidth/month
Supabase Database + Auth 500MB DB, 2GB bandwidth
Vercel Analytics Performance monitoring 2,500 events/month

πŸ“‚ Project Structure

vapetrack-ph/
β”œβ”€β”€ app/                          # Next.js App Router
β”‚   β”œβ”€β”€ (auth)/                   # Route group: Authentication pages
β”‚   β”‚   β”œβ”€β”€ login/                # Login page
β”‚   β”‚   └── signup/               # Sign-up page
β”‚   β”œβ”€β”€ (dashboard)/              # Route group: Protected pages
β”‚   β”‚   β”œβ”€β”€ dashboard/            # Analytics dashboard
β”‚   β”‚   β”œβ”€β”€ pos/                  # Point of Sale
β”‚   β”‚   β”œβ”€β”€ inventory/            # Inventory management
β”‚   β”‚   β”œβ”€β”€ branches/             # Branch management
β”‚   β”‚   β”œβ”€β”€ staff/                # Staff management
β”‚   β”‚   └── reports/              # Reports & analytics
β”‚   β”œβ”€β”€ api/                      # API routes (serverless functions)
β”‚   β”‚   └── webhooks/             # External webhooks (PayMongo, etc.)
β”‚   β”œβ”€β”€ actions/                  # Server Actions (mutations)
β”‚   β”‚   β”œβ”€β”€ auth.ts               # Authentication actions
β”‚   β”‚   β”œβ”€β”€ products.ts           # Product CRUD
β”‚   β”‚   └── sales.ts              # Sales processing
β”‚   β”œβ”€β”€ layout.tsx                # Root layout (PWA manifest, fonts)
β”‚   β”œβ”€β”€ page.tsx                  # Landing page (redirects to login)
β”‚   └── globals.css               # Global styles + Tailwind imports
β”‚
β”œβ”€β”€ components/                   # React components
β”‚   β”œβ”€β”€ ui/                       # shadcn/ui components (Button, Card, etc.)
β”‚   β”œβ”€β”€ pos/                      # POS-specific components
β”‚   β”‚   β”œβ”€β”€ ProductGrid.tsx       # Product selection interface
β”‚   β”‚   β”œβ”€β”€ POSCart.tsx           # Shopping cart display
β”‚   β”‚   └── CheckoutModal.tsx     # Checkout flow
β”‚   β”œβ”€β”€ inventory/                # Inventory components
β”‚   β”‚   β”œβ”€β”€ ProductForm.tsx       # Add/Edit product
β”‚   β”‚   └── VariantManager.tsx    # Manage product variants
β”‚   └── layouts/                  # Shared layouts
β”‚       β”œβ”€β”€ DashboardLayout.tsx   # Main app layout
β”‚       └── POSLayout.tsx         # Fullscreen POS layout
β”‚
β”œβ”€β”€ lib/                          # Shared utilities
β”‚   β”œβ”€β”€ supabase/                 # Supabase client factories
β”‚   β”‚   β”œβ”€β”€ client.ts             # Browser client
β”‚   β”‚   β”œβ”€β”€ server.ts             # Server-side client (with auth)
β”‚   β”‚   └── middleware.ts         # Auth middleware
β”‚   β”œβ”€β”€ utils/                    # Helper functions
β”‚   β”‚   β”œβ”€β”€ cn.ts                 # Tailwind class merger
β”‚   β”‚   β”œβ”€β”€ formatters.ts         # Currency, date formatting
β”‚   β”‚   └── validators.ts         # Form validation
β”‚   └── hooks/                    # Custom React hooks
β”‚       β”œβ”€β”€ useAuth.ts            # Authentication hook
β”‚       β”œβ”€β”€ useCart.ts            # POS cart state (Zustand)
β”‚       └── useProducts.ts        # TanStack Query hooks
β”‚
β”œβ”€β”€ types/                        # TypeScript type definitions
β”‚   β”œβ”€β”€ database.ts               # Auto-generated Supabase types
β”‚   └── index.ts                  # Application-specific types
β”‚
β”œβ”€β”€ supabase/                     # Supabase configuration
β”‚   β”œβ”€β”€ migrations/               # Database migrations (SQL)
β”‚   β”‚   β”œβ”€β”€ 001_initial_schema.sql
β”‚   β”‚   β”œβ”€β”€ 002_rls_policies.sql
β”‚   β”‚   └── 003_rpcs.sql
β”‚   └── seed.sql                  # Sample data for testing
β”‚
β”œβ”€β”€ public/                       # Static assets
β”‚   β”œβ”€β”€ icons/                    # PWA icons (192x192, 512x512)
β”‚   β”œβ”€β”€ manifest.json             # PWA manifest
β”‚   └── favicon.ico               # Browser favicon
β”‚
β”œβ”€β”€ docs/                         # Documentation
β”‚   β”œβ”€β”€ PRD.md                    # Product requirements
β”‚   β”œβ”€β”€ ARCHITECTURE.md           # Technical architecture
β”‚   β”œβ”€β”€ SCHEMA.md                 # Database schema
β”‚   β”œβ”€β”€ API_SPEC.md               # Backend API spec
β”‚   β”œβ”€β”€ UI_UX.md                  # Design system
β”‚   β”œβ”€β”€ ROADMAP.md                # Implementation roadmap
β”‚   └── README.md                 # This file
β”‚
β”œβ”€β”€ .env.example                  # Environment variables template
β”œβ”€β”€ .env.local                    # Your local env vars (git-ignored)
β”œβ”€β”€ next.config.ts                # Next.js configuration
β”œβ”€β”€ tailwind.config.ts            # Tailwind configuration
β”œβ”€β”€ tsconfig.json                 # TypeScript configuration
β”œβ”€β”€ eslint.config.mjs             # ESLint configuration
└── package.json                  # Dependencies

πŸ”‘ Core Concepts

1. Multi-Tenancy via Row-Level Security (RLS)

Every table has an organization_id column. Supabase RLS policies automatically filter queries:

// Application code - NO manual filtering needed
const { data: products } = await supabase
  .from('products')
  .select('*');  // Returns ONLY current user's organization products

// RLS policy enforces:
// WHERE organization_id = current_user.organization_id

Key Rules:

  • βœ… Never write WHERE organization_id = X in application code
  • βœ… Trust RLS policies to enforce tenant isolation
  • βœ… Test with multiple organizations to verify RLS works

2. Product Variants Pattern

Two-table approach: products (base info) β†’ product_variants (SKUs, prices, stock)

// Example: Vape juice with 3 nicotine levels
Product: {
  id: "prod-001",
  name: "Premium Mango Juice",
  brand: "Cloud9",
  category_id: "juice"
}

Variants: [
  { sku: "PMJ-3MG", name: "3mg", price: 450, capital_cost: 300, stock: 10 },
  { sku: "PMJ-6MG", name: "6mg", price: 450, capital_cost: 300, stock: 5 },
  { sku: "PMJ-12MG", name: "12mg", price: 500, capital_cost: 330, stock: 8 }
]

Critical Rules:

  • βœ… All sales reference product_variants, NOT products
  • βœ… Single-variant products still need one variant (e.g., "Standard")
  • βœ… Inventory tracked per variant, not per product

3. Server Actions for Mutations

Use Next.js Server Actions (not API routes) for database writes:

// app/actions/products.ts
'use server';

export async function createProduct(formData: FormData) {
  const supabase = createServerClient(); // Auto-includes auth
  
  const { data, error } = await supabase
    .from('products')
    .insert({
      name: formData.get('name'),
      // organization_id injected by RLS automatically
    });
  
  if (error) throw error;
  return data;
}

Benefits:

  • Type-safe by default
  • No CSRF tokens needed
  • Works with React 19's useFormState

4. Optimistic UI with TanStack Query

For fast POS interactions, assume success and rollback on error:

const { mutate } = useMutation({
  mutationFn: createSale,
  onMutate: async (newSale) => {
    // Cancel in-flight queries
    await queryClient.cancelQueries({ queryKey: ['sales'] });
    
    // Optimistically update UI
    queryClient.setQueryData(['sales'], (old) => [...old, newSale]);
  },
  onError: (_, __, context) => {
    // Rollback on failure
    queryClient.setQueryData(['sales'], context.previousSales);
    toast.error('Sale failed. Please retry.');
  }
});

πŸ§ͺ Development Workflow

Common Tasks

# Start development server
npm run dev

# Run type checking (catches errors before runtime)
npm run build

# Run linter
npm run lint

# Generate Supabase types (after schema changes)
npx supabase gen types typescript --project-id <your-project-ref> > types/database.ts

Adding a New Feature

  1. Read documentation first (PRD, Schema, API Spec)
  2. Check RLS policies (ensure new tables have tenant isolation)
  3. Use Server Actions for mutations
  4. Implement optimistic UI for interactive features
  5. Test with multiple organizations to verify RLS

Adding shadcn/ui Components

# Copy components into your project (don't install as dependency)
npx shadcn@latest add button
npx shadcn@latest add card
npx shadcn@latest add dialog

# Components are copied to components/ui/
# Customize freely - you own the code

πŸ“± Mobile Testing

Target devices: Android phones (5.5" - 6.7" screens)

Chrome DevTools Emulation

  1. Open Chrome DevTools (F12)
  2. Toggle device toolbar (Ctrl+Shift+M)
  3. Select iPhone SE (375Γ—667) or Pixel 5 (393Γ—851)
  4. Test touch interactions (click = tap)

Testing on Real Devices

  1. Ensure dev server is running: npm run dev
  2. Find your local IP: ipconfig (Windows) or ifconfig (Mac/Linux)
  3. Access from phone: http://192.168.x.x:3000
  4. Note: Phone and PC must be on same WiFi network

πŸš€ Deployment

Vercel (Recommended)

# Install Vercel CLI
npm install -g vercel

# Deploy to production
vercel --prod

Or use GitHub integration:

  1. Push code to GitHub
  2. Import repo in Vercel Dashboard
  3. Add environment variables (Supabase keys)
  4. Deploy automatically on every push

Environment Variables to Set:

  • NEXT_PUBLIC_SUPABASE_URL
  • NEXT_PUBLIC_SUPABASE_ANON_KEY
  • SUPABASE_SERVICE_ROLE_KEY (server-side only)

πŸ“š Documentation


πŸ› Troubleshooting

Common Issues

❌ Error: Invalid API key

  • Check .env.local has correct Supabase keys
  • Restart dev server after changing env vars: npm run dev

❌ Module not found: Can't resolve 'types/database'

  • Generate types: npx supabase gen types typescript --project-id <ref> > types/database.ts

❌ RLS policies blocking queries

  • Verify user's JWT contains organization_id claim
  • Check RLS policies in Supabase Dashboard β†’ Authentication β†’ Policies

❌ Styles not loading

  • Clear .next cache: rm -rf .next (Mac/Linux) or rmdir /s .next (Windows)
  • Restart dev server

πŸ› οΈ Validation & Quality

To ensure code quality and consistency, we use ESLint and Next.js built-in validation tools.

# Run linting
npm run lint

# Run type-checking and build validation
npm run build

πŸš€ SaaS Project Overview

Many vape shops in the Philippines still rely on manual logbooks or unwieldy spreadsheets, leading to inaccurate inventory, lost profits, and limited visibility over staff actions. VapeTrack PH SaaS streamlines retail operations with:

  • Real-time inventory tracking
  • Sales and profit analytics
  • Staff accountability and activity logs
  • Multi-branch management
  • Multi-tenant (each shop has its own secure workspace)
  • Subscription management and billing
  • Self-service onboarding and account management

All via a cloud-based, web interface accessible from phones, tablets, or PCs. No installation or server setup required.


❌ Out of Scope

To ensure affordability and simplicity:

  • ❌ No barcode scanning
  • ❌ No receipt printing
  • ❌ No hardware dependencies
  • ❌ No on-premise/self-hosted version

πŸ‘₯ User Roles

  • Shop Owner: Full access to their shop's workspace, branch and staff management, analytics, subscription management, reporting.
  • Staff (Taga-bantay): PIN login, branch selection, sales recording, view limited product info.
  • Platform Admin (SaaS): Manages tenants, billing, and platform-wide settings (internal use).

✨ Key Features (SaaS)

  • πŸ” Role-based authentication (Owner, Staff, Platform Admin)
  • 🏬 Multi-branch support per tenant
  • πŸ“¦ Inventory and product management
  • πŸ’° Sales, profit, and capital tracking
  • πŸ“Š Advanced analytics and reporting (Daily/Weekly/Monthly/Yearly)
  • 🧾 Staff audit logs
  • ⚠️ Low-stock alerts
  • 🏒 Multi-tenant architecture (each shop is isolated)
  • πŸ’³ Subscription & billing management
  • πŸ“ Self-service onboarding and workspace creation
  • πŸ”„ Cloud backups and data security
  • πŸ“± Fully mobile-responsive UI

πŸ› οΈ Tech Stack

  • Frontend: Next.js 16, React 19, Tailwind CSS 4
  • Backend: Nextjs API route, Supabase (serverless backend with real-time queries)
  • Database: Supabase(Postgresql)
  • Authentication: Supabase Auth
  • Payments: PayMongo
  • Deployment: Vercel (frontend) + Supabase (Database)

🚦 Getting Started (For Developers)

1. Clone the Repository

git clone https://github.com/YOUR_USERNAME/vapetrack-ph.git
cd vapetrack-ph

2. Install Dependencies

npm install

3. Set Up Environment

Copy .env.example to .env.local and fill in Supabase credentials, PayMongo keys, and other SaaS configs.

4. Run Development Server

npm run dev

Visit http://localhost:3000 to access the app.


🚒 Deployment

Frontend (Vercel)

The frontend is optimized for deployment on the Vercel Platform.

  1. Connect your GitHub repository to Vercel.
  2. Configure environment variables (refer to .env.local).
  3. Deploy!

Backend (Supabase)

The backend is powered by Supabase.

  1. Create a new project on Supabase.
  2. Set up your database schema using the Supabase dashboard or migrations.
  3. Add the NEXT_PUBLIC_SUPABASE_URL and NEXT_PUBLIC_SUPABASE_ANON_KEY to your Vercel project settings.

πŸ“š Documentation


πŸ“œ License

This project is licensed under the MIT License - see the LICENSE file for details.


πŸ•’ Changelog

Stay updated with the latest changes in the GitHub Releases page.


πŸ’‘ Contribution

Contributions, feedback, and bug reports are welcome! Please open Issues and Pull Requests.


About

Resources

Stars

0 stars

Watchers

0 watching

Forks

Releases

No releases published

Packages

 
 
 

Contributors