A comprehensive, role-based web application for managing vision care services, patient information, inventory, clinics, and business operations. Built with modern technologies including React, GraphQL, Supabase, and Ant Design.
- Project Overview
- Key Features
- User Roles & Permissions
- Tech Stack
- Architecture
- Database Schema
- Prerequisites
- Installation
- Environment Configuration
- Database Setup
- Running the Application
- Project Structure
- Available Scripts
- Development Guidelines
- Design System
- Deployment
- Troubleshooting
- Contributing
- License
Vision Expert System is an enterprise-grade platform designed to streamline vision care operations across multiple branches. The system manages the complete lifecycle from patient registration and eye examinations to order processing, lab tracking, delivery, and financial management. With role-based access control, different stakeholders can access relevant features based on their responsibilities.
- Patient Registration: Comprehensive customer profiles with contact information, NIC, and date of birth
- Clinic Management: Schedule and manage vision clinics across different locations
- Prescription Management: Record detailed eye prescriptions with SPH, CYL, AXIS, and PD measurements
- Optometrist Dashboard: Specialized interface for eye care professionals
- Order Processing: Complete order lifecycle from placement to delivery
- Frame & Lens Management: Track frames by color, serial number, type, and status
- Batch Processing: Group orders into batches for efficient lab processing
- Order Status Tracking: Real-time status updates (Pending, Confirmed, In Lab, Ready, Delivered)
- Reminder Calls: Automated reminder system for customer follow-ups
- Stock Control: Multi-branch inventory tracking with real-time updates
- Supplier Management: Manage supplier relationships and product sourcing
- Brand & Product Catalog: Organized product database with types, brands, and SKUs
- Stock Movement: Track stock transfers between branches
- Damaged Stock: Report and manage damaged inventory with approval workflows
- Cash Handling: Multi-level cash management with approval workflows
- Petty Cash: Branch-level petty cash allocation and expense tracking
- Payment Processing: Handle payments, advances, discounts, and balance amounts
- Cash Transfers: Secure cash transfer system between branches and administration
- Revenue Tracking: Monitor branch performance against targets
- Sales Reports: Comprehensive sales analytics and filtering
- Cash Flow Views: Financial flow monitoring
- Order Flow Tracking: Visual order lifecycle tracking
- System Activity: Login tracking and user activity monitoring
- Branch Performance: Revenue and order target comparisons
- Complaint Tracking: Centralized complaint management system
- Warranty Claims: Handle warranty claims with approval workflows
- Resolution Tracking: Track complaint resolution progress
- Assignment System: Assign complaints to specific staff members
The system implements role-based access control with seven distinct user roles:
- Access Level: Full system access
- Key Features: Project management, branch management, user management, main stock handling, petty cash allocation, payment monitoring, comprehensive reports
- Dashboard:
/owner
- Access Level: Branch-level management
- Key Features: Branch stock management, incoming stock approval, cash handling, petty cash, pending payments, pending lab orders, complaint handling, clinic management
- Dashboard:
/manager-dashboard
- Access Level: Operational administration
- Key Features: Inventory management, customer lookup, batch tracking, lab follow-up, reminder calls, complaint management, petty cash handling, cash transfer approval
- Dashboard:
/admin-dashboard
- Access Level: Financial operations
- Key Features: Recovery details, recovery filtering, order filtering, daily sales, cash flow views, order flow views, financial reports
- Dashboard:
/accountant
- Access Level: Sales operations
- Key Features: New order creation, order management, order status changes, cash transfers, complaint viewing
- Dashboard:
/sales-executive-dashboard
- Access Level: Delivery and recovery
- Key Features: Recovery sheet, delivery management, cash transfers, recovery follow-up, customer lookup, warranty claims
- Dashboard:
/recovery-dashboard
- Access Level: Clinical operations
- Key Features: Prescription creation, patient management, clinical dashboard
- Dashboard:
/optometrist-dashboard
- React 19.2 - Modern UI library with concurrent features
- Vite 7.2 - Lightning-fast build tool and development server
- React Router 7.13 - Client-side routing with nested routes
- TailwindCSS 4.1 - Utility-first CSS framework with Vite plugin
- Ant Design (antd) 6.2 - Enterprise-class UI component library
- @ant-design/icons 6.1 - Comprehensive icon set
- Recharts 3.8 - Charting library for data visualization
- Supabase 2.93 - Backend-as-a-Service providing:
- PostgreSQL database
- Authentication system
- GraphQL API
- Real-time subscriptions
- Apollo Client 4.1 - GraphQL client with caching and state management
- GraphQL 16.12 - Query language for efficient data fetching
- Day.js 1.11 - Lightweight date manipulation library
- ExcelJS 4.4 - Excel file generation and manipulation
- File-saver 2.0 - Client-side file saving
- XLSX 0.18 - Spreadsheet file format support
- RxJS 7.8 - Reactive programming for complex state management
- ESLint 9.39 - Code quality and linting
- @vitejs/plugin-react 5.1 - React support for Vite
- TypeScript types - Type definitions for React components
The application follows a modern React architecture with:
- Component-Based Structure: Functional components with hooks
- Role-Based Routing: Protected routes based on user roles
- Centralized State Management: React Context for auth, Apollo Client for data
- Design System: Centralized design tokens for consistent UI
- GraphQL API Layer: Efficient data fetching with Apollo Client
- User logs in via Supabase Auth
- Session token stored and managed by Supabase client
- User role fetched from staff table via GraphQL
- Menu and routes dynamically generated based on role
- Protected routes enforce role-based access
- Read Operations: GraphQL queries via Apollo Client
- Write Operations: GraphQL mutations with optimistic updates
- Real-time Updates: Supabase subscriptions for live data
- Caching: Apollo Client cache for performance optimization
- Protected Routes: Route-level access control
- Context Providers: Auth context for global user state
- Custom Hooks: Reusable business logic extraction
- Component Composition: Complex UIs built from simple components
- Design Tokens: Centralized styling constants
The application uses PostgreSQL with a custom schema named vision_expert. The database consists of 40+ tables organized into logical groups:
- branch: Branch locations with revenue and order targets
- staff: Staff members linked to branches and roles
- role: User role definitions (Admin, Manager, etc.)
- customer: Customer profiles with personal information
- customer_has_branch: Customer-branch relationship mapping
- clinic: Vision clinic scheduling and management
- clinic_staff: Staff assignment to clinics
- clinic_expenses: Clinic expense tracking
- clinic_has_equipment: Equipment allocation to clinics
- clinic_attend_customer: Customer attendance records
- clinic_status: Clinic status definitions
- prescription: Eye examination prescriptions with measurements
- product: Product catalog with pricing and warranty
- product_type: Product type classifications
- brand: Brand information
- product_type_brand: Product-type-brand relationships
- stock: Inventory levels by branch
- stock_movement_history: Stock transfer tracking
- frame: Frame inventory with serial numbers
- frame_type: Frame type classifications
- lense_type: Lens type definitions with pricing
- order: Order records with complete lifecycle tracking
- order_status: Order status definitions
- order_status_history: Order status change history
- order_payment: Payment records for orders
- payment: Payment information with discounts and fees
- delivery_order: Delivery management
- batch: Order batching for lab processing
- batch_order: Order-to-batch relationships
- batch_timeline: Batch processing timeline
- lab_follow_up: Lab order tracking
- lab_follow_up_status: Lab status definitions
- petty_cash: Branch petty cash transactions
- petty_cash_allocation: Petty cash allocation to branches
- petty_cash_request: Petty cash request workflow
- cash_transfers_to_admin: Cash transfer management
- cash_transfer_status: Cash transfer status definitions
- cash_type: Cash type classifications
- complaint: Customer complaint records
- complaint_status: Complaint status definitions
- warranty: Warranty claim management
- supplier: Supplier information
- equipment: Equipment inventory
- branch_expenses: Branch expense tracking
- damaged_stock: Damaged inventory reporting
- damage_history: Damage event tracking
- re_order: Reorder requests
- reminder_call: Customer reminder call tracking
- login_activity: User login tracking
- Foreign Key Relationships: Maintained data integrity
- Timestamp Tracking: Created_at and updated_at fields
- Status Enums: Standardized status fields
- Check Constraints: Data validation at database level
- Identity Columns: Auto-incrementing primary keys
- UUID References: Integration with Supabase Auth
Before you begin, ensure you have the following installed on your system:
- Node.js (v18 or higher recommended) - Download
- npm (comes with Node.js) or yarn
- Git - Download
- Supabase Account - Create Account
- Docker (optional, for containerized development) - Download
git clone https://github.com/yourusername/Vision-Expert-System-v2.git
cd Vision-Expert-System-v2npm installOr if you prefer using yarn:
yarn installnpm run lintThis will check for any linting errors in your code.
Create a .env.local file in the root directory:
cp .env.example .env.localAdd your Supabase credentials to .env.local:
VITE_SUPABASE_URL=your_supabase_project_url
VITE_SUPABASE_PUBLISHABLE_KEY=your_supabase_anon_key- Go to your Supabase Dashboard
- Create a new project or select an existing one
- Navigate to Settings > API
- Copy the following values:
- Project URL: Your Supabase project URL
- anon/public key: The public API key
The application uses a custom PostgreSQL schema. Execute the schema setup:
- Go to your Supabase project's SQL Editor
- Execute the schema from
db/complete_schema.sql - Execute sample data from
db/sample_data.sql(optional)
Supabase provides GraphQL API automatically. Ensure:
- GraphQL is enabled in your Supabase project
- The GraphQL endpoint is accessible at:
https://your-project.supabase.co/graphql/v1 - Proper RLS (Row Level Security) policies are configured
Configure Supabase Authentication:
- Enable Email/Password authentication in Supabase
- Configure any additional OAuth providers if needed
- Set up user roles in the
roletable - Create staff accounts and link them to auth users
Run the sample data script to populate reference tables:
-- Execute in db/sample_data.sql
-- This will populate: roles, branches, product types, brands, order statuses, etc.Start the development server with hot module replacement:
npm run devThe application will be available at http://localhost:5173
Using Docker for containerized development:
docker-compose upThis will:
- Pull the Node.js 22 image
- Install dependencies
- Start the development server on port 5173
- Enable host access for external connections
Create an optimized production build:
npm run buildThe output will be in the dist/ directory.
Preview the production build locally:
npm run previewVision-Expert-System-v2/
├── public/ # Static assets
│ └── sample.txt
├── src/
│ ├── assets/ # Images, icons, and media
│ │ ├── icons/
│ │ └── images/
│ ├── auth/ # Authentication context and providers
│ │ ├── AuthContext.jsx
│ │ └── AuthProvider.jsx
│ ├── client/ # API clients and configuration
│ │ ├── supabase.js # Supabase client configuration
│ │ └── supabase-grphql-apollo.client.js # Apollo GraphQL client
│ ├── component/ # Reusable React components
│ │ ├── Admin/ # Admin-specific components
│ │ ├── Manager/ # Manager-specific components
│ │ ├── optimetrist/ # Optometrist-specific components
│ │ ├── owner/ # Owner-specific components
│ │ ├── recoveryOfficer/ # Recovery officer components
│ │ ├── sales-executive/ # Sales executive components
│ │ ├── shared/ # Shared components
│ │ ├── LogOut.jsx
│ │ ├── SideMenu.jsx
│ │ ├── Sidebar.jsx
│ │ └── TopHeader.jsx
│ ├── const/ # Constants and configuration
│ │ ├── branch.js
│ │ ├── designSystem.js # Design system tokens
│ │ ├── functions.js # Utility functions
│ │ ├── menu.jsx # Role-based menu configuration
│ │ └── text.js
│ ├── pages/ # Page components
│ │ ├── Accountant/ # Accountant pages (9 pages)
│ │ ├── AdministrativeOfficer/ # Admin pages (17 pages)
│ │ ├── Manager/ # Manager pages (11 pages)
│ │ ├── optimetrist/ # Optometrist pages (3 pages)
│ │ ├── owner/ # Owner pages (11 pages)
│ │ ├── recovery-officer/ # Recovery officer pages (9 pages)
│ │ ├── sales-executive/ # Sales executive pages (6 pages)
│ │ ├── track/ # Public order tracking
│ │ ├── login/ # Login page
│ │ ├── CommonPageStructure.jsx # Page layout wrapper
│ │ ├── ForgetPassword.page.jsx
│ │ └── OrderLookup.jsx # Shared order lookup
│ ├── routes/ # Routing configuration
│ │ ├── App.jsx # Main route definitions
│ │ └── protectedRoutes.jsx # Route protection logic
│ ├── main.css # Global styles
│ └── main.jsx # Application entry point
├── db/ # Database schema and data
│ ├── complete_schema.sql # Full database schema
│ ├── sample_data.sql # Sample/reference data
│ └── migrations/ # Database migration files
├── .agents/ # AI agent configurations
├── .git/ # Git repository
├── index.html # HTML entry point
├── package.json # Project dependencies
├── vite.config.js # Vite configuration
├── eslint.config.js # ESLint configuration
├── docker-compose.yml # Docker configuration
├── vercel.json # Vercel deployment config
├── .env.example # Environment variables template
├── .gitignore # Git ignore rules
└── README.md # This file
Starts the Vite development server with hot module replacement. Access at http://localhost:5173.
Creates an optimized production build in the dist/ directory using Vite.
Previews the production build locally using Vite's preview server.
Runs ESLint to check code quality and consistency across the project.
- ESLint Configuration: Follow rules defined in
eslint.config.js - Naming Conventions: Use camelCase for variables/functions, PascalCase for components
- Component Structure: Keep components focused and single-responsibility
- Functional Components: Use functional components with React hooks
- No Unused Variables: The linter enforces no unused variables (uppercase constants exempted)
- Pages: Store in
src/pages/[role]/directories - Components: Reusable components in
src/component/with role subdirectories - Constants: Centralized in
src/const/ - Utilities: Shared functions in
src/const/functions.js - Types: Use TypeScript types from
@types/reactpackages
- Global State: Use React Context API for auth and user state
- Server State: Use Apollo Client for GraphQL data with caching
- Local State: Use React hooks (useState, useReducer) for UI-specific state
- Form State: Use Ant Design Form components for form management
- TailwindCSS: Use utility classes for most styling
- Ant Design: Use Ant Design components for complex UI elements
- Design Tokens: Import from
src/const/designSystem.jsfor consistency - Custom CSS: Add to
src/main.cssonly when necessary - Responsive: Use Tailwind's responsive prefixes (md:, lg:, etc.)
- Queries: Define in component files using
gqltag - Mutations: Use optimistic updates for better UX
- Fragments: Use fragments for reusable field selections
- Error Handling: Implement proper error boundaries and handling
- Loading States: Show loading indicators during data fetches
- Branch Naming: Use
feature/,bugfix/,hotfix/prefixes - Commit Messages: Use conventional commit format
feat: add new featurefix: resolve bugdocs: update documentation
- Pull Requests: Provide detailed descriptions and testing steps
- Code Review: All changes require review before merging
The application uses a centralized design system defined in src/const/designSystem.js:
- Primary: Blue (#1890ff) - Main actions and branding
- Secondary: Purple (#722ed1) - Secondary actions
- Success: Green (#52c41a) - Success states
- Warning: Orange (#faad14) - Warning states
- Error: Red (#ff4d4f) - Error states
- Role-Specific Colors: Each role has a distinct color for identification
- Font Family: System font stack for optimal performance
- Font Sizes: Range from 12px (xs) to 32px (xxxl)
- Font Weights: Normal (400), Medium (500), Semibold (600), Bold (700)
- Line Heights: Tight (1.25), Normal (1.5), Relaxed (1.75)
- XS: 4px, SM: 8px, MD: 12px, LG: 16px
- XL: 20px, XXL: 24px, XXXL: 32px
- SM: 4px, MD: 8px, LG: 12px, XL: 16px, Round: 50px
Pre-defined styles for:
- Buttons (primary, secondary, danger, default)
- Cards (default, compact, elevated)
- Tables (default, compact)
- Forms (labels, inputs, selects, date pickers)
- Modals (default, large, small)
- Headers and stat cards
Standardized color mapping for status tags:
- Pending: default, In Progress: processing, Resolved: success
- Active: success, Inactive: error, Hold: warning
- Various order statuses with appropriate colors
The project includes vercel.json for single-page application routing:
{
"rewrites": [
{ "source": "/(.*)", "destination": "/index.html" }
]
}Deploy to Vercel:
- Connect your GitHub repository to Vercel
- Configure build settings:
- Build Command:
npm run build - Output Directory:
dist - Install Command:
npm install
- Build Command:
- Add environment variables in Vercel dashboard
- Deploy
Using the provided docker-compose.yml:
docker-compose up -dThis creates a containerized environment with Node.js 22.
- Build the project:
npm run build - Upload
dist/directory to your server - Configure your web server (Nginx, Apache) to serve the files
- Set up environment variables on the server
- Configure SSL/TLS for production
Ensure these are set in your production environment:
VITE_SUPABASE_URL=your_production_supabase_url
VITE_SUPABASE_PUBLISHABLE_KEY=your_production_anon_keyIf port 5173 is already in use, Vite will automatically use the next available port. To specify a different port:
npm run dev -- --port 3000Ensure all dependencies are installed:
npm installClear cache and reinstall if issues persist:
rm -rf node_modules package-lock.json
npm install- Verify your
.env.localcredentials are correct - Check that your Supabase project is active
- Ensure your API keys have the correct permissions
- Verify GraphQL is enabled in your Supabase project
- Check RLS policies allow necessary operations
- Verify your GraphQL endpoint is accessible
- Check that your schema matches the database
- Ensure authentication tokens are valid
- Review Apollo Client network errors in browser console
- Clear Vite cache:
rm -rf node_modules/.vite - Check for TypeScript errors in components
- Verify all imports are correct
- Ensure environment variables are set
- Check Supabase Auth configuration
- Verify email confirmation settings
- Ensure staff records exist in database
- Check role assignments in staff table
- Review auth context provider logic
- Check Apollo Client cache configuration
- Implement pagination for large datasets
- Use React.memo for expensive components
- Optimize GraphQL queries to fetch only needed fields
- Consider implementing loading skeletons
Contributions are welcome! Please follow these guidelines:
- Fork the Repository: Create your fork of the project
- Create a Branch: Use descriptive branch names
git checkout -b feature/your-feature-name
- Make Changes: Follow the development guidelines
- Test Thoroughly: Ensure all features work correctly
- Commit Changes: Use conventional commit messages
git commit -m 'feat: add new feature description' - Push to Fork: Push your changes to your fork
git push origin feature/your-feature-name
- Create Pull Request: Provide detailed description of changes
- All pull requests require review before merging
- Ensure code passes all linting checks
- Include tests for new features
- Update documentation as needed
- Respond to review feedback promptly
When reporting issues, include:
- Clear description of the problem
- Steps to reproduce
- Expected vs actual behavior
- Environment details (OS, Node version, browser)
- Screenshots if applicable
- Relevant error messages or logs
This project is licensed under the MIT License - see the LICENSE file for details.
For issues, questions, or suggestions:
- GitHub Issues: Open an issue on the repository
- Documentation: Refer to this README and inline code comments
- Team Contact: Contact the development team directly
Version: 2.0
Last Updated: July 2026
Maintained By: Vision Expert System Development Team
Acknowledgments
Built with modern web technologies and best practices to provide a comprehensive solution for vision care management. Special thanks to the open-source community for the amazing tools and libraries that make this project possible.