Skip to content

WimpyvL/Zappy-Health-Dashboard

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

272 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Telehealth Dashboard

A comprehensive telehealth platform built with Next.js, TypeScript, and Firebase, featuring advanced state management, monitoring, and a unified component architecture.

🚀 Quick Start

# Install dependencies
npm install

# Set up environment variables
cp .env.example .env.local
# Fill in your Firebase configuration

# Run development server
npm run dev

# Run tests
npm test

# Build for production
npm run build

📋 Table of Contents

🏗️ Architecture Overview

Core Principles

  1. Unified Database Layer: Single TypeScript service for all data operations
  2. Component-First Design: Reusable, configurable components with minimal duplication
  3. Type Safety: Comprehensive TypeScript coverage with strict mode
  4. Performance Optimization: React Query caching, lazy loading, and performance monitoring
  5. Error Resilience: Multi-level error boundaries with recovery mechanisms

Technology Stack

  • Frontend: Next.js 14, React 18, TypeScript
  • Backend: Firebase (Firestore, Auth, Storage)
  • State Management: React Query + Enhanced Auth Context
  • UI Components: Radix UI + Tailwind CSS
  • Testing: Jest, React Testing Library
  • Monitoring: Custom monitoring service with Core Web Vitals
  • Type Safety: Strict TypeScript with comprehensive type definitions

✨ Key Features

🔐 Authentication & Authorization

  • Role-based Access Control: Admin, Provider, Patient roles
  • Firebase Authentication: Email/password, social logins
  • Permission System: Granular permissions with UI enforcement
  • Session Management: Automatic token refresh and logout

📊 Data Management

  • Unified Database Service: Single source for all data operations
  • Optimistic Updates: Immediate UI feedback with rollback capability
  • Caching Strategy: 5-minute query cache with intelligent invalidation
  • Batch Operations: Efficient bulk create/update/delete operations

🎨 Component Architecture

  • AdminPage Component: Generic admin interface eliminating 90% code duplication
  • Configurable Tables: Sort, filter, paginate with minimal setup
  • Form Builder: Dynamic forms with validation and type safety
  • Error Boundaries: Graceful error handling with recovery options

📈 Performance & Monitoring

  • Core Web Vitals: Real-time LCP, FID, CLS tracking
  • Error Logging: Comprehensive error capture with context
  • Performance Analytics: User interaction and page load metrics
  • Resource Optimization: Code splitting, lazy loading, image optimization

📁 Project Structure

src/
├── app/                    # Next.js app router pages
│   ├── dashboard/         # Main dashboard application
│   │   ├── admin/        # Admin-specific pages
│   │   ├── patients/     # Patient management
│   │   └── providers/    # Provider management
│   └── auth/             # Authentication pages
├── components/           # Reusable UI components
│   ├── ui/              # Base UI components
│   ├── forms/           # Form components
│   └── __tests__/       # Component tests
├── lib/                 # Core utilities and configurations
│   ├── auth-context.tsx # Enhanced global state management
│   ├── firebase.ts      # Firebase configuration
│   ├── monitoring.ts    # Performance monitoring
│   └── test-utils.tsx   # Testing utilities
├── services/           # Business logic and data services
│   └── database/       # Unified database service
│       ├── hooks.ts    # React Query hooks
│       └── __tests__/  # Service tests
├── types/             # TypeScript type definitions
└── hooks/            # Custom React hooks

🛠️ Development Guidelines

Code Standards

  1. TypeScript Strict Mode: All code must pass strict type checking
  2. Component Props: Use interfaces for all component props
  3. Error Handling: Wrap async operations in try-catch blocks
  4. Performance: Use React.memo, useCallback, useMemo for optimization
  5. Testing: Minimum 80% code coverage for critical paths

Database Operations

// ✅ Good: Use unified database service
import { usePatients, useCreatePatient } from '@/services/database/hooks';

function PatientList() {
  const { data: patients, isLoading, error } = usePatients();
  const createPatient = useCreatePatient();
  
  if (error) return <ErrorMessage error={error} />;
  if (isLoading) return <LoadingSpinner />;
  
  return (
    <AdminPage
      config={{
        title: 'Patients',
        collectionName: 'patients',
        columns: patientColumns,
        permissions: { create: true, edit: true, delete: true }
      }}
    />
  );
}

Component Creation

// ✅ Good: Use AdminPage for consistent admin interfaces
import { AdminPage, AdminPageConfig } from '@/components/ui/admin-page';

const config: AdminPageConfig<Patient> = {
  title: 'Patient Management',
  description: 'Manage patient records and information',
  collectionName: 'patients',
  columns: [
    { key: 'firstName', label: 'First Name', sortable: true },
    { key: 'lastName', label: 'Last Name', sortable: true },
    { key: 'email', label: 'Email', sortable: true },
  ],
  permissions: {
    create: true,
    edit: true,
    delete: true,
    export: true,
  },
  filters: [
    { key: 'status', type: 'select', options: ['active', 'inactive'] },
    { key: 'plan', type: 'select', options: ['basic', 'premium'] },
  ],
};

