A comprehensive, modern healthcare management platform built with Next.js 15, designed to streamline hospital operations, patient care, and administrative workflows. This system provides role-based access control for multiple user types including administrators, doctors, nurses, patients, lab technicians, and cashiers.
- Admin Dashboard: Complete system oversight, user management, analytics, and configuration
- Doctor Portal: Patient management, appointment scheduling, medical records, diagnosis, and prescriptions
- Patient Portal: Appointment booking, medical history access, doctor ratings, and profile management
- Nurse Interface: Patient care coordination, vital signs recording, and medical record updates
- Lab Technician: Lab test management, results entry, and service tracking
- Cashier: Billing, payment processing, and financial record management
- Appointment Management: Schedule, reschedule, cancel, and track appointments with real-time status updates
- Patient Records: Comprehensive medical history, allergies, conditions, insurance information, and emergency contacts
- Doctor Profiles: Specializations, availability schedules, ratings, reviews, and working hours
- Medical Records: Diagnosis, prescriptions, lab requests, treatment plans, and vital signs tracking
- Billing & Payments: Invoice generation, payment processing (cash/card), receipt management, and financial reporting
- Analytics Dashboard: Visual charts and statistics for appointments, revenue, patient demographics, and system usage
- Rating System: Patient feedback and doctor performance ratings
- Audit Logging: Track all system actions for compliance and security
- Framework: Next.js 16.1.1 with App Router
- UI Library: React 19
- Styling: Tailwind CSS 4 with custom animations
- UI Components: Radix UI primitives with shadcn/ui styling
- Icons: Lucide React
- Charts: Recharts for data visualization
- Forms: React Hook Form with Zod validation
- Notifications: Sonner toast notifications
- Database: PostgreSQL
- ORM: Prisma 6.4.1
- Authentication: Clerk with role-based access control
- Date Handling: date-fns
- Package Manager: npm
- Linting: ESLint (Next.js configuration)
- Database Seeding: Faker.js for test data generation
Before you begin, ensure you have the following installed:
- Node.js: Version 18.17 or higher
- npm: Version 9 or higher
- PostgreSQL: Version 14 or higher
- Git: For version control
git clone <repository-url>
cd DOC_INTELnpm installCreate a .env file in the root directory with the following variables:
# Database Configuration
DATABASE_URL="postgresql://username:password@localhost:5432/healthcare_db?schema=public"
# Clerk Authentication
NEXT_PUBLIC_CLERK_PUBLISHABLE_KEY=your_clerk_publishable_key
CLERK_SECRET_KEY=your_clerk_secret_key
# Clerk URLs (adjust based on your domain)
NEXT_PUBLIC_CLERK_SIGN_IN_URL=/sign-in
NEXT_PUBLIC_CLERK_SIGN_UP_URL=/sign-up
NEXT_PUBLIC_CLERK_AFTER_SIGN_IN_URL=/
NEXT_PUBLIC_CLERK_AFTER_SIGN_UP_URL=/
# Application URL (for production)
NEXT_PUBLIC_APP_URL=http://localhost:3000Important Notes:
- Replace
username,password, and database name inDATABASE_URLwith your PostgreSQL credentials - Get Clerk API keys from Clerk Dashboard
- Configure Clerk metadata to include user roles (admin, doctor, patient, nurse, lab_technician, cashier)
# Login to PostgreSQL
psql -U postgres
# Create database
CREATE DATABASE healthcare_db;
# Exit PostgreSQL
\q# Generate Prisma Client
npx prisma generate
# Run database migrations
npx prisma migrate dev --name init
# (Optional) Seed database with sample data
npx prisma db seedIn your Clerk Dashboard:
- Navigate to Users & Authentication β Metadata
- Add custom metadata field:
role - Assign roles to users:
admin,doctor,patient,nurse,lab_technician, orcashier
Example metadata structure:
{
"role": "admin"
}npm run devOpen http://localhost:3000 in your browser.
npm run buildnpm run startnpm run lintThis project is optimized for deployment on Vercel.
- Create a Vercel account
- Install Vercel CLI (optional):
npm i -g vercel - Set up a PostgreSQL database (recommended: Vercel Postgres or Supabase)
Option 1: Deploy via Vercel Dashboard (Recommended)
- Push your code to GitHub/GitLab/Bitbucket
- Go to Vercel Dashboard
- Import your repository
- Configure environment variables (see below)
- Deploy!
Option 2: Deploy via Vercel CLI
# Login to Vercel
vercel login
# Deploy
vercel
# Deploy to production
vercel --prodAdd these environment variables in your Vercel project settings:
# Database (use your production PostgreSQL URL)
DATABASE_URL=postgresql://user:password@host:port/database?schema=public
# Clerk Authentication
NEXT_PUBLIC_CLERK_PUBLISHABLE_KEY=pk_live_xxxxx
CLERK_SECRET_KEY=sk_live_xxxxx
NEXT_PUBLIC_CLERK_SIGN_IN_URL=/sign-in
NEXT_PUBLIC_CLERK_SIGN_UP_URL=/sign-up
NEXT_PUBLIC_CLERK_AFTER_SIGN_IN_URL=/
NEXT_PUBLIC_CLERK_AFTER_SIGN_UP_URL=/
# Application URL (your Vercel domain)
NEXT_PUBLIC_APP_URL=https://your-app.vercel.appAfter deployment, run Prisma migrations on your production database:
# Using Vercel CLI
vercel env pull .env.production
npx prisma migrate deploy
# Or connect directly to your production database
DATABASE_URL="your-production-url" npx prisma migrate deployThis Next.js app can also be deployed to:
- Railway: Railway Deployment Guide
- Render: Render Deployment Guide
- AWS Amplify: AWS Amplify Guide
- DigitalOcean App Platform: DigitalOcean Guide
DOC_INTEL/
βββ app/ # Next.js App Router
β βββ (auth)/ # Authentication routes (sign-in, sign-up)
β βββ (protected)/ # Protected routes (role-based access)
β β βββ admin/ # Admin dashboard and management
β β βββ doctor/ # Doctor portal
β β βββ patient/ # Patient portal
β β βββ staff/ # Staff (nurse, lab tech, cashier) portal
β β βββ record/ # Medical records and user management
β βββ actions/ # Server actions
β βββ globals.css # Global styles
β βββ layout.js # Root layout
β βββ page.js # Home page
βββ components/ # React components
β βββ appointment/ # Appointment-related components
β βββ charts/ # Chart components (Recharts)
β βββ dialogs/ # Modal dialogs
β βββ forms/ # Form components
β βββ settings/ # Settings components
β βββ tables/ # Data table components
β βββ ui/ # shadcn/ui components
βββ lib/ # Utility libraries
β βββ db.js # Prisma client instance
β βββ routes.js # Route access control configuration
β βββ schema.js # Zod validation schemas
β βββ utils.js # Utility functions
βββ prisma/ # Prisma ORM
β βββ migrations/ # Database migrations
β βββ schema.prisma # Database schema
β βββ seed.js # Database seeding script
βββ public/ # Static assets
βββ utils/ # Additional utilities
β βββ roles.js # Role definitions and helpers
β βββ services/ # Service layer functions
β βββ settings.js # Application settings
βββ middleware.js # Clerk authentication middleware
βββ next.config.mjs # Next.js configuration
βββ package.json # Dependencies and scripts
This application uses Clerk for authentication and user management:
- Sign-up/Sign-in: Pre-built authentication UI
- Session Management: Secure session handling
- User Metadata: Custom role assignment via metadata
- Protected Routes: Middleware-based route protection
The system implements granular access control through middleware (middleware.js) and route configuration (lib/routes.js):
| Role | Access Level | Permissions |
|---|---|---|
| Admin | Full System Access | User management, system configuration, all records, analytics |
| Doctor | Medical Staff | Patient records, appointments, diagnosis, prescriptions, staff records |
| Patient | Personal Access | Own appointments, medical history, doctor ratings, profile |
| Nurse | Care Coordination | Patient records, vital signs, medical updates, appointments |
| Lab Technician | Laboratory | Lab tests, results entry, service management |
| Cashier | Financial | Billing, payments, invoices, financial records |
Routes are automatically protected based on user roles. Unauthorized access attempts redirect users to their role-specific dashboard.
- Patient: Personal info, medical history, allergies, insurance, emergency contacts
- Doctor: Credentials, specialization, availability, working hours, ratings
- Staff: Nurses, lab technicians, cashiers with role-based attributes
- Appointment: Scheduling, status tracking, patient-doctor relationships
- MedicalRecords: Diagnosis, prescriptions, lab requests, treatment plans
- VitalSigns: Body temperature, blood pressure, heart rate, oxygen saturation
- Diagnosis: Symptoms, diagnosis details, medications, follow-up plans
- Payment: Billing, payment methods, receipts, financial tracking
- Rating: Patient feedback and doctor performance reviews
- Services: Medical services catalog with pricing
- LabTest: Laboratory test management and results
- AuditLog: System activity tracking for compliance
- Role: ADMIN, DOCTOR, PATIENT, NURSE, LAB_TECHNICIAN, CASHIER
- AppointmentStatus: PENDING, SCHEDULED, CANCELLED, COMPLETED
- PaymentStatus: PAID, UNPAID, PART
- Gender: MALE, FEMALE
- Status: ACTIVE, INACTIVE, DORMANT
- Real-time availability checking
- Conflict prevention
- Status workflow (Pending β Scheduled β Completed/Cancelled)
- Email/SMS notifications (via Clerk)
- HIPAA-compliant data storage
- Comprehensive patient history
- Vital signs tracking
- Lab test integration
- Prescription management
- Appointment trends
- Revenue analytics
- Patient demographics
- Doctor performance metrics
- System usage statistics
We welcome contributions! Please follow these guidelines:
- Fork the repository
- Create a feature branch:
git checkout -b feature/your-feature-name - Commit changes:
git commit -m 'Add some feature' - Push to branch:
git push origin feature/your-feature-name - Open a Pull Request
- Follow existing code style and conventions
- Write meaningful commit messages
- Add comments for complex logic
- Update documentation as needed
- Test thoroughly before submitting
This application implements several security measures:
- Authentication: Clerk provides secure, production-ready authentication
- Role-Based Access Control: Middleware-level route protection
- Environment Variables: Sensitive data stored in environment variables
- HTTPS: Always use HTTPS in production
- Database Security: PostgreSQL with SSL connections in production
Important: Always keep dependencies up to date to patch security vulnerabilities.
# Check for outdated packages
npm outdated
# Update all packages to latest versions
npm update
# Update Next.js specifically (recommended)
npm install next@latest react@latest react-dom@latest- Next.js 16.1.1: Addresses CVE-2025-66478 (Critical RCE vulnerability)
- React 19: Latest stable version with security patches
Never commit .env files to version control!
- β
Use
.env.localfor local development (gitignored by default) - β Use Vercel Environment Variables for production
- β Rotate API keys regularly
- β Use different keys for development and production
- β Never expose
CLERK_SECRET_KEYorDATABASE_URLpublicly
This project is private and proprietary. All rights reserved.
Next.js Configuration Warnings
If you see warnings about deprecated configuration options:
# Warning: experimental.serverComponentsExternalPackages is deprecated
# Solution: Already fixed in next.config.mjs using serverExternalPackages
# Warning: swcMinify is deprecated
# Solution: Already removed (enabled by default in Next.js 15+)Security Vulnerability: CVE-2025-66478
Critical RCE vulnerability in Next.js 15.x. Solution: Update to Next.js 16.1.1+
npm install next@latest react@latest react-dom@latestVercel Build Failing: "Cannot find module '@prisma/client'"
This is fixed by the postinstall script in package.json. If you still encounter this:
# Ensure postinstall script exists in package.json
"postinstall": "prisma generate"
# Verify Prisma is in dependencies (not devDependencies)
# Check that DATABASE_URL is set in Vercel environment variablesDatabase Connection Error
# Verify PostgreSQL is running (local development)
sudo service postgresql status
# Check DATABASE_URL in .env file
# Ensure credentials and database name are correct
# For Vercel: Verify DATABASE_URL is set in environment variables
# Make sure the database allows connections from Vercel IPsPrisma Client Not Generated
# Generate Prisma Client manually
npx prisma generate
# If using Vercel, this runs automatically via postinstall scriptClerk Authentication Issues
- Verify API keys in
.env(development) or Vercel environment variables (production) - Check Clerk Dashboard for application status
- Ensure user metadata includes
rolefield - For production, use
pk_live_andsk_live_keys (notpk_test_)
Build Errors
# Clear Next.js cache
rm -rf .next
# Reinstall dependencies
rm -rf node_modules package-lock.json
npm install
# Regenerate Prisma Client
npx prisma generateVercel Deployment: Database Migration Issues
# After first deployment, run migrations on production database
DATABASE_URL="your-production-url" npx prisma migrate deploy
# Or use Vercel CLI
vercel env pull .env.production
npx prisma migrate deployTypeScript Errors (if using TypeScript in future)
# Regenerate Prisma types
npx prisma generate
# Check for type errors
npm run buildFor issues, questions, or contributions, please open an issue in the repository.
Built with β€οΈ using Next.js 15 and modern web technologies