Skip to content

An application for healthcare workers to clock in and clock out of their shifts.

Notifications You must be signed in to change notification settings

akkupratap323/HealthShift

Repository files navigation

๐Ÿฅ HealthShift - Advanced Healthcare Workforce Management System

Next.js TypeScript GraphQL PWA Prisma Vercel

A cutting-edge Progressive Web Application for healthcare organizations to manage their workforce with intelligent location-based shift tracking, automatic geofencing notifications, and comprehensive analytics.

๐Ÿš€ Live Demo โ€ข ๐Ÿ“ฑ Install as PWA โ€ข ๐Ÿ“– Tutorial


๐ŸŒŸ Executive Summary

HealthShift revolutionizes healthcare workforce management by combining modern web technologies with intelligent location services. This comprehensive solution enables healthcare organizations to accurately track staff shifts through GPS-verified clock in/out functionality, automatic perimeter notifications, and powerful analytics - all wrapped in a beautiful, mobile-first Progressive Web App.

โœจ Key Features & Innovations

๐ŸŽฏ Smart Geofencing & Location Services

  • Automatic Perimeter Detection: AI-powered notifications when care workers enter/exit work locations
  • Intelligent Clock Reminders: Background location tracking with smart notifications
  • GPS-Verified Time Tracking: Prevent time fraud with location-based validation
  • Configurable Work Zones: Custom radius settings for each healthcare facility
  • Offline Location Sync: Queue location data when offline, sync when connected

๐Ÿ” Advanced Authentication & Security

  • Multi-Provider Auth: Google OAuth + Email authentication via Auth0
  • Role-Based Access Control: Granular permissions for managers and care workers
  • Manager Access Verification: Elegant 4-second overlay confirming authorized access
  • Secure Session Management: JWT tokens with automatic refresh
  • Data Encryption: End-to-end security for sensitive healthcare data

๐Ÿ“ฑ Progressive Web App Excellence

  • Native App Experience: Install directly to home screen on any device
  • Offline-First Architecture: Full functionality even without internet
  • Background Sync: Automatic data synchronization when connection restored
  • Push Notifications: Real-time alerts for shift reminders and updates
  • Service Worker: Advanced caching and performance optimization

๐Ÿ“Š Comprehensive Analytics Dashboard

  • Real-Time Workforce Monitoring: Live view of active shifts across all locations
  • Advanced Data Visualization: Interactive charts powered by Chart.js
  • Predictive Analytics: Workforce pattern analysis and optimization insights
  • Custom Reporting: Generate detailed reports for compliance and auditing
  • Performance Metrics: Average hours, productivity trends, and staffing efficiency

๐Ÿ‘ฉโ€โš•๏ธ Care Worker Experience

  • One-Tap Clock In/Out: Streamlined interface optimized for mobile use
  • Smart Location Tracking: Automatic detection with privacy controls
  • Shift History & Analytics: Personal performance tracking and insights
  • Optional Notes System: Add context to clock-ins with rich text notes
  • Notification Preferences: Customizable alert settings and frequencies

๐Ÿ‘จโ€๐Ÿ’ผ Manager Command Center

  • Live Staff Monitoring: Real-time dashboard showing all active shifts
  • Location Management: Create and configure multiple work locations
  • Staff Analytics: Individual and team performance insights
  • Compliance Reporting: Automated reports for regulatory requirements
  • Workforce Optimization: Data-driven scheduling recommendations

๐Ÿ—๏ธ Technical Architecture

System Architecture Diagram

graph TB
    A[Client Browser/PWA] --> B[Next.js 15 App Router]
    B --> C[Authentication Layer]
    C --> D[Auth0 Provider]
    B --> E[GraphQL API Layer]
    E --> F[Apollo Server]
    F --> G[Prisma ORM]
    G --> H[PostgreSQL Database]
    B --> I[Location Services]
    I --> J[Geolocation API]
    I --> K[Service Worker]
    K --> L[Background Sync]
    B --> M[PWA Components]
    M --> N[Manifest & Icons]
    M --> O[Push Notifications]
Loading

Data Flow Architecture

