Skip to content

Latest commit

 

History

History
248 lines (201 loc) · 8.51 KB

File metadata and controls

248 lines (201 loc) · 8.51 KB

MedTrace: Pharma Batch Record Tracker

📋 Project Overview

MedTrace Systems - An Electronic Batch Record (EBR) system for pharmaceutical manufacturing. This is a portfolio project demonstrating a simplified Manufacturing Execution System (MES) used in pharma to track batch production from start to finish with full traceability and compliance.

What is MES?

A Manufacturing Execution System is a real-time production monitoring system that captures and reports all activities on the production floor. In pharmaceuticals, MES ensures:

  • GMP Compliance (Good Manufacturing Practices)
  • Traceability - Track every batch from raw materials to finished product
  • Quality Assurance - Verify each step meets specifications
  • Audit Trail - Digital signatures and timestamps on all actions

What is EBR?

An Electronic Batch Record is the digital equivalent of a paper batch record. It documents every step of a batch's production journey, including:

  • Operator actions and observations
  • Digital signatures and timestamps
  • Quality measurements and deviations
  • Approvals and final sign-off

🎯 Features

1. Authentication System

  • User registration and login with email + password
  • JWT-based authentication (15-min access tokens, 7-day refresh tokens)
  • Role-based access control (Operator vs Admin)
  • Secure httpOnly cookies for token storage

2. Recipe Management (Admin Only)

  • Create recipes with multiple steps
  • Each step includes: name, instruction, expected value, unit, signature requirement
  • Activate/deactivate recipes
  • Pre-seeded with 3 sample recipes: Paracetamol, Amoxicillin, Ibuprofen

3. Batch Execution (Operator)

  • Start a batch from an active recipe
  • Sequential step-by-step execution (no skipping)
  • Auto-generated Batch IDs (format: BAT-YYYYMMDD-XXXX)
  • Record actual values for each step
  • Digital e-signature for critical steps
  • Auto-save progress to prevent data loss
  • Visual progress bar with completion percentage

4. Batch Review & Approval (Admin)

  • View all pending batches on dashboard
  • Review step records and operator data
  • Approve or reject batches with comments
  • Rejection sends batch back for review

5. EBR PDF Export

  • Generate professional PDF batch records for approved batches
  • Includes: batch info, all steps with actual values, e-signatures, approval details
  • GMP compliance disclaimer
  • Download from batch detail page

6. Dashboards

  • Admin Dashboard: KPIs (total batches, pending, approved today, active recipes), chart of batches per product (30-day), recent batches table
  • Operator Dashboard: Quick-start new batch, my batch history with resume buttons

🛠️ Tech Stack

Layer Technology
Frontend React 18 + Vite + Tailwind CSS
Backend Node.js + Express.js
Database MongoDB with Mongoose
Authentication JWT (access + refresh tokens)
PDF Generation pdfkit
Charts Recharts
HTTP Client Axios
Notifications React Hot Toast
Icons Lucide React
Deployment Vercel (Frontend), Render (Backend), MongoDB Atlas (DB)

📁 Project Structure

pharma-batch-tracker/
├── client/                        # React + Vite Frontend
│   ├── src/
│   │   ├── components/
│   │   │   ├── ProtectedRoute.jsx
│   │   │   ├── Sidebar.jsx
│   │   │   ├── UI.jsx             # Reusable UI components (Button, Input, Card, etc.)
│   │   │   ├── Stepper.jsx        # Batch execution stepper
│   │   │   └── BatchComponents.jsx
│   │   ├── pages/
│   │   │   ├── LoginPage.jsx
│   │   │   ├── RegisterPage.jsx
│   │   │   ├── AdminDashboard.jsx
│   │   │   ├── OperatorDashboard.jsx
│   │   │   ├── RecipeManagementPage.jsx
│   │   │   ├── BatchExecutionPage.jsx
│   │   │   └── AdminBatchesPage.jsx
│   │   ├── context/
│   │   │   └── AuthContext.jsx
│   │   ├── hooks/
│   │   │   ├── useAuth.js
│   │   │   └── useBatch.js
│   │   ├── services/
│   │   │   └── api.js             # Axios instance + API endpoints
│   │   ├── utils/
│   │   │   └── helpers.js
│   │   ├── App.jsx
│   │   ├── main.jsx
│   │   └── index.css
│   ├── package.json
│   ├── vite.config.js
│   ├── tailwind.config.js
│   ├── vercel.json
│   ├── .env.example
│   └── index.html
│
├── server/                        # Express Backend
│   ├── models/
│   │   ├── User.js
│   │   ├── Recipe.js
│   │   └── Batch.js
│   ├── controllers/
│   │   ├── authController.js
│   │   ├── recipeController.js
│   │   └── batchController.js
│   ├── routes/
│   │   ├── authRoutes.js
│   │   ├── recipeRoutes.js
│   │   └── batchRoutes.js
│   ├── middleware/
│   │   ├── authenticateToken.js
│   │   ├── roleCheck.js
│   │   └── errorHandler.js
│   ├── utils/
│   │   ├── logger.js
│   │   ├── batchIdGenerator.js
│   │   ├── pdfGenerator.js
│   │   └── seeder.js
│   ├── package.json
│   ├── index.js
│   ├── .env.example
│   └── .gitignore
│
└── README.md

📊 API Endpoints

Authentication

  • POST /api/auth/register - Register new user
  • POST /api/auth/login - Login user
  • POST /api/auth/refresh - Refresh access token
  • POST /api/auth/logout - Logout
  • GET /api/auth/me - Get current user

Recipes (Admin Only)

  • POST /api/recipes - Create recipe
  • GET /api/recipes - Get all recipes
  • GET /api/recipes/:id - Get recipe by ID
  • PUT /api/recipes/:id - Update recipe
  • PATCH /api/recipes/:id/deactivate - Deactivate recipe

Batches

  • POST /api/batches - Start new batch (Operator)
  • GET /api/batches/:id - Get batch details
  • POST /api/batches/:id/step - Complete batch step (Operator)
  • GET /api/batches/my-batches - Get operator's batches
  • GET /api/batches - Get all batches (Admin only)
  • POST /api/batches/:id/approve - Approve batch (Admin)
  • POST /api/batches/:id/reject - Reject batch (Admin)
  • GET /api/batches/:id/download - Download EBR PDF
  • GET /api/batches/stats/dashboard - Dashboard stats (Admin)

🔐 Security Features

  • ✅ Password hashing with bcrypt
  • ✅ JWT access + refresh token pattern
  • ✅ httpOnly, secure, sameSite cookies
  • ✅ Role-based access control (RBAC)
  • ✅ CORS protection
  • ✅ Input validation on client and server
  • ✅ Error handling without leaking sensitive info
  • ✅ MongoDB injection prevention (Mongoose)

📝 Sample Recipes (Pre-seeded)

1. Paracetamol 500mg Tablet (100 kg batches)

  • Weighing → Granulation → Drying → Milling → Blending → Compression → Coating → QC Inspection

2. Amoxicillin 250mg Capsule (50 kg batches)

  • Material Verification → Blending → Capsule Filling → Polishing → Weight Check → Visual Inspection

3. Ibuprofen 400mg Tablet (75 kg batches)

  • Dispensing → Wet Granulation → Fluid Bed Drying → Sizing → Lubrication → Tablet Compression → Film Coating

📚 Code Quality

  • ✅ Async/await throughout (no callbacks)
  • ✅ Consistent error handling with try/catch
  • ✅ Comments on complex logic
  • ✅ Modular component structure
  • ✅ DRY principles (Don't Repeat Yourself)
  • ✅ HTTP status codes used correctly
  • ✅ Input validation on both client and server

🤝 Contributing

This is a portfolio project. Modifications and improvements are encouraged!


📄 License

Author: Vedant24v

This project is created as a portfolio demonstration for pharmaceutical manufacturing execution systems and electronic batch records.


✨ Features Roadmap

  • Mobile app (React Native)
  • Advanced analytics and reporting
  • Batch deviation management
  • Equipment integration (IoT sensors)
  • Automated alerts for out-of-spec values
  • Multi-language support
  • Two-factor authentication (2FA)

📧 Contact

For questions or suggestions, please reach out to the project author.


Note: This is a simplified EBR system for educational/portfolio purposes. A production system would require additional features like audit trails, compliance validation, and integration with enterprise systems.