A comprehensive telehealth platform built with Next.js, TypeScript, and Firebase, featuring advanced state management, monitoring, and a unified component architecture.
# 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- Architecture Overview
- Key Features
- Project Structure
- Development Guidelines
- API Documentation
- Testing Strategy
- Deployment
- Contributing
- Unified Database Layer: Single TypeScript service for all data operations
- Component-First Design: Reusable, configurable components with minimal duplication
- Type Safety: Comprehensive TypeScript coverage with strict mode
- Performance Optimization: React Query caching, lazy loading, and performance monitoring
- Error Resilience: Multi-level error boundaries with recovery mechanisms
- 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
- 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
- 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
- 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
- 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
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
- TypeScript Strict Mode: All code must pass strict type checking
- Component Props: Use interfaces for all component props
- Error Handling: Wrap async operations in try-catch blocks
- Performance: Use React.memo, useCallback, useMemo for optimization
- Testing: Minimum 80% code coverage for critical paths
// ✅ 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 }
}}
/>
);
}// ✅ 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} />;
}// ✅ 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>
);
}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
});Create a new patient record.
const createPatient = useCreatePatient();
createPatient.mutate({
firstName: 'John',
lastName: 'Doe',
email: '[email protected]',
// ... other patient fields
});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();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' });- Components: Test rendering, props, and user interactions
- Hooks: Test data fetching, mutations, and error states
- Utilities: Test helper functions and type guards
- Database Operations: Test CRUD operations with mock data
- Authentication Flow: Test login, logout, and permission checks
- Form Validation: Test form submission and validation
- User Workflows: Test complete user journeys
- Error Scenarios: Test error handling and recovery
- Performance: Test Core Web Vitals and load times
# 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# 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 for production
npm run build
# Start production server
npm start
# Deploy to Vercel
vercel deploy- 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
- Fork & Clone: Fork the repository and clone locally
- Branch: Create a feature branch from
main - Develop: Make changes following coding standards
- Test: Ensure all tests pass and coverage is maintained
- Document: Update documentation for new features
- Pull Request: Submit PR with clear description
# 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- TypeScript strict mode compliance
- Test coverage for new features
- Performance impact assessed
- Security implications reviewed
- Accessibility standards met
- Documentation updated
- 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]
This project is licensed under the MIT License - see the LICENSE file for details.
Built with ❤️ by the Telehealth Dashboard Team