A comprehensive business management application for wholesale/retail operations built with ES6 modules, Firebase, and Capacitor for Android deployment.
- Purchase & Sales Management: Separate collections for purchases, retail sales, and wholesale sales
- Real-time Sync: Automatic UI updates via Firestore onSnapshot listeners
- Stock Tracking: Real-time stock levels with adjustment history
- Cash Management: Session-based cash tracking with sign-in/sign-out
- User Management: Role-based access (owner, manager, staff)
- Reports & Analytics: Daily/weekly/monthly reports with charts
- Bluetooth Printing: ESC/POS thermal printer support
- Audit Logging: 90-day retention for critical actions
- Outstanding Tracking: Customer/supplier payment management
- Offline Support: Service worker for offline functionality
- Frontend: Vanilla JavaScript (ES6 Modules)
- Database: Firebase Firestore
- Authentication: Firebase Auth
- Mobile: Capacitor 7.x (Android)
- Hosting: Firebase Hosting
- Testing: Jest + Babel
├── www/ # Web application
│ ├── js/
│ │ ├── __tests__/ # Unit tests
│ │ ├── auth/ # Authentication module
│ │ ├── firebase/ # Firestore service
│ │ ├── modules/ # Business logic modules
│ │ ├── services/ # Printer, audit services
│ │ ├── ui/ # UI management, navigation
│ │ ├── utils/ # Constants, state, helpers, validator
│ │ └── main.js # App initialization
│ ├── css/ # Modular stylesheets
│ ├── templates/ # HTML templates
│ ├── service-worker.js # Offline support
│ └── index.html # Main entry point
├── android/ # Capacitor Android project
├── jest.config.js # Jest test configuration
├── babel.config.js # Babel ES6 transform config
└── firebase.json # Firebase configuration
| Collection | Purpose | State Property |
|---|---|---|
items |
Product catalog with rates | AppState.items |
purchases |
Purchase transactions (stock IN) | AppState.purchaseHistory |
retailSales |
Retail sales from billing tab | AppState.retailSalesHistory |
wholesaleSales |
Wholesale sales from sales tab | AppState.salesHistory |
expenses |
Business expenses | AppState.expensesHistory |
stockAdjustments |
Manual stock corrections | AppState.stockAdjustments |
withdrawals |
Cash withdrawals | AppState.withdrawalsHistory |
cashSessions |
Cash management sessions | (loaded on demand) |
users |
User accounts and roles | (loaded on demand) |
The app uses Firestore onSnapshot listeners for automatic UI synchronization:
- Items: Updates item dropdowns across all tabs
- Purchases/Sales: Recalculates stock, updates history, finance, analytics
- Expenses: Updates expense history and reports
- Stock Adjustments: Recalculates stock levels
- Withdrawals: Updates withdrawal history
- Cash Sessions: Updates cash management view
All listeners are set up via FirebaseService.setupRealtimeListeners() and cleaned up on logout via FirebaseService.cleanup().
- Node.js 18+
- Firebase CLI (
npm install -g firebase-tools) - Android Studio (for mobile builds)
# Install dependencies
npm install# Run local server
npm start
# OR
npx http-server www -p 8080
# Deploy to Firebase
firebase deploy --only hosting# Sync Capacitor
npx cap sync android
# Open in Android Studio
npx cap open androidThe project uses Jest for unit testing with Babel for ES6 module transformation.
# Run all tests once
npm test
# Run tests in watch mode (re-runs on file changes)
npm run test:watch
# Run tests with coverage report
npm run test:coveragewww/js/__tests__/
├── __mocks__/
│ └── firebase-mock.js # Mock Firebase/Firestore for testing
├── helpers.test.js # Tests for utility helper functions (26 tests)
├── state.test.js # Tests for AppState module (31 tests)
└── validator.test.js # Tests for form validation utilities (45 tests)
| File | Statements | Branches | Functions | Lines |
|---|---|---|---|---|
| helpers.js | 62.96% | 38.88% | 75% | 62.74% |
| state.js | 100% | 100% | 100% | 100% |
| validator.js | 96.22% | 93.47% | 90% | 96% |
Tests are written using Jest syntax. Example:
import { Validator } from '../utils/validator.js';
describe('Validator', () => {
test('should validate required fields', () => {
const result = Validator.required('value', 'Field Name');
expect(result.valid).toBe(true);
});
});- Jest Config:
jest.config.js- Test environment, patterns, coverage settings - Babel Config:
babel.config.js- ES6 module transformation for Node.js
The app includes a comprehensive validation utility (www/js/utils/validator.js) for client-side form validation:
import { Validator } from './utils/validator.js';
// Validate a bill before saving
const result = Validator.validateBill({
sellerName: 'Supplier Name',
items: [{ name: 'Rice', rate: 50, weight: 10 }]
});
if (!result.valid) {
console.log(result.errors); // Array of error messages
}The app includes a service worker (www/service-worker.js) that:
- Caches static assets (CSS, JS, HTML, templates)
- Uses cache-first strategy for static files
- Uses network-first strategy for Firebase API calls
- Enables basic offline functionality
- Module Documentation: www/js/README.md
- Architecture Diagram: www/js/ARCHITECTURE_DIAGRAM.md
- Quick Start Guide: www/js/QUICK_START.md