bloodbank

Rural Blood Bank 🩸

A community-powered, multi-tenant blood donation platform connecting blood donors with patients in rural areas of Bangladesh. Built with modern web technologies and designed for organizations to manage their own blood bank networks.

Next.js TypeScript MongoDB Tailwind CSS


🌟 Key Features

Multi-Tenant Architecture

Super Admin Dashboard

Donor Management

Blood Request System

Admin Dashboard

Authentication & Security

Progressive Web App (PWA)


πŸ›  Tech Stack

Category Technology
Framework Next.js 16 (App Router with Turbopack)
Language TypeScript 5.x
Database MongoDB with Mongoose 9
Authentication NextAuth.js 4.x
Styling Tailwind CSS 4.x
Forms React Hook Form + Zod Validation
Notifications Sonner (Toast notifications)
Icons Lucide React
PWA @ducanh2912/next-pwa

πŸ“ Project Structure

bloodbank/
β”œβ”€β”€ app/
β”‚   β”œβ”€β”€ (auth)/                    # Auth route group (empty, uses /login)
β”‚   β”œβ”€β”€ (dashboard)/               # Dashboard route group (empty, uses org-scoped)
β”‚   β”œβ”€β”€ [orgSlug]/                 # Organization-scoped pages
β”‚   β”‚   β”œβ”€β”€ layout.tsx             # Org layout with Navbar & Footer
β”‚   β”‚   β”œβ”€β”€ page.tsx               # Org landing page
β”‚   β”‚   β”œβ”€β”€ dashboard/             # Admin dashboard
β”‚   β”‚   β”‚   β”œβ”€β”€ page.tsx           # Dashboard overview
β”‚   β”‚   β”‚   β”œβ”€β”€ donors/page.tsx    # Donor management
β”‚   β”‚   β”‚   └── requests/page.tsx  # Request management
β”‚   β”‚   β”œβ”€β”€ donors/page.tsx        # Public donor discovery
β”‚   β”‚   β”œβ”€β”€ register/page.tsx      # Donor registration
β”‚   β”‚   └── requests/              # Blood requests
β”‚   β”‚       β”œβ”€β”€ page.tsx           # Requests listing
β”‚   β”‚       └── new/page.tsx       # New request form
β”‚   β”œβ”€β”€ api/                       # API routes
β”‚   β”‚   β”œβ”€β”€ auth/[...nextauth]/    # NextAuth.js handler
β”‚   β”‚   β”œβ”€β”€ donors/                # Donor APIs
β”‚   β”‚   β”‚   β”œβ”€β”€ route.ts           # GET: List donors
β”‚   β”‚   β”‚   β”œβ”€β”€ register/route.ts  # POST: Register donor
β”‚   β”‚   β”‚   └── verify/route.ts    # POST: Verify donor
β”‚   β”‚   β”œβ”€β”€ requests/              # Request APIs
β”‚   β”‚   β”‚   β”œβ”€β”€ route.ts           # GET: List requests
β”‚   β”‚   β”‚   β”œβ”€β”€ new/route.ts       # POST: Create request
β”‚   β”‚   β”‚   └── status/route.ts    # POST: Update status
β”‚   β”‚   └── org/stats/route.ts     # GET: Organization stats
β”‚   β”œβ”€β”€ login/page.tsx             # Global login page
β”‚   β”œβ”€β”€ page.tsx                   # Main landing page
β”‚   β”œβ”€β”€ layout.tsx                 # Root layout
β”‚   └── globals.css                # Global styles
β”œβ”€β”€ components/
β”‚   β”œβ”€β”€ AuthProvider.tsx           # NextAuth session provider
β”‚   β”œβ”€β”€ Navbar.tsx                 # Organization-aware navbar
β”‚   β”œβ”€β”€ Footer.tsx                 # Organization-aware footer
β”‚   └── ui/                        # Reusable UI components
β”‚       β”œβ”€β”€ button.tsx
β”‚       β”œβ”€β”€ card.tsx
β”‚       └── input.tsx
β”œβ”€β”€ lib/
β”‚   β”œβ”€β”€ authOptions.ts             # NextAuth configuration
β”‚   β”œβ”€β”€ orgUtils.ts                # Organization utilities
β”‚   β”œβ”€β”€ context/
β”‚   β”‚   └── OrganizationContext.tsx  # Organization React context
β”‚   β”œβ”€β”€ db/
β”‚   β”‚   └── mongodb.ts             # MongoDB connection
β”‚   └── models/
β”‚       β”œβ”€β”€ User.ts                # User & DonorProfile models
β”‚       β”œβ”€β”€ BloodRequest.ts        # Blood request model
β”‚       └── Organization.ts        # Organization model
β”œβ”€β”€ scripts/
β”‚   └── seed.ts                    # Database seeder
└── public/                        # Static assets

πŸ—„ Database Models

User