๐Ÿ“ฑ User Action โ†’ ๐Ÿ” Auth Check โ†’ ๐Ÿ“ Location Verify โ†’ ๐Ÿ“Š GraphQL API โ†’ ๐Ÿ’พ Database โ†’ ๐Ÿ”„ Real-time Update โ†’ ๐Ÿ“ฑ UI Refresh

๐Ÿ“ Complete Project Structure

healthcare-shift-tracker/
โ”œโ”€โ”€ ๐Ÿ“ prisma/
โ”‚   โ”œโ”€โ”€ schema.prisma                    # Database schema with relations
โ”‚   โ””โ”€โ”€ migrations/                      # Database migration history
โ”œโ”€โ”€ ๐Ÿ“ public/
โ”‚   โ”œโ”€โ”€ manifest.json                    # PWA manifest with shortcuts
โ”‚   โ”œโ”€โ”€ sw.js                           # Service worker (auto-generated)
โ”‚   โ”œโ”€โ”€ sw-enhanced.js                  # Custom service worker features
โ”‚   โ””โ”€โ”€ ๐Ÿ“ icons/                       # PWA icons (72x72 to 512x512)
โ”‚       โ”œโ”€โ”€ icon-72x72.png
โ”‚       โ”œโ”€โ”€ icon-96x96.png
โ”‚       โ”œโ”€โ”€ icon-128x128.png
โ”‚       โ”œโ”€โ”€ icon-144x144.png
โ”‚       โ”œโ”€โ”€ icon-152x152.png
โ”‚       โ”œโ”€โ”€ icon-192x192.png
โ”‚       โ”œโ”€โ”€ icon-384x384.png
โ”‚       โ””โ”€โ”€ icon-512x512.png
โ”œโ”€โ”€ ๐Ÿ“ src/
โ”‚   โ”œโ”€โ”€ ๐Ÿ“ app/                         # Next.js 15 App Router
โ”‚   โ”‚   โ”œโ”€โ”€ globals.css                 # Global Tailwind styles
โ”‚   โ”‚   โ”œโ”€โ”€ layout.tsx                  # Root layout with PWA meta tags
โ”‚   โ”‚   โ”œโ”€โ”€ page.tsx                    # Landing page with gradient design
โ”‚   โ”‚   โ”œโ”€โ”€ ๐Ÿ“ api/                     # API routes
โ”‚   โ”‚   โ”‚   โ”œโ”€โ”€ ๐Ÿ“ auth/
โ”‚   โ”‚   โ”‚   โ”‚   โ””โ”€โ”€ [...auth0]/route.ts # Auth0 authentication endpoints
โ”‚   โ”‚   โ”‚   โ””โ”€โ”€ ๐Ÿ“ graphql/
โ”‚   โ”‚   โ”‚       โ””โ”€โ”€ route.ts            # GraphQL API endpoint
โ”‚   โ”‚   โ”œโ”€โ”€ ๐Ÿ“ auth/
โ”‚   โ”‚   โ”‚   โ””โ”€โ”€ ๐Ÿ“ signin/
โ”‚   โ”‚   โ”‚       โ””โ”€โ”€ page.tsx            # Custom sign-in page
โ”‚   โ”‚   โ”œโ”€โ”€ ๐Ÿ“ care-worker/
โ”‚   โ”‚   โ”‚   โ””โ”€โ”€ page.tsx                # Care worker portal with geofencing
โ”‚   โ”‚   โ”œโ”€โ”€ ๐Ÿ“ dashboard/
โ”‚   โ”‚   โ”‚   โ””โ”€โ”€ page.tsx                # Analytics dashboard
โ”‚   โ”‚   โ”œโ”€โ”€ ๐Ÿ“ manager/
โ”‚   โ”‚   โ”‚   โ””โ”€โ”€ page.tsx                # Manager dashboard with overlay
โ”‚   โ”‚   โ””โ”€โ”€ ๐Ÿ“ tutorial/
โ”‚   โ”‚       โ””โ”€โ”€ page.tsx                # Comprehensive tutorial system
โ”‚   โ”œโ”€โ”€ ๐Ÿ“ components/                  # React components
โ”‚   โ”‚   โ”œโ”€โ”€ ๐Ÿ“ ui/                      # shadcn/ui components
โ”‚   โ”‚   โ”‚   โ”œโ”€โ”€ button.tsx
โ”‚   โ”‚   โ”‚   โ”œโ”€โ”€ card.tsx
โ”‚   โ”‚   โ”‚   โ”œโ”€โ”€ input.tsx
โ”‚   โ”‚   โ”‚   โ”œโ”€โ”€ table.tsx
โ”‚   โ”‚   โ”‚   โ”œโ”€โ”€ badge.tsx
โ”‚   โ”‚   โ”‚   โ”œโ”€โ”€ label.tsx
โ”‚   โ”‚   โ”‚   โ””โ”€โ”€ alert.tsx
โ”‚   โ”‚   โ”œโ”€โ”€ ClockInOut.tsx              # Clock in/out interface
โ”‚   โ”‚   โ”œโ”€โ”€ StatsCharts.tsx             # Chart.js visualizations
โ”‚   โ”‚   โ”œโ”€โ”€ Providers.tsx               # Context providers wrapper
โ”‚   โ”‚   โ”œโ”€โ”€ GeofencingManager.tsx       # Location tracking component
โ”‚   โ”‚   โ””โ”€โ”€ PWAInstallPrompt.tsx        # PWA installation prompt
โ”‚   โ”œโ”€โ”€ ๐Ÿ“ contexts/                    # React Context providers
โ”‚   โ”‚   โ”œโ”€โ”€ AppContext.tsx              # Global application state
โ”‚   โ”‚   โ””โ”€โ”€ ToastContext.tsx            # Toast notification system
โ”‚   โ”œโ”€โ”€ ๐Ÿ“ hooks/                       # Custom React hooks
โ”‚   โ”‚   โ””โ”€โ”€ useGeofencing.ts            # Geofencing functionality hook
โ”‚   โ”œโ”€โ”€ ๐Ÿ“ lib/                         # Core utilities and configurations
โ”‚   โ”‚   โ”œโ”€โ”€ ๐Ÿ“ graphql/                 # GraphQL implementation
โ”‚   โ”‚   โ”‚   โ”œโ”€โ”€ typeDefs.ts             # GraphQL schema definitions
โ”‚   โ”‚   โ”‚   โ”œโ”€โ”€ resolvers.ts            # GraphQL resolvers with business logic
โ”‚   โ”‚   โ”‚   โ”œโ”€โ”€ queries.ts              # Client-side GraphQL queries
โ”‚   โ”‚   โ”‚   โ””โ”€โ”€ mutations.ts            # Client-side GraphQL mutations
โ”‚   โ”‚   โ”œโ”€โ”€ apollo-client.ts            # Apollo Client configuration
โ”‚   โ”‚   โ”œโ”€โ”€ auth0.ts                    # Auth0 configuration
โ”‚   โ”‚   โ”œโ”€โ”€ prisma.ts                   # Prisma client configuration
โ”‚   โ”‚   โ”œโ”€โ”€ utils.ts                    # Utility functions
โ”‚   โ”‚   โ”œโ”€โ”€ locationService.ts          # Advanced location management
โ”‚   โ”‚   โ””โ”€โ”€ sw-utils.ts                 # Service worker utilities
โ”‚   โ””โ”€โ”€ ๐Ÿ“ middleware.ts                # Next.js middleware for auth
โ”œโ”€โ”€ ๐Ÿ“„ next.config.js                   # Next.js + PWA configuration
โ”œโ”€โ”€ ๐Ÿ“„ tailwind.config.js               # Tailwind CSS configuration
โ”œโ”€โ”€ ๐Ÿ“„ package.json                     # Dependencies and scripts
โ”œโ”€โ”€ ๐Ÿ“„ tsconfig.json                    # TypeScript configuration
โ”œโ”€โ”€ ๐Ÿ“„ .env.local                       # Environment variables
โ”œโ”€โ”€ ๐Ÿ“„ .gitignore                       # Git ignore rules
โ”œโ”€โ”€ ๐Ÿ“„ CLAUDE.md                        # Development documentation
โ””โ”€โ”€ ๐Ÿ“„ README.md                        # This comprehensive documentation

๐Ÿ› ๏ธ Technology Stack Deep Dive

Frontend Technologies

Technology Version Purpose Why Chosen
Next.js 15.4.6 React Framework App Router, Server Components, PWA support
TypeScript 5.0+ Type Safety Prevent runtime errors, better DX
Tailwind CSS 3.4+ Styling Rapid development, consistent design
shadcn/ui Latest UI Components Modern, accessible, customizable
Lucide React Latest Icons Beautiful, consistent icon system

Backend & Database

Technology Version Purpose Why Chosen
GraphQL 16.8+ API Layer Type-safe queries, real-time updates
Apollo Server 4.0+ GraphQL Server Excellent Next.js integration
Prisma ORM 6.13+ Database Layer Type-safe database access, migrations
PostgreSQL 14+ Primary Database Reliable, scalable, JSON support
Auth0 Latest Authentication Enterprise-grade security

PWA & Mobile

Technology Version Purpose Why Chosen
next-pwa 5.6+ PWA Configuration Automatic service worker generation
Workbox Latest Service Worker Advanced caching strategies
Web Push API Native Notifications Real-time user engagement
Geolocation API Native Location Services Accurate GPS tracking

Data Visualization

Technology Version Purpose Why Chosen
Chart.js 4.4+ Data Visualization Canvas-based, performant charts
react-chartjs-2 5.2+ React Integration Seamless React Chart.js wrapper

๐Ÿš€ Advanced Setup & Configuration

Prerequisites

  • Node.js 18.17+ (LTS recommended)
  • PostgreSQL 14+ (or compatible cloud database)
  • Auth0 Account (free tier available)
  • Modern Browser with PWA support

Environment Configuration

Create a comprehensive .env.local file:

# ==============================================
# Auth0 Configuration (v4.9.0 compatible)
# ==============================================
AUTH0_SECRET="your-32-byte-hex-secret-here"
AUTH0_BASE_URL="http://localhost:3000"
AUTH0_ISSUER_BASE_URL="https://your-domain.auth0.com"
AUTH0_CLIENT_ID="your-auth0-client-id"
AUTH0_CLIENT_SECRET="your-auth0-client-secret"
APP_BASE_URL="http://localhost:3000"

# ==============================================
# Database Configuration
# ==============================================
# PostgreSQL (recommended for production)
DATABASE_URL="postgresql://username:password@localhost:5432/healthshift_db"

# Alternative: Supabase (cloud PostgreSQL)
# DATABASE_URL="postgresql://postgres:[password]@db.[project].supabase.co:5432/postgres"

# Alternative: Railway (cloud PostgreSQL)
# DATABASE_URL="postgresql://postgres:[password]@[host]:5432/railway"

# ==============================================
# Next.js Configuration
# ==============================================
NEXTAUTH_URL="http://localhost:3000"
NEXTAUTH_SECRET="your-32-byte-hex-secret-here"

# ==============================================
# PWA & Push Notifications (Optional)
# ==============================================
NEXT_PUBLIC_VAPID_PUBLIC_KEY="your-vapid-public-key"
VAPID_PRIVATE_KEY="your-vapid-private-key"

# ==============================================
# Analytics & Monitoring (Optional)
# ==============================================
NEXT_PUBLIC_GA_ID="GA-XXXXXXXXX"
SENTRY_DSN="https://xxx@sentry.io/xxx"

Detailed Installation Steps

1. Project Setup

# Clone the repository
git clone https://github.com/your-username/healthcare-shift-tracker.git
cd healthcare-shift-tracker

# Install dependencies with exact versions
npm ci

# Generate Prisma client
npx prisma generate

2. Database Setup

# Initialize database (first time only)
npx prisma db push

# Optional: Seed with sample data
npx prisma db seed

# Open Prisma Studio for database management
npx prisma studio

3. Auth0 Configuration

  1. Create Auth0 Application:

    • Type: Regular Web Application
    • Technology: Next.js
  2. Configure URLs:

    Allowed Callback URLs: http://localhost:3000/api/auth/callback
    Allowed Logout URLs: http://localhost:3000
    Allowed Web Origins: http://localhost:3000
    
  3. Social Connections (Optional):

    • Enable Google OAuth
    • Configure social login settings

4. Development Server

# Start development server with Turbopack
npm run dev

# Alternative: Standard Next.js dev server
npm run dev:standard

# Build for production testing
npm run build
npm run start

Production Deployment

Vercel Deployment (Recommended)

# Install Vercel CLI
npm i -g vercel

# Deploy to Vercel
vercel --prod

# Configure environment variables in Vercel dashboard

Docker Deployment

FROM node:18-alpine
WORKDIR /app
COPY package*.json ./
RUN npm ci --only=production
COPY . .
RUN npm run build
EXPOSE 3000
CMD ["npm", "start"]

๐Ÿ“ฑ PWA Installation & Features

Installation Instructions

Mobile Devices

  1. iOS (Safari):

    • Visit the app in Safari
    • Tap the share button (box with arrow)
    • Select "Add to Home Screen"
    • Confirm installation
  2. Android (Chrome/Firefox):

    • Visit the app in your browser
    • Look for the "Install" prompt
    • Tap "Install" or use browser menu
    • App will appear on home screen

Desktop Installation

  1. Chrome/Edge:

    • Visit the app
    • Look for install icon in address bar
    • Click install and confirm
  2. Manual Installation:

    • Chrome menu โ†’ "Install HealthShift..."
    • App will appear in applications folder

PWA Features

  • โœ… Offline Functionality: Core features work without internet
  • โœ… Background Sync: Data syncs when connection restored
  • โœ… Push Notifications: Real-time alerts and reminders
  • โœ… App Shortcuts: Quick access to key features
  • โœ… Native App Feel: Full-screen experience
  • โœ… Auto-Updates: Latest version automatically downloaded

๐Ÿ” Security & Privacy

Security Measures

  • Authentication: Auth0 enterprise-grade security
  • Authorization: Role-based access control (RBAC)
  • Data Encryption: TLS 1.3 for data in transit
  • Input Validation: GraphQL schema validation + Prisma types
  • CSRF Protection: Next.js built-in CSRF protection
  • SQL Injection Prevention: Prisma ORM prevents SQL injection

Privacy Features

  • Location Data: Only collected during active shifts
  • Data Retention: Configurable data retention policies
  • User Consent: Explicit permission for location services
  • Data Export: Users can export their personal data
  • GDPR Compliance: Built-in privacy controls

๐Ÿ“Š Analytics & Reporting

Manager Dashboard Metrics

  • ๐Ÿ“ˆ Real-Time Active Shifts: Live workforce monitoring
  • โฑ๏ธ Average Daily Hours: Team productivity metrics
  • ๐Ÿ“… Daily Clock-In Trends: Staffing pattern analysis
  • ๐Ÿ‘ฅ Weekly Staff Hours: Individual performance tracking
  • ๐Ÿฉ Hour Distribution: Full-time vs part-time analysis
  • ๐Ÿ“‹ Comprehensive Shift History: Complete audit trail

Care Worker Analytics

  • โฐ Personal Shift History: Individual performance tracking
  • ๐Ÿ“Š Monthly Hours Summary: Personal productivity insights
  • ๐ŸŽฏ Average Shift Duration: Consistency metrics
  • ๐Ÿ“ Location Analytics: Work pattern insights

๐ŸŽฏ Business Impact & ROI

For Healthcare Organizations

  • ๐Ÿ’ฐ Cost Savings: Eliminate time theft and buddy punching
  • ๐Ÿ“‹ Compliance: Automated reporting for regulatory requirements
  • ๐Ÿ“ˆ Productivity: Data-driven workforce optimization
  • โšก Efficiency: Streamlined shift management processes
  • ๐Ÿ” Visibility: Real-time workforce insights

For Care Workers

  • ๐Ÿ“ฑ Convenience: Mobile-first design for easy use
  • ๐Ÿ”’ Transparency: Clear shift history and performance data
  • โšก Speed: One-tap clock in/out functionality
  • ๐ŸŽฏ Accuracy: GPS verification prevents disputes

For Managers

  • ๐Ÿ“Š Insights: Comprehensive workforce analytics
  • โฐ Real-Time: Instant visibility into staffing levels
  • ๐Ÿ“ˆ Optimization: Data-driven scheduling decisions
  • ๐Ÿ“‹ Reporting: Automated compliance reports

๐Ÿงช Testing & Quality Assurance

Automated Testing

  • Unit Tests: Core business logic testing
  • Integration Tests: API and database testing
  • E2E Tests: Complete user workflow testing
  • PWA Tests: Service worker and offline functionality

Manual Testing Checklist

  • โœ… Authentication flows (login/logout)
  • โœ… Location-based clock in/out
  • โœ… Manager dashboard functionality
  • โœ… PWA installation and offline mode
  • โœ… Cross-device compatibility
  • โœ… Performance optimization

๐Ÿš€ Performance Optimizations

Frontend Performance

  • Code Splitting: Automatic route-based splitting
  • Image Optimization: Next.js automatic image optimization
  • Lazy Loading: Components loaded on demand
  • Caching: Aggressive caching strategies
  • Bundle Analysis: Optimized bundle sizes

Backend Performance

  • Database Indexing: Optimized queries with proper indexes
  • Connection Pooling: Efficient database connections
  • GraphQL Optimization: Query optimization and caching
  • CDN Integration: Static asset delivery optimization

๐Ÿ”ฎ Future Enhancements & Roadmap

Phase 2: Advanced Features

  • ๐Ÿ”” Smart Notifications: AI-powered shift reminders
  • ๐Ÿ“… Shift Scheduling: Advanced scheduling system
  • ๐Ÿ“Š Predictive Analytics: Machine learning insights
  • ๐Ÿฅ Multi-Facility Support: Enterprise-scale deployment
  • ๐Ÿ’ฌ Communication Hub: In-app messaging system

Phase 3: Enterprise Features

  • ๐Ÿ“ˆ Advanced Reporting: Custom report builder
  • ๐Ÿ”„ API Integration: Third-party system integration
  • ๐Ÿ‘ฅ Team Management: Advanced user management
  • ๐ŸŽฏ Performance Metrics: KPI tracking and goals
  • ๐Ÿ” SSO Integration: Enterprise authentication

๐Ÿ“š Documentation & Support

Developer Resources

  • ๐Ÿ“– API Documentation: Complete GraphQL schema reference
  • ๐ŸŽฅ Video Tutorials: Step-by-step implementation guides
  • ๐Ÿ’ก Best Practices: Code quality and security guidelines
  • ๐Ÿ”ง Troubleshooting: Common issues and solutions

User Guides

  • ๐Ÿ‘ฉโ€โš•๏ธ Care Worker Guide: Complete user manual
  • ๐Ÿ‘จโ€๐Ÿ’ผ Manager Guide: Administrative features walkthrough
  • ๐Ÿ“ฑ Mobile Guide: PWA installation and usage
  • โ“ FAQ: Frequently asked questions

๐Ÿค Contributing & Development

Development Workflow

  1. Fork the repository
  2. Create feature branch (git checkout -b feature/amazing-feature)
  3. Commit changes (git commit -m 'Add amazing feature')
  4. Push to branch (git push origin feature/amazing-feature)
  5. Create Pull Request

Code Standards

  • ESLint: Consistent code style
  • Prettier: Automatic code formatting
  • TypeScript: Strict type checking
  • Conventional Commits: Standardized commit messages

๐Ÿ“„ License & Legal

This project is developed as a comprehensive solution for healthcare workforce management, implementing industry best practices for security, performance, and user experience.

Built with โค๏ธ for healthcare organizations and workers worldwide


๐Ÿ“ž Support & Contact

For technical support, feature requests, or general inquiries:


HealthShift - Revolutionizing Healthcare Workforce Management

Live Demo Tutorial

About

An application for healthcare workers to clock in and clock out of their shifts.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Contributors 2

  •  
  •