Initializing
Back to Projects
Year2024
DomainFullstack
AccessOpen Source
Complexity0 / 10
Express.jsEJSSQLiteNode.jsTelegram BotAdmin DashboardQuote SystemTailwind CSS
FullstackArchived

Popular Enterprise - Pickles & Spices Business Website

A complete business website for an Indian pickle and spice manufacturer with product catalog, quote management system, admin dashboard, and Telegram notifications.

Parsing system architecture diagram...

Technology Stack

LayerTechnologyVersion/Details
BackendExpress.js^5.2.1
Template EngineEJS^4.0.1
DatabaseSQLitesqlite3 ^5.1.7
Sessionexpress-session^1.19.0
Securityhelmet^8.1.0
Authenticationbcryptjs^3.0.3
Notificationsnode-telegram-bot-api^0.67.0
File Uploadmulter^2.0.2
Image Optimizationsharp^0.34.5
Compressioncompression^1.8.1
CSSTailwind CSS^4.1.18
Lighthouse@lhci/cli^0.15.1

Purpose and Philosophy

Popular Enterprise is a complete business website designed for an Indian pickle and spice manufacturing company. The project implements a quote-based e-commerce model rather than direct online purchasing, which is common in traditional Indian businesses where pricing may vary based on quantity, location, and seasonal availability.

The core philosophy centers on "Digital Traditional Commerce" - combining modern web technologies with traditional business practices. The system respects the way Indian B2B and B2C commerce often operates: customers inquire about products, receive personalized quotes, and complete transactions through phone calls or in-person meetings.

Core Design Principles

  1. Quote-First Model: Instead of checkout, customers request quotes. This allows for flexible pricing based on quantity, location, and seasonal factors common in the food industry.
  1. Instant Notifications: Every customer action (quote request, contact form, feedback) triggers an immediate Telegram notification to the business owner, ensuring rapid response.
  1. Complete Admin Control: A comprehensive dashboard gives the business owner full control over products, quotes, sales tracking, and reporting.
  1. Audit Trail: All admin actions are logged for accountability and tracking.
  1. Performance Optimized: The project includes image optimization scripts and Lighthouse CI integration for maintaining high performance.

Database Schema

Tables Overview

sql
-- Categories (Pickles, Spices, etc.)
CREATE TABLE categories (
    id INTEGER PRIMARY KEY AUTOINCREMENT,
    name TEXT NOT NULL UNIQUE,
    description TEXT
);

-- Products with SEO fields
CREATE TABLE products (
    id INTEGER PRIMARY KEY AUTOINCREMENT,
    name TEXT NOT NULL,
    category_id INTEGER,
    description TEXT,
    main_image TEXT,
    seo_title TEXT,
    seo_description TEXT,
    FOREIGN KEY (category_id) REFERENCES categories(id)
);

-- Product variants (size + price)
CREATE TABLE product_variants (
    id INTEGER PRIMARY KEY AUTOINCREMENT,
    product_id INTEGER,
    size TEXT,
    price REAL,
    cost_price REAL,
    FOREIGN KEY (product_id) REFERENCES products(id)
);

-- Quote requests from customers
CREATE TABLE quotes (
    id INTEGER PRIMARY KEY AUTOINCREMENT,
    name TEXT NOT NULL,
    phone TEXT NOT NULL,
    product_id INTEGER,
    variant_id INTEGER,
    quantity INTEGER,
    address TEXT,
    status TEXT DEFAULT 'New',
    created_at DATETIME DEFAULT CURRENT_TIMESTAMP
);

-- Sales records
CREATE TABLE sales_records (
    id INTEGER PRIMARY KEY AUTOINCREMENT,
    date TEXT DEFAULT CURRENT_TIMESTAMP,
    product_id INTEGER,
    variant_id INTEGER,
    customer_name TEXT,
    quantity INTEGER,
    unit_price REAL,
    total_price REAL,
    quote_id INTEGER
);

-- Contact form submissions
CREATE TABLE contacts (
    id INTEGER PRIMARY KEY AUTOINCREMENT,
    name TEXT NOT NULL,
    email TEXT,
    phone TEXT,
    message TEXT,
    status TEXT DEFAULT 'New'
);

-- Customer feedback
CREATE TABLE feedbacks (
    id INTEGER PRIMARY KEY AUTOINCREMENT,
    name TEXT NOT NULL,
    rating INTEGER,
    comment TEXT,
    status TEXT DEFAULT 'Pending'
);

-- Compliance documents (certificates)
CREATE TABLE compliance_files (
    id INTEGER PRIMARY KEY AUTOINCREMENT,
    title TEXT NOT NULL,
    file_path TEXT NOT NULL,
    expiry_date TEXT,
    is_public BOOLEAN DEFAULT 1
);

-- Admin users
CREATE TABLE admin_users (
    id INTEGER PRIMARY KEY AUTOINCREMENT,
    username TEXT NOT NULL UNIQUE,
    password TEXT NOT NULL,
    role TEXT DEFAULT 'Admin'
);

-- Audit logs
CREATE TABLE audit_logs (
    id INTEGER PRIMARY KEY AUTOINCREMENT,
    admin_id INTEGER,
    action TEXT NOT NULL,
    details TEXT,
    created_at DATETIME DEFAULT CURRENT_TIMESTAMP
);

-- Quote contact logs
CREATE TABLE quote_contact_logs (
    id INTEGER PRIMARY KEY AUTOINCREMENT,
    quote_id INTEGER,
    admin_id INTEGER,
    note TEXT NOT NULL,
    created_at DATETIME DEFAULT CURRENT_TIMESTAMP
);

API Endpoints

Public API Routes

javascript
// Quote Request
router.post('/quote', async (req, res) => {
    const { name, phone, product_id, variant_id, quantity, address } = req.body;
    // Insert quote, send Telegram notification
});

// Contact Form
router.post('/contact', async (req, res) => {
    const { name, email, phone, message } = req.body;
    // Insert contact, send Telegram notification
});

// Feedback
router.post('/feedback', async (req, res) => {
    const { name, rating, comment } = req.body;
    // Insert feedback, send Telegram notification
});

Admin API Routes

javascript
// Product Management
router.get('/admin/products/:id', ...);     // Get single product
router.post('/admin/products', ...);        // Add product with variants
router.put('/admin/products/:id', ...);     // Update product
router.delete('/admin/products/:id', ...);   // Delete product

// Quote to Sale Conversion
router.post('/admin/convert-to-sale', ...); // Convert quote to sales record

// Bulk Sales Import
router.post('/admin/sales/import', ...);     // CSV bulk import

// Contact Management
router.delete('/admin/contacts/:id', ...);   // Delete contact

Telegram Notifications

javascript
// services/telegram.js
const TelegramBot = require('node-telegram-bot-api');
const bot = new TelegramBot(process.env.TELEGRAM_TOKEN, { polling: false });

async function sendNotification(message) {
    try {
        await bot.sendMessage(process.env.TELEGRAM_CHAT_ID, message, {
            parse_mode: 'Markdown'
        });
    } catch (err) {
        console.error('Telegram notification failed:', err);
    }
}

// Quote notification format
const message = `
📦 *NEW QUOTE REQUEST*

👤 *Name:* ${name}
📞 *Phone:* ${phone}
🛒 *Product:* ${product.name}
⚖ *Size:* ${variant.size}
🔢 *Quantity:* ${quantity}
📍 *Address:* ${address || 'N/A'}

🕒 *Time:* ${new Date().toLocaleString()}
`.trim();

Admin Dashboard Features

Dashboard KPIs

  • Today's Sales Total
  • This Month Sales
  • Pending Quotes
  • Conversion Rate (Completed/Total Quotes)
  • Total Products

Dashboard Charts

  • Weekly sales trends (line chart)
  • Top selling products (bar chart)
  • Recent quote requests

Product Management

  • Add/Edit/Delete products
  • Upload product images
  • Add size variants with pricing
  • Set SEO meta title and description

Quote Management

  • View all quote requests
  • Filter by status (New, Contacted, Completed, Cancelled)
  • Convert quote to sale
  • Add contact logs/notes
  • Export to CSV

Sales Management

  • Manual sales entry
  • Automatic sales creation from completed quotes
  • Bulk CSV import for daily sales logs

Reports Module

  • Daily sales summary
  • Product-wise sales
  • Pending quotes report
  • Conversion rate analysis
  • Weekly/Monthly totals

Contact Queries

  • View all contact form submissions
  • Mark as resolved
  • Export data

Feedback Moderation

  • Review feedback submissions
  • Approve/Delete feedback
  • Only approved feedback displayed on site

Compliance File Manager

  • Upload certificates and licenses
  • Set expiry dates
  • Public or admin-only visibility

Audit Logs

  • Track admin actions
  • Product edits
  • Quote status changes
  • Sales record modifications
  • File uploads

Settings

  • Site name and description
  • Contact information
  • Social media links
  • Business hours

Quote Workflow

code
Customer browses products

Selects product, chooses variant and quantity

Fills quote form (name, phone, address)

Quote saved to database

Telegram notification sent instantly to owner

Owner views quote in admin dashboard

Owner contacts customer via phone

If sale completed: Owner marks quote as "Completed"

System auto-creates sales record

Sales reflected in reports and KPIs

Security Implementation

Authentication

javascript
// Session-based auth with bcrypt
const bcrypt = require('bcryptjs');

// Password comparison
if (user && await bcrypt.compare(password, user.password)) {
    req.session.adminId = user.id;
    req.session.role = user.role;
}

Security Headers (Helmet)

javascript
app.use(helmet({
    contentSecurityPolicy: {
        directives: {
            script-src: ["'self'", "'unsafe-inline'", "https://cdn.jsdelivr.net"],
            style-src: ["'self'", "'unsafe-inline'", "https://fonts.googleapis.com"],
            img-src: ["'self'", "data:", "https://*"],
            font-src: ["'self'", "https://fonts.gstatic.com"]
        }
    }
}));

Session Configuration

javascript
app.use(session({
    store: new SQLiteStore({ db: 'sessions.db' }),
    secret: process.env.SESSION_SECRET,
    resave: false,
    saveUninitialized: false,
    cookie: {
        maxAge: 30 * 24 * 60 * 60 * 1000, // 30 days
        httpOnly: true
    }
}));

Performance Optimization

Image Optimization Script

javascript
// scripts/optimize-images.js
const sharp = require('sharp');
const glob = require('glob');
const path = require('path');

async function optimizeImages() {
    const files = glob.sync('public/assets/**/*.{png,jpg,jpeg}');
    
    for (const file of files) {
        const outputPath = file.replace('/assets/', '/assets/optimized/');
        await sharp(file)
            .webp({ quality: 80 })
            .toFile(outputPath.replace(/\.[^.]+$/, '.webp'));
    }
}

Tailwind Build

bash
npm run build:css
# Generates optimized CSS from Tailwind

Lighthouse CI Integration

bash
npm run lhci
# Runs Lighthouse audits with CI

Key Features Summary

Public Website

  1. Homepage - Brand intro, featured products
  2. Products Catalog - Category filtering, product grid
  3. Product Details - Images, variants with prices, description, Request Quote button
  4. Compliances - Public certificates and licenses
  5. About Us - Company story and heritage
  6. Contact Us - Contact form, phone, address

Admin Dashboard

  1. Dashboard - KPIs, charts, recent activity
  2. Products - Full CRUD with image upload
  3. Quotes - View, manage, convert to sales
  4. Sales - Manual entry, bulk import, auto-generation
  5. Reports - Sales analytics, conversion rates
  6. Contacts - Contact form submissions management
  7. Feedbacks - Moderation system
  8. Compliances - Document management
  9. Settings - Site configuration
  10. Audit Logs - Action tracking

Notifications

  • New quote requests
  • New contact inquiries
  • New feedback submissions

Environment Variables

properties
PORT=3000
SESSION_SECRET=your_secret_key
TELEGRAM_TOKEN=your_telegram_bot_token
TELEGRAM_CHAT_ID=your_chat_id

Build and Run

bash
# Install dependencies
npm install

# Initialize database
node database/init.js

# Start server
npm start

# Optimize images
npm run images:optimize

# Build CSS
npm run build:css

# Run Lighthouse audit
npm run lhci

Conclusion

Popular Enterprise represents a comprehensive business website solution for traditional Indian food businesses transitioning to digital presence. The project demonstrates several sophisticated patterns:

  • Quote-Based E-commerce: Unlike typical online stores, this implements a inquiry-first model perfect for B2B and wholesale businesses
  • Real-Time Notifications: Telegram bot integration ensures instant awareness of customer inquiries
  • Complete Business Management: From product catalog to sales tracking to audit logs, the system provides end-to-end business management
  • Performance Focused: Image optimization, Tailwind CSS, and Lighthouse CI integration ensure fast loading times
  • Security Conscious: Helmet headers, bcrypt password hashing, session management, and audit logging

The system is ideal for small to medium food manufacturing businesses looking to establish a professional web presence while maintaining their traditional business processes.

(End of file - 585 lines)

Architecture Feedback

Spotted a potential optimization or antipattern? Let me know.

Submit a Technical Suggestion