export default function PatientsPage() {
  return <AdminPage config={config} />;
}

Error Handling

// ✅ Good: Comprehensive error handling
import { ErrorBoundary } from '@/components/error-boundary';
import { useToast } from '@/hooks/use-toast';

function MyComponent() {
  const { toast } = useToast();
  
  const handleAsyncOperation = async () => {
    try {
      await riskyOperation();
      toast({ title: 'Success', description: 'Operation completed' });
    } catch (error) {
      console.error('Operation failed:', error);
      toast({
        title: 'Error',
        description: 'Operation failed. Please try again.',
        variant: 'destructive'
      });
    }
  };

  return (
    <ErrorBoundary fallback={<ErrorFallback />}>
      {/* Component content */}
    </ErrorBoundary>
  );
}

📚 API Documentation

Database Hooks

usePatients(options?: QueryOptions)

Fetch patients with optional filtering, sorting, and pagination.

const { data, isLoading, error, refetch } = usePatients({
  filters: [{ field: 'status', op: '==', value: 'active' }],
  sortBy: 'lastName',
  sortDirection: 'asc',
  limit: 20
});

useCreatePatient()

Create a new patient record.

const createPatient = useCreatePatient();

createPatient.mutate({
  firstName: 'John',
  lastName: 'Doe',
  email: '[email protected]',
  // ... other patient fields
});

Auth Context

The enhanced auth context provides comprehensive state management:

const {
  // Authentication state
  user, loading, signIn, signUp, logout,
  
  // UI state management
  uiState, toggleSidebar, setTheme, addNotification,
  
  // Permission helpers
  hasRole, hasPermission
} = useAuth();

Monitoring Service

Track performance and errors:

import { monitoring } from '@/lib/monitoring';

// Record custom events
monitoring.recordEvent('user_action', { action: 'click', element: 'button' });

// Record performance metrics
monitoring.recordPerformance('api_call', startTime, endTime);

// Record errors
monitoring.recordError(error, { context: 'user_creation' });

🧪 Testing Strategy

Unit Tests

  • Components: Test rendering, props, and user interactions
  • Hooks: Test data fetching, mutations, and error states
  • Utilities: Test helper functions and type guards

Integration Tests

  • Database Operations: Test CRUD operations with mock data
  • Authentication Flow: Test login, logout, and permission checks
  • Form Validation: Test form submission and validation

E2E Tests

  • User Workflows: Test complete user journeys
  • Error Scenarios: Test error handling and recovery
  • Performance: Test Core Web Vitals and load times

Running Tests

# Run all tests
npm test

# Run tests in watch mode
npm run test:watch

# Run tests with coverage
npm run test:coverage

# Run E2E tests
npm run test:e2e

🚀 Deployment

Environment Setup

# Production environment variables
NEXT_PUBLIC_FIREBASE_API_KEY=your_api_key
NEXT_PUBLIC_FIREBASE_AUTH_DOMAIN=your_domain
NEXT_PUBLIC_FIREBASE_PROJECT_ID=your_project_id
FIREBASE_ADMIN_PRIVATE_KEY=your_private_key

Build Process

# Build for production
npm run build

# Start production server
npm start

# Deploy to Vercel
vercel deploy

Performance Checklist

  • Images optimized with Next.js Image component
  • Code splitting implemented for large pages
  • Bundle analyzer run and optimized
  • Core Web Vitals meeting targets
  • Error monitoring configured
  • Database indexes created
  • Security rules validated

🤝 Contributing

Development Workflow

  1. Fork & Clone: Fork the repository and clone locally
  2. Branch: Create a feature branch from main
  3. Develop: Make changes following coding standards
  4. Test: Ensure all tests pass and coverage is maintained
  5. Document: Update documentation for new features
  6. Pull Request: Submit PR with clear description

Commit Guidelines

# Format: type(scope): description
feat(auth): add role-based permission system
fix(database): resolve pagination issue
docs(readme): update API documentation
test(components): add AdminPage test coverage

Code Review Checklist

  • TypeScript strict mode compliance
  • Test coverage for new features
  • Performance impact assessed
  • Security implications reviewed
  • Accessibility standards met
  • Documentation updated

📞 Support

  • Documentation: Check this README and inline code comments
  • Issues: Create GitHub issues for bugs and feature requests
  • Discussions: Use GitHub Discussions for questions
  • Email: [email protected]

📄 License

This project is licensed under the MIT License - see the LICENSE file for details.


Built with ❤️ by the Telehealth Dashboard Team

Releases

Packages

Contributors

Languages