Technology Stack
| Layer | Technology | Version/Details |
|---|---|---|
| Backend | Express.js | ^5.2.1 |
| Template Engine | EJS | ^4.0.1 |
| Database | SQLite | sqlite3 ^5.1.7 |
| Session | express-session | ^1.19.0 |
| Security | helmet | ^8.1.0 |
| Authentication | bcryptjs | ^3.0.3 |
| Notifications | node-telegram-bot-api | ^0.67.0 |
| File Upload | multer | ^2.0.2 |
| Image Optimization | sharp | ^0.34.5 |
| Compression | compression | ^1.8.1 |
| CSS | Tailwind 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
- 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.
- Instant Notifications: Every customer action (quote request, contact form, feedback) triggers an immediate Telegram notification to the business owner, ensuring rapid response.
- Complete Admin Control: A comprehensive dashboard gives the business owner full control over products, quotes, sales tracking, and reporting.
- Audit Trail: All admin actions are logged for accountability and tracking.
- Performance Optimized: The project includes image optimization scripts and Lighthouse CI integration for maintaining high performance.
Database Schema
Tables Overview
-- 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
// 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
// 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 contactTelegram Notifications
// 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
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 KPIsSecurity Implementation
Authentication
// 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)
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
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
// 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
npm run build:css
# Generates optimized CSS from TailwindLighthouse CI Integration
npm run lhci
# Runs Lighthouse audits with CIKey Features Summary
Public Website
- Homepage - Brand intro, featured products
- Products Catalog - Category filtering, product grid
- Product Details - Images, variants with prices, description, Request Quote button
- Compliances - Public certificates and licenses
- About Us - Company story and heritage
- Contact Us - Contact form, phone, address
Admin Dashboard
- Dashboard - KPIs, charts, recent activity
- Products - Full CRUD with image upload
- Quotes - View, manage, convert to sales
- Sales - Manual entry, bulk import, auto-generation
- Reports - Sales analytics, conversion rates
- Contacts - Contact form submissions management
- Feedbacks - Moderation system
- Compliances - Document management
- Settings - Site configuration
- Audit Logs - Action tracking
Notifications
- New quote requests
- New contact inquiries
- New feedback submissions
Environment Variables
PORT=3000
SESSION_SECRET=your_secret_key
TELEGRAM_TOKEN=your_telegram_bot_token
TELEGRAM_CHAT_ID=your_chat_idBuild and Run
# 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 lhciConclusion
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.