{
  name: string;           // Required
  phone: string;          // Required, unique identifier
  email?: string;         // Optional
  password?: string;      // Optional (for demo, uses simple bypass)
  role: UserRole;         // donor | patient | volunteer | admin | super_admin
  organization?: ObjectId;
  image?: string;
  createdAt: Date;
  updatedAt: Date;
}

DonorProfile

{
  user: ObjectId;           // Reference to User
  organization: ObjectId;   // Reference to Organization
  bloodGroup: string;       // A+, A-, B+, B-, O+, O-, AB+, AB-
  district: string;
  upazila: string;
  village?: string;
  lastDonationDate?: Date;
  isAvailable: boolean;     // Default: true
  isVerified: boolean;      // Default: false (requires admin verification)
}

BloodRequest

{
  patientName: string;
  bloodGroup: string;
  location: string;
  district: string;
  upazila: string;
  urgency: UrgencyLevel;     // normal | urgent | emergency
  requiredDate: Date;
  contactNumber: string;
  additionalNotes?: string;
  status: RequestStatus;     // pending | fulfilled | canceled
  requester: ObjectId;       // Reference to User
  organization: ObjectId;    // Reference to Organization
  createdAt: Date;
  updatedAt: Date;
}

Organization

{
  name: string;
  slug: string;              // Unique, lowercase URL slug
  logo?: string;
  primaryColor?: string;     // Default: #D32F2F (red)
  contactEmail?: string;
  contactPhone?: string;
  address?: string;
  isActive: boolean;         // Default: true
  createdAt: Date;
  updatedAt: Date;
}

πŸ”Œ API Endpoints

Donors

| Method | Endpoint | Description | |——–|β€”β€”β€”-|β€”β€”β€”β€”-| | GET | /api/donors?orgSlug=X&bloodGroup=Y&district=Z&upazila=W | List donors with optional filters | | POST | /api/donors/register | Register a new donor | | POST | /api/donors/verify | Verify/unverify a donor (admin) |

Blood Requests

| Method | Endpoint | Description | |——–|β€”β€”β€”-|β€”β€”β€”β€”-| | GET | /api/requests?orgSlug=X&urgency=Y&status=Z | List requests with optional filters | | POST | /api/requests/new | Create a new blood request | | POST | /api/requests/status | Update request status |

Organization

| Method | Endpoint | Description | |——–|β€”β€”β€”-|β€”β€”β€”β€”-| | GET | /api/org/stats?orgSlug=X | Get organization statistics |

Super Admin

| Method | Endpoint | Description | |——–|β€”β€”β€”-|β€”β€”β€”β€”-| | GET | /api/admin/organizations | List all organizations | | POST | /api/admin/organizations | Create new organization | | GET | /api/admin/organizations/[id] | Get organization by ID with stats | | PUT | /api/admin/organizations/[id] | Update organization | | DELETE | /api/admin/organizations/[id] | Delete organization | | GET | /api/admin/stats | Get platform-wide statistics |

Authentication

| Method | Endpoint | Description | |——–|β€”β€”β€”-|β€”β€”β€”β€”-| | POST | /api/auth/[...nextauth] | NextAuth.js authentication handler |


πŸš€ Getting Started

Prerequisites

1. Clone the Repository

git clone https://github.com/3s-Soft/bloodbank.git
cd bloodbank

2. Install Dependencies

npm install

3. Setup Environment Variables

Create a .env.local file in the root directory:

# MongoDB Connection
MONGODB_URI=mongodb://localhost:27017/bloodbank

# NextAuth Configuration
NEXTAUTH_URL=http://localhost:3000
NEXTAUTH_SECRET=your-secret-key-here-generate-with-openssl

4. Seed the Database

Run the seed script to create test organizations and users:

npx tsx scripts/seed.ts

5. Run Development Server

npm run dev

Open http://localhost:3000 to view the application.


πŸ§ͺ Demo Credentials

Test Admin User

| Field | Value | |β€”β€”-|β€”β€”-| | Phone | 01700000000 | | Password | demo123 |

Test Organizations

Organization URL Slug Primary Color
Savar Blood Bank savar-blood-bank Red (#D32F2F)
Uttara Donors uttara-donors Blue (#1976D2)
Mirpur Life Savers mirpur-life-savers Green (#388E3C)

Test URLs (After Seeding)


πŸ“œ Available Scripts

Command Description
npm run dev Start development server with Turbopack
npm run build Build production bundle
npm run start Start production server
npm run lint Run ESLint
npx tsx scripts/seed.ts Seed database with test data

🀝 Contributing

Contributions are welcome! Please read our Contributing Guide and Code of Conduct before submitting a pull request.


πŸ“„ License

This project is licensed under the MIT License - see the LICENSE file for details.


πŸ”’ Security

For security vulnerabilities, please refer to our Security Policy.


πŸ™ Acknowledgments