A comprehensive telemedicine platform built with Next.js, enabling seamless virtual healthcare consultations with integrated video calling, appointment booking, prescription management, and M-Pesa payment processing.
- Secure Authentication - Sign up and sign in with Clerk authentication
- Doctor Discovery - Browse and select from available doctors by specialty
- Appointment Booking - Schedule consultations with preferred doctors
- M-Pesa Integration - Pay for appointments via STK Push
- Video Consultations - High-quality video calls powered by Stream Video SDK
- Prescription Management - Receive and view digital prescriptions
- Appointment History - Track upcoming and previous appointments
- WhatsApp Notifications - Get meeting links via WhatsApp
- Personal Dashboard - Manage appointments and schedules
- Doctor Notes Panel - Document patient consultations in real-time
- Prescription Creation - Write and send digital prescriptions during calls
- Patient History - Access previous appointment records
- Doctor Management - Add, edit, and remove doctor profiles
- Appointment Oversight - View and manage all appointments
- Financial Dashboard - Track payments and revenue
- Analytics - Monitor platform usage and performance
- Framework: Next.js 15 with App Router
- Language: TypeScript
- Styling: Tailwind CSS
- Authentication: Clerk
- Video SDK: Stream Video React SDK
- Database: Firebase Firestore
- Payment: M-Pesa API (Safaricom)
- Notifications: Twilio (WhatsApp Business API)
- UI Components: Radix UI, Lucide Icons
- PDF Generation: jsPDF
- Animation: Framer Motion
Before you begin, ensure you have the following:
- Node.js 20.x or higher
- npm or yarn package manager
- Firebase Account - Create one here
- Clerk Account - Sign up here
- Stream Account - Get API key here
- M-Pesa Developer Account (Optional for testing) - Safaricom Developer Portal
- Twilio Account (Optional) - For WhatsApp notifications
git clone https://github.com/Math3wsl3vi/telemedical-app.git
cd telemedical-appnpm install
# or
yarn installCreate a .env.local file in the root directory:
# Clerk Authentication
NEXT_PUBLIC_CLERK_PUBLISHABLE_KEY=your_clerk_publishable_key
CLERK_SECRET_KEY=your_clerk_secret_key
# Stream Video SDK
NEXT_PUBLIC_STREAM_API_KEY=your_stream_api_key
STREAM_SECRET_KEY=your_stream_secret_key
# Firebase Configuration
NEXT_PUBLIC_FIREBASE_API_KEY=your_firebase_api_key
NEXT_PUBLIC_FIREBASE_AUTH_DOMAIN=your_project.firebaseapp.com
NEXT_PUBLIC_FIREBASE_PROJECT_ID=your_project_id
NEXT_PUBLIC_FIREBASE_STORAGE_BUCKET=your_project.appspot.com
NEXT_PUBLIC_FIREBASE_MESSAGING_SENDER_ID=your_sender_id
NEXT_PUBLIC_FIREBASE_APP_ID=your_app_id
# M-Pesa Configuration (For Production)
NEXT_PUBLIC_MPESA_CONSUMER_KEY=your_mpesa_consumer_key
NEXT_PUBLIC_MPESA_CONSUMER_SECRET=your_mpesa_consumer_secret
NEXT_PUBLIC_MPESA_SHORTCODE=your_business_shortcode
NEXT_PUBLIC_MPESA_PASSKEY=your_passkey
NEXT_PUBLIC_MPESA_BASE_URL=https://sandbox.safaricom.co.ke
# Payment Mode (Demo/Production)
NEXT_PUBLIC_MOCK_PAYMENT=true # Set to false for real M-Pesa payments
# Application Base URL
NEXT_PUBLIC_BASE_URL=http://localhost:3000
# WhatsApp Business API (Optional)
WHATSAPP_API_KEY=your_whatsapp_api_key
WHATSAPP_PHONE_ID=your_phone_idπ Note: See ENV_CONFIGURATION.md for detailed environment variable documentation.
- Create a new Firebase project
- Enable Firestore Database
- Create the following collections:
appointmentsdoctorsprescriptions
- Set up Firebase security rules (see FIREBASE_SETUP.md)
npm run dev
# or
yarn devOpen http://localhost:3000 in your browser.
For development and testing without real M-Pesa payments:
- Set
NEXT_PUBLIC_MOCK_PAYMENT=truein.env.local - The app will simulate successful payments after 3 seconds
- Appointments will be saved to Firestore with
paymentStatus: 'pending'
See DEMO_MODE_SETUP.md for more details.
telemedical-app/
βββ app/
β βββ (auth)/ # Authentication pages
β β βββ sign-in/
β β βββ sign-up/
β βββ (root)/ # Main application
β β βββ (home)/ # Patient-facing pages
β β β βββ doctor/ # Doctor profiles
β β β βββ medicationConfirm/
β β β βββ paymentConfirm/
β β β βββ personal-room/
β β βββ admin/ # Admin dashboard
β β βββ meeting/ # Video call pages
β βββ api/ # API routes
β βββ mpesa/ # M-Pesa integration
β βββ prescriptions/ # Prescription handling
β βββ send-whatsapp/ # WhatsApp notifications
βββ components/
β βββ admin/ # Admin components
β βββ ui/ # Reusable UI components
βββ lib/
β βββ appointments.ts # Appointment management
β βββ firebase.ts # Firebase configuration
β βββ mpesa.ts # M-Pesa integration
β βββ utils.ts # Utility functions
βββ hooks/ # Custom React hooks
βββ actions/ # Server actions
βββ providers/ # Context providers
βββ constants/ # App constants
The app uses Clerk for authentication with the following features:
- Email/Password authentication
- Social login support (configurable)
- Protected routes via middleware
- Role-based access control (Patient, Doctor, Admin)
- Patient selects a doctor and appointment time
- Enters M-Pesa phone number
- Receives STK push prompt on phone
- Enters M-Pesa PIN
- Payment confirmation
- Appointment saved to Firestore
- Meeting link generated
- Real-time payment verification
- Automatic retry mechanism
- 2-minute timeout with graceful fallback
- Rate limiting to respect API limits (5 requests/minute)
Powered by Stream Video React SDK:
- HD video quality
- Screen sharing
- Real-time chat
- Recording capabilities
- Virtual backgrounds
- Device settings control
{
patientId: string;
patientName: string;
patientEmail: string;
doctorId: string;
doctorName: string;
doctorSpecialty: string;
appointmentDate: Timestamp;
meetingId: string;
meetingLink: string;
description: string;
paymentStatus: 'pending' | 'completed' | 'failed';
status: 'scheduled' | 'completed' | 'cancelled';
createdAt: Timestamp;
phoneNumber?: string;
amount?: number;
}{
id: string;
name: string;
specialty: string;
image: string;
rating: number;
experience: string;
availability: string[];
consultationFee: number;
}# Development
npm run dev # Start development server
# Production
npm run build # Build for production
npm run start # Start production server
# Code Quality
npm run lint # Run ESLintThe app is fully responsive and works seamlessly across:
- π± Mobile devices (iOS & Android)
- π» Tablets
- π₯οΈ Desktop browsers
- Push your code to GitHub
- Import project to Vercel
- Configure environment variables in Vercel dashboard
- Deploy
Ensure all environment variables are set in your deployment platform:
- Set
NEXT_PUBLIC_MOCK_PAYMENT=falsefor real payments - Update
NEXT_PUBLIC_BASE_URLto your production URL - Use production M-Pesa credentials
If you encounter M-Pesa authentication issues, see MPESA_ERROR_2001_SOLUTION.md.
- Payment timeout: Check M-Pesa credentials and network connectivity
- Firebase permissions: Verify Firestore security rules
- Video call not starting: Ensure Stream API key is correct
- Authentication errors: Check Clerk configuration
- Complete Implementation Summary
- Environment Configuration Guide
- Firebase Setup Instructions
- Demo Mode Setup
- Quick Reference Guide
Contributions are welcome! Please follow these steps:
- Fork the repository
- Create a feature branch (
git checkout -b feature/AmazingFeature) - Commit your changes (
git commit -m 'Add some AmazingFeature') - Push to the branch (
git push origin feature/AmazingFeature) - Open a Pull Request
This project is licensed under the MIT License - see the LICENSE file for details.
Math3wsl3vi
- GitHub: @Math3wsl3vi
- Next.js for the amazing framework
- Stream for video SDK
- Clerk for authentication
- Firebase for database
- Safaricom for M-Pesa API
- Radix UI for accessible components
- Tailwind CSS for styling
For support, email your-email@example.com or open an issue in the repository.
Built with β€οΈ for better healthcare access