Skip to content

Latest commit

 

History

History
290 lines (185 loc) · 5.74 KB

File metadata and controls

290 lines (185 loc) · 5.74 KB

Inventory, Sales & Billing SaaS for Small Businesses

A multi-tenant, production-ready SaaS application that enables small shop owners to manage inventory, sales, billing, customers, credit (Udhar), staff roles, and business analytics all from a single dashboard.

Product Vision

Small retail businesses (kirana stores, mobile shops, medical stores) often rely on manual registers or fragmented apps for inventory, billing, and credit tracking.

This product provides:

  • End-to-end shop management
  • POS-style billing
  • Real-time inventory updates
  • Customer credit (Udhar) ledger
  • Actionable business insights

Built with scalability, security, and real-world workflows in mind.

Core Principles

  • Multi-tenant by design (each business is fully isolated)
  • Transaction-safe operations (no inconsistent stock)
  • Role-based access control
  • Backend-driven business logic
  • Production-grade architecture

High-Level Architecture

                ┌──────────────┐
                │   Frontend   │
                │ React + TS   │
                │ (Vite)       │
                └──────┬───────┘
                       │ HTTPS (JWT)
                       ▼
               ┌──────────────────┐
               │   Backend API    │
               │ Express + TS     │
               │ (REST)           │
               └──────┬───────────┘
                      │
        ┌─────────────┴─────────────┐
        ▼                           ▼
┌────────────────┐         ┌─────────────────┐
│ MongoDB Atlas  │         │ PDF Generator   │
│ (Multi-tenant) │         │ (Invoices)      │
└────────────────┘         └─────────────────┘

Key Architectural Decisions

1️ Multi-Tenancy via Business Isolation

  • Every user belongs to exactly one business
  • All entities (products, sales, customers, staff) are scoped by businessId
  • businessId is embedded inside JWT

Why?

  • Prevents data leaks
  • Enables SaaS scalability
  • Allows future subscription plans

2️ JWT-Based Authentication

  • Stateless authentication

  • Token includes:

    {
      "userId": "...",
      "businessId": "...",
      "role": "OWNER | MANAGER | CASHIER"
    }

Benefits

  • Horizontal scalability
  • Easy frontend integration
  • Clear authorization boundaries

3️ Role-Based Access Control (RBAC)

Role Capabilities
OWNER Full access
MANAGER Inventory + reports
CASHIER Billing only

Why?

  • Reflects real shop hierarchy
  • Prevents accidental destructive actions
  • Enterprise-grade authorization model

4️ Transaction-Safe Billing (Critical)

Billing uses MongoDB transactions:

Create Sale
 ├─ Validate products
 ├─ Check stock
 ├─ Deduct stock
 ├─ Create sale record
 └─ Commit transaction

If any step fails → rollback

Why this matters

  • No overselling
  • No partial updates
  • Production reliability

Data Model (Simplified)

User
 ├─ role
 └─ businessId

Business
 └─ ownerId

Product
 └─ businessId

Sale
 ├─ businessId
 ├─ items[]
 └─ paymentStatus

Customer
 ├─ businessId
 └─ balance (Udhar)

Staff (User)
 └─ role-based access

Billing & Invoice System

Features

  • POS-style billing
  • Paid / Unpaid (Udhar)
  • Auto stock deduction
  • Auto invoice number
  • PDF invoice generation (server-side)

Why server-side PDFs?

  • Tamper-proof
  • Consistent formatting
  • Audit-friendly

Udhar (Credit Ledger) System

A key India-specific differentiator.

How it works

  • Unpaid sales increase customer balance

  • Customer ledger shows:

    • Date
    • Invoice
    • Amount
  • Payments reduce balance

Business Value

  • Replaces manual Udhar notebooks
  • Prevents revenue leakage
  • Improves cash flow visibility

Analytics & Reporting

Dashboard APIs

  • Today’s sales
  • Monthly revenue
  • Pending Udhar
  • Low stock alerts

Reports

  • Sales history
  • Date-range filtering
  • Invoice re-download

Built using MongoDB aggregation pipelines for performance.

Frontend Architecture

  • Vite + React + TypeScript
  • POS-style billing UI
  • Axios with JWT interceptors
  • Protected routes
  • Modular API layer
UI → API Layer → Backend

Why this separation?

  • Maintainability
  • Testability
  • Easy future mobile app support

Security Considerations

  • Password hashing (bcrypt)
  • JWT validation middleware
  • Business-level data scoping
  • Role-based route protection
  • No direct client-side trust

Deployment Architecture

Component Platform
Backend Render
Frontend Vercel
Database MongoDB Atlas

Supports:

  • Horizontal scaling
  • Environment-based configs
  • Production logging

What This Project Demonstrates

This project showcases:

  • SaaS system design
  • Multi-tenant architecture
  • Secure authentication & authorization
  • Transactional consistency
  • Real-world business workflows
  • Full-stack TypeScript proficiency

Future Roadmap

  • Subscription plans
  • Offline-first mode
  • Reorder suggestions
  • GST reports