- 🌟 Overview
- ✨ Key Features
- 🏗️ Architecture
- 🔧 Tech Stack
- 📁 Project Structure
- 🚀 Getting Started
- 🔑 Authentication System
- 👥 User Roles & Permissions
- 📊 Core Modules
- 🤖 AI Chatbot Integration
- 📱 API Documentation
- 🎨 UI Components
- 🔧 Utilities & Hooks
- 🚀 Deployment
- 🤝 Contributing
BloodBond is a modern, full-stack blood bank management system designed to streamline blood donation and distribution processes. The platform connects three main stakeholders: Donors, Hospitals, and Blood Banks through an intuitive web interface with real-time notifications, inventory management, and AI-powered assistance.
To create a seamless, efficient, and life-saving blood management ecosystem that reduces the gap between blood availability and medical needs.
- Emergency Blood Requests: Instant blood requests with nearby blood bank notifications
- Request Tracking: Real-time status tracking for all blood requests
- Smart Matching: Automatic blood type compatibility checking with blood compatibility matrix
- Status Updates: Comprehensive request lifecycle management (Pending → Accepted → Fulfilled)
- Hospital Request System: Specialized hospital-to-blood bank request management
- Bulk Request Processing: Handle multiple blood requests efficiently
- JWT-based Authentication: Secure session management with NextAuth.js
- Role-based Access Control: Distinct interfaces for Donors, Hospitals, and Blood Banks
- Protected Routes: Secure access to role-specific functionalities with RoleGuard components
- Session Persistence: Automatic session management and refresh
- Multi-step Registration: Comprehensive registration flow with role-specific profile completion
- Dual Inventory Systems: Separate inventory management for Blood Banks and Hospitals
- Real-time Blood Inventory: Live tracking of blood units by type with expiry monitoring
- Hospital Inventory Management: Independent hospital blood stock control with batch tracking
- Automated Logging: Comprehensive inventory change tracking with audit trails
- Stock Level Indicators: Visual indicators for stock status (Good/Low Stock/Critical)
- Expiry Management: Advanced expiration tracking with automated alerts
- Emergency Requests: Priority handling for urgent blood needs with emergency call interface
- Proximity Search: Location-based blood bank recommendations
- Instant Notifications: Real-time alerts to relevant blood banks
- Guest Access: Emergency requests without mandatory registration
- Emergency Contact Management: Direct communication channels for urgent situations
- Drive Creation: Blood banks can create and manage donation drives
- Registration System: Donors can register for specific drives
- Drive Analytics: Comprehensive statistics and reporting for donation drives
- Automated Notifications: Drive reminders and updates to registered donors
- Multi-location Support: Manage drives across different locations
- Direct Donor Requests: Blood banks can request specific donors for rare blood types
- Donor Contact System: Secure communication between blood banks and donors
- Critical Settings: Donors can set availability for emergency situations
- Response Management: Streamlined donor response tracking and management
- Smart Matching: AI-powered donor-request matching based on location and blood type
- Groq AI Integration: Intelligent assistance for blood-related queries
- Contextual Help: Role-specific guidance and information
- 24/7 Availability: Round-the-clock support for users
- Enhanced Chat Interface: Improved chat UI with message processing and history
- Toast Notifications: Instant feedback for user actions with contextual messaging
- Emergency Alerts: Priority notifications for urgent requests with emergency notification hooks
- Status Updates: Automatic notifications for request status changes
- Inventory Alerts: Low stock and expiry warnings for both blood banks and hospitals
- Cross-platform Sync: Consistent notifications across devices
- Responsive Design: Mobile-first design with seamless desktop experience
- Dark/Light Theme: System-aware theme switching with CSS variables
- Interactive Landing Page: Multi-section home page with feature highlights and statistics
- Role-based Dashboards: Customized dashboards with relevant statistics and quick actions
- Modern UI Components: Clean, accessible interface with Lucide React icons and advanced form components
BloodBond follows a modern JAMstack architecture with enhanced modularity:
┌─────────────────┐ ┌──────────────────┐ ┌─────────────────┐
│ Frontend │ │ API Layer │ │ Database │
│ (Next.js) │◄──►│ (Next.js API) │◄──►│ (MongoDB) │
│ │ │ │ │ │
│ • React 18 │ │ • RESTful APIs │ │ • Blood Banks │
│ • TailwindCSS │ │ • Authentication │ │ • Blood Requests│
│ • Lucide Icons │ │ • Role Guards │ │ • Donations │
│ • Context APIs │ │ • Data Validation│ │ • Inventory │
│ • Custom Hooks │ │ • AI Integration │ │ • Drive Management│
└─────────────────┘ └──────────────────┘ └─────────────────┘
- Framework: Next.js 15.5.2 (App Router)
- UI Library: React 18
- Styling: TailwindCSS with custom CSS variables for theming
- Icons: Lucide React (1,000+ SVG icons)
- State Management: React Context API + Custom Hooks
- Form Management: Advanced form components with validation
- Runtime: Node.js 20+
- Framework: Next.js API Routes
- Database: MongoDB with Mongoose ODM
- Authentication: NextAuth.js with JWT strategy
- Data Processing: Advanced message processing and blood compatibility checking
- AI Chatbot: Groq API for intelligent assistance with enhanced knowledge base
- Authentication: NextAuth.js providers with multi-role support
- Deployment: Vercel platform
- Package Manager: npm
- Linting: ESLint with Next.js configuration
- Build Tool: Next.js with Turbopack (dev mode)
- Environment: .env.local for configuration
bloodbond/
├── 📁 app/ # Next.js App Router directory
│ ├── 📄 layout.js # Root layout with providers
│ ├── 📄 page.js # Enhanced landing page with feature sections
│ ├── 📄 globals.css # Global styles & CSS variables for theming
│ ├── 📄 chatbot.css # Specialized chatbot styling
│ ├── 📄 dark-theme.css # Dark theme specific styles
│ ├── 📁 api/ # Backend API routes
│ │ ├── 📁 auth/ # Enhanced authentication with session management
│ │ ├── 📁 requests/ # Blood request management with tracking
│ │ ├── 📁 inventory/ # Blood bank inventory APIs with logging
│ │ ├── 📁 hospital-inventory/ # Hospital inventory management APIs
│ │ ├── 📁 hospital-requests/ # Hospital-specific request handling
│ │ ├── 📁 emergency/ # Emergency request handling
│ │ ├── 📁 chatbot/ # AI chatbot integration
│ │ ├── 📁 bloodbank/ # Blood bank specific operations
│ │ ├── 📁 donors/ # Donor management and statistics
│ │ ├── 📁 donations/ # Donation tracking and management
│ │ ├── 📁 donation-drives/ # Drive creation and management
│ │ ├── 📁 donor-contact-request/# Donor-blood bank communication
│ │ └── 📁 bloodbank-donor-requests/ # Blood bank to donor requests
│ ├── 📁 dashboard/ # Role-based dashboards with enhanced analytics
│ │ ├── 📁 donor/ # Donor-specific dashboard
│ │ ├── 📁 hospital/ # Hospital dashboard with inventory overview
│ │ └── 📁 bloodbank/ # Blood bank dashboard with drive management
│ ├── 📁 hospital-inventory/ # Hospital inventory management interface
│ ├── 📁 emergency/ # Emergency request interface
│ ├── 📁 emergency-call/ # Emergency call interface
│ ├── 📁 track-request/ # Universal request tracking system
│ ├── 📁 donor-requests/ # Donor request management
│ ├── 📁 hospital-requests/ # Hospital request interface
│ ├── 📁 hospital-request-acceptance/ # Hospital request acceptance
│ ├── 📁 register/ # Multi-role registration system
│ └── 📁 login/ # Authentication pages
├── 📁 components/ # Reusable UI components
│ ├── 📄 navbar.jsx # Enhanced navigation with role-based menus
│ ├── 📄 Login.jsx # Authentication form
│ ├── 📄 Chatbot.jsx # AI chatbot interface
│ ├── 📄 ChatInput.jsx # Enhanced chat input component
│ ├── 📄 ChatMessage.jsx # Message display component
│ ├── 📄 RoleGuard.jsx # Role-based access control
│ ├── 📄 RoleSelection.jsx # Registration role selection
│ ├── 📄 ProtectedRoute.jsx # Route protection wrapper
│ ├── 📄 SessionProvider.jsx # Authentication wrapper
│ ├── 📄 footer.jsx # Site footer
│ └── 📁 forms/ # Specialized form components
├── 📁 context/ # React Context providers
│ ├── 📄 ToastContext.jsx # Enhanced notification system
│ └── 📄 ThemeContext.jsx # Advanced dark/light theme management
├── 📁 hooks/ # Custom React hooks
│ ├── 📄 useUserRole.js # Enhanced role management hook
│ ├── 📄 useEmergencyNotifications.js # Emergency alerts system
│ ├── 📄 useEmergencyRequestCheck.js # Emergency request validation
│ └── 📄 useRequestStatus.js # Advanced request tracking
├── 📁 lib/ # Utility libraries
│ ├── 📄 roleAuth.js # Role-based authorization
│ ├── 📄 groqClient.js # AI chatbot client
│ ├── 📄 knowledgeBase.js # Enhanced chatbot knowledge base
│ ├── 📄 messageProcessor.js # Message processing utilities
│ └── 📄 bloodCompatibility.js # Blood type compatibility matrix
├── 📁 model/ # MongoDB schemas
│ ├── 📄 user.js # Enhanced user model with roles
│ ├── 📄 BloodRequest.js # Blood request schema with status tracking
│ ├── 📄 BloodBank.js # Blood bank information
│ ├── 📄 BloodInventory.js # Blood bank inventory management
│ ├── 📄 HospitalInventory.js # Hospital inventory schema with batch tracking
│ ├── 📄 HospitalInventoryLog.js # Hospital inventory audit trail
│ ├── 📄 HospitalProfile.js # Hospital profile management
│ ├── 📄 HospitalRequest.js # Hospital-specific requests
│ ├── 📄 InventoryLog.js # Blood bank inventory change logs
│ ├── 📄 Donation.js # Donation records
│ ├── 📄 DonationDrive.js # Donation drive management
│ ├── 📄 DriveRegistration.js # Drive registration tracking
│ ├── 📄 Doner.js # Donor profile and statistics
│ └── 📄 DonorContactRequest.js # Donor-blood bank communication
├── 📁 db/ # Database configuration
│ └── 📄 connectDB.mjs # MongoDB connection
└── 📄 next.config.mjs # Next.js configuration
- Node.js 20+ installed
- MongoDB database (local or cloud)
- Groq API key for chatbot functionality
-
Clone the repository
git clone https://github.com/DevSsChar/BloodBond.git cd BloodBond -
Install dependencies
npm install
-
Environment Setup Create
.env.localfile in the root directory:# Database MONGODB_URI=mongodb://localhost:27017/bloodbond # Authentication NEXTAUTH_SECRET=your-nextauth-secret NEXTAUTH_URL=http://localhost:3000 # AI Chatbot GROQ_API_KEY=your-groq-api-key
-
Run the development server
npm run dev
-
Open your browser Navigate to
http://localhost:3000
// Advanced authentication configuration
providers: [
CredentialsProvider({
async authorize(credentials) {
// Custom authentication logic with role validation
// Multi-step registration support
// Enhanced session management
// JWT token generation and validation
}
})
]- JWT Strategy: Stateless authentication with secure tokens
- Role Persistence: User roles stored in JWT payload with session refresh
- Auto Refresh: Automatic session renewal with auth refresh endpoints
- Secure Storage: HTTP-only cookies for token storage
- Session Update: Dynamic session updates for profile changes
// Enhanced route protection with role-based access
export async function middleware(request) {
// Check authentication status
// Validate user roles with granular permissions
// Redirect unauthorized access
// Handle emergency access exceptions
}- Enhanced Profile Management: Comprehensive donor profile with medical history
- Request Tracking: Monitor blood request status with real-time updates
- Donation History: Track past donations with detailed statistics
- Emergency Requests: Submit urgent blood needs with priority handling
- Drive Participation: Register for and participate in donation drives
- Critical Settings: Configure availability for emergency blood needs
- Contact Responses: Respond to blood bank contact requests
- Patient Management: Handle patient blood requirements with comprehensive tracking
- Hospital Inventory Management: Independent blood stock management with batch tracking
- Inventory Dashboard: Real-time inventory overview with blood type breakdown
- Stock Level Management: Minimum stock level configuration with automated alerts
- Expiry Tracking: Blood unit expiration monitoring with 30-day warnings
- Inventory Logs: Complete audit trail of inventory changes and transactions
- Hospital Requests: Submit and manage hospital-to-blood bank requests
- Request Acceptance: Process incoming blood requests with status management
- Emergency Access: Priority blood request handling with instant notifications
- Advanced Inventory Management: Complete blood stock control with analytics
- Request Processing: Accept/reject blood requests with automated notifications
- Donor Coordination: Manage donor appointments and communication
- Emergency Notifications: Receive urgent request alerts with proximity-based matching
- Donation Drive Management: Create, manage, and track donation drives
- Donor Contact System: Direct communication with registered donors
- Analytics Dashboard: Comprehensive statistics and reporting tools
- Multi-location Management: Handle operations across different locations
// Advanced functionality
- Create new blood requests with automatic blood bank matching
- Track request status with real-time updates (pending/accepted/rejected/fulfilled)
- Update request information with audit trails
- Emergency request processing with priority handling
- Automated blood bank notifications with proximity search
- Hospital-specific request management
- Bulk request processing capabilities// Blood Bank Inventory Operations
- Real-time blood unit tracking with advanced analytics
- Blood type categorization with compatibility matrix
- Expiry date management with automated alerts
- Low stock alerts with configurable thresholds
- Comprehensive inventory transaction logging
- Multi-location inventory support
// Hospital Inventory Operations
- Independent hospital blood stock management
- Batch number tracking with expiration monitoring
- Minimum and maximum stock level configuration
- Complete audit trail with detailed change logs
- Stock level indicators with visual dashboards
- Automated reorder suggestions// Drive management features
- Create and schedule donation drives
- Registration system for donor participation
- Drive analytics and reporting
- Automated notifications and reminders
- Multi-location drive support
- Performance tracking and statistics// Enhanced communication system
- Direct donor contact requests from blood banks
- Secure messaging between parties
- Response tracking and management
- Critical donor availability settings
- Emergency contact protocols
- Communication history and audit trails// Comprehensive emergency features
- Guest access with minimal registration
- Location-based blood bank search with distance calculation
- Priority request processing with immediate notifications
- Emergency contact management with direct communication
- Real-time status tracking with updates
- Emergency call interface for urgent situations// Advanced chatbot capabilities
- Blood-related query assistance with context awareness
- Role-specific guidance and personalized responses
- Emergency procedure information with step-by-step guidance
- Donation process guidance with detailed instructions
- Real-time conversation handling with message processing
- Enhanced knowledge base with blood compatibility informationEnhanced Knowledge Base Topics:
- Blood donation eligibility with detailed criteria
- Blood types and compatibility with visual matrix
- Emergency procedures with immediate actions
- Donation process steps with preparation guidelines
- Health and safety guidelines with best practices
- Drive participation and scheduling assistance
- Contextual Responses: Role-aware assistance with personalized guidance
- Multi-turn Conversations: Advanced conversation context management
- Emergency Guidance: Immediate help for urgent situations with action items
- Educational Content: Comprehensive blood donation awareness and education
POST /api/auth/signin # User login with role validation
POST /api/auth/signout # User logout with session cleanup
GET /api/auth/session # Current session with role information
POST /api/auth/refresh # Session refresh and renewal
POST /api/users/register # Multi-step user registration
POST /api/users/complete-registration # Profile completion after role selection
GET /api/requests # List requests with advanced filtering
POST /api/requests # Create request with automatic matching
PUT /api/requests/:id # Update request status with notifications
DELETE /api/requests/:id # Cancel request with status tracking
GET /api/requests/track # Universal request tracking system
GET /api/hospital-requests # Hospital-specific request management
POST /api/hospital-requests # Create hospital requests
PUT /api/hospital-requests/:id # Update hospital request status
GET /api/hospital-requests/respond # Hospital request response system
GET /api/donation-drives # List available drives with filtering
POST /api/donation-drives/create # Create new donation drive
POST /api/donation-drives/register # Register for drive participation
GET /api/donation-drives/my-drives # User's registered drives
POST /api/donor-contact-request # Create donor contact request
GET /api/donor-contact-request # List contact requests
POST /api/donor-contact-request/respond # Respond to contact requests
GET /api/inventory # Blood bank inventory with analytics
POST /api/inventory # Update inventory with logging
GET /api/inventory/logs # Detailed inventory change history
GET /api/hospital-inventory # Hospital inventory with breakdown
POST /api/hospital-inventory # Add/update hospital inventory
GET /api/hospital-inventory/logs # Hospital inventory audit logs
- Role-based Menus: Dynamically generated navigation based on user roles
- Multi-level Navigation: Hierarchical menu structure for complex workflows
- Authentication State: Advanced login/logout with session management
- Responsive Design: Mobile-optimized with collapsible sections
- Theme Integration: Seamless dark/light mode transitions
- Multi-step Registration: Guided registration with role-specific forms
- Enhanced Validation: Client and server-side validation with real-time feedback
- Role Selection: Interactive role selection with detailed descriptions
- Error Handling: User-friendly error messages with actionable guidance
- Responsive Forms: Mobile-optimized with accessible form controls
- Advanced Chat UI: Modern chat interface with message threading
- Message Processing: Enhanced message handling with context awareness
- Chat History: Persistent conversation history with search functionality
- Typing Indicators: Real-time typing status and response indicators
- File Attachments: Support for sharing relevant documents and images
// Advanced access control
- Granular permission checking
- Role-based component rendering
- Automatic redirection for unauthorized access
- Emergency access exceptions
- Session validation with real-time updates// Specialized form handling
- Blood type selection with compatibility info
- Date/time pickers for scheduling
- Location selection with maps integration
- File upload with validation
- Multi-step form wizards// Comprehensive emergency handling
const { notifications, emergencyCheck, handleEmergency } = useEmergencyNotifications();
// Real-time emergency request validation
// Automated alert distribution
// Priority-based notification routing
// Emergency contact management// Advanced role-based functionality
const { userRole, permissions, checkAccess, hasPermission } = useUserRole();
// Granular permission checking
// Dynamic role updates
// Session-aware role management
// Multi-level authorization// Comprehensive request tracking
const { requests, updateStatus, trackProgress, getHistory } = useRequestStatus();
// Real-time status synchronization
// Request lifecycle management
// Automated status notifications
// Historical tracking and analytics// Advanced compatibility checking
- Complete blood type compatibility matrix
- Donor-recipient matching algorithms
- Emergency compatibility protocols
- Rare blood type handling// Enhanced chatbot integration
- Context-aware message processing
- Multi-turn conversation handling
- Intent recognition and response routing
- Personalized response generation-
Connect Repository
# Push to GitHub with latest changes git push origin main -
Configure Environment Variables
MONGODB_URI=your-production-mongodb-uri NEXTAUTH_SECRET=your-production-secret NEXTAUTH_URL=https://your-domain.vercel.app GROQ_API_KEY=your-groq-api-key
-
Deploy
- Connect GitHub repository to Vercel
- Add environment variables
- Configure build settings for optimal performance
- Deploy automatically on push with preview deployments
- Code Standards: Follow ESLint configuration with Prettier formatting
- Component Architecture: Modular components with custom hooks
- API Design: RESTful endpoints with comprehensive error handling
- Database Design: Optimized schemas with proper indexing
- Authentication: Multi-layered security with role-based access
- Testing: Unit and integration tests for critical components
- Documentation: Comprehensive inline documentation
- Performance: Optimized queries and component rendering
Built with ❤️ for saving lives through technology
BloodBond - Connecting blood donors, hospitals, and blood banks for a healthier tomorrow
- ✅ Donation Drive Management: Complete drive creation and participation system
- ✅ Advanced Donor-Blood Bank Communication: Direct contact and request system
- ✅ Enhanced Emergency System: Improved emergency call interface and handling
- ✅ Hospital Request Management: Specialized hospital-to-blood bank request system
- ✅ Blood Compatibility Matrix: Advanced blood type compatibility checking
- ✅ Enhanced Chatbot: Improved AI assistance with message processing
- ✅ Role Guard System: Comprehensive role-based access control
- ✅ Multi-step Registration: Enhanced user onboarding experience
- ✅ Advanced Analytics: Comprehensive statistics and reporting
- ✅ Enhanced UI/UX: Improved interface with better navigation and theming