A modern retail inventory management application built with Couchbase Lite for web, featuring real-time sync capabilities with Couchbase Capella App Services.
- 📱 Offline-First: Full functionality without internet connection using Couchbase Lite
- 🔄 Real-Time Sync: Automatic bidirectional sync with Couchbase Capella App Services
- 🏪 Multi-Store Support: Manage inventory across multiple retail locations
- 📦 Inventory Management: Track products, stock levels, and orders
- 🎨 Modern UI: Built with React, TypeScript, and shadcn/ui components
- 🔐 Secure: Store-based authentication and data isolation
- Frontend: React 18 + TypeScript + Vite
- UI Framework: shadcn/ui + Tailwind CSS
- Database: Couchbase Lite for JavaScript
- Sync: Couchbase Capella App Services
- Icons: Lucide React
- State Management: TanStack Query
Important
Before proceeding with the web app setup, you must complete the Capella backend configuration described in the root README. This includes creating a Capella cluster, deploying an App Service, setting up the bucket/scopes/collections, importing the sample dataset, creating App Endpoints and App Users, recording the public connection URL, and configuring CORS for the web app. If you skip these steps, the app will fail to authenticate and sync.
- Node.js
- macOS: Version 18 or higher (install with nvm)
- Windows: Windows Installer (Version 24.15 was tested)
- npm: Comes with Node.js
- Couchbase Capella Account: For App Services sync functionality
git clone https://github.com/couchbase-examples/couchbase-lite-retail-demo.git
cd couchbase-lite-retail-demo/webnpm installUse the --verbose to troubleshoot any issues.
Copy the example environment file and configure it with your Couchbase Capella settings:
cp .env.example .envEdit .env and set your Couchbase App Services WebSocket URL:
# Get this from your Capella App Services dashboard
# Format: wss://your-endpoint.apps.cloud.couchbase.com:4984/database-name
VITE_APP_SERVICES_URL=wss://your-endpoint.apps.cloud.couchbase.com:4984Where to find your WebSocket URL:
- Log into Couchbase Capella
- Navigate to App Services
- Select your App Services endpoint
- Copy the complete WebSocket URL EXCLUDING the database path ('/supermarket-aa' or "/supermarket-nyc' will be automatically added inside the code, based on the user selection)
- Example:
wss://xxxxx.apps.cloud.couchbase.com
- Example:
npm run devThe output will look as follows. It indicates under which address/port the application is available, e.g. http://localhost:8080.
VITE v5.4.21 ready in 832 ms
➜ Local: http://localhost:8080/
➜ Network: http://169.254.83.107:8080/
➜ Network: http://192.168.0.158:8080/
➜ Network: http://172.19.160.1:8080/
Build the optimized production bundle:
npm run buildThe built files will be in the dist/ directory.
Preview the production build locally:
npm run previewNote
This command will run the application on port 4173. You will have to update the App Services endpoints' CORS settings to include http://localhost:4173 in order to be able to authenticate. You might want to refrain from doing so and just run npm run dev as described above.
web/
├── src/
│ ├── components/ # React components
│ ├── lib/
│ │ ├── database/ # Couchbase Lite database setup and types
│ │ └── auth.ts # Authentication helpers
│ ├── pages/ # Page components
│ └── App.tsx # Main app component
├── public/ # Static assets
├── .env.example # Environment variables template
└── package.json # Dependencies and scripts
The app uses email-based authentication with the following format:
- Email:
{store-id}@supermarket.com(e.g.,nyc-store-01@supermarket.com) - Password: As configured in your Capella App Services
The store ID is extracted from the email and determines:
- Which data scope the user has access to
- Store-specific inventory and orders
Note: The App Services URL configured in .env is used as-is without any modifications based on the store ID.
VITE_APP_SERVICES_URL: Complete WebSocket URL for your Capella App Services endpoint (including database path)
The following are defined in the application code and don't need to be configured:
- Database Name:
retail-inventory(defined insrc/lib/database/types.ts) - Database Version:
4(defined insrc/lib/database/types.ts) - Collections:
inventory,orders,profile - Scopes:
AA-Store,NYC-Store(automatically selected based on login)
npm run dev: Start development server with hot reloadnpm run build: Build for productionnpm run preview: Preview production build locallynpm run lint: Run ESLint to check code quality
- Verify your
VITE_APP_SERVICES_URLis correct - Check that your App Services endpoint is running
- Ensure your credentials are valid in Capella
- Check browser console for error messages
- Verbose logging:
npm install --verbose - Clear node_modules
- macOS:
rm -rf node_modules && npm install - Windows:
rd /s /q node_modules
- macOS:
- Clear cache
- macOS:
rm -rf dist .vite - Windows:
rd /s /q dist .vite
- macOS:
- Ensure Node.js version is 18 or higher:
node --version
- Run:
npm run buildto see all type errors - Ensure all dependencies are installed:
npm install