Skip to content

JASH9898567/pharma

Repository files navigation

💊 Pharma MES Simulator

A Pharmaceutical Manufacturing Execution System (MES) simulator built with FastAPI that doubles as a real-world demonstration of Operating System concepts — process scheduling, thread management, interrupt handling, deadlock avoidance, and memory management.

Originally developed as a B.Tech Operating Systems project, this simulator shows how OS-level design patterns power real industrial applications.


🚀 Features

  • Real-time Machine Simulation — Virtual pharmaceutical machines (mixer, granulator, etc.) run as independent OS threads
  • Priority CPU Scheduler — Batches are scheduled like OS processes using a priority queue (heapq)
  • Interrupt Vector Table — Simulated hardware faults trigger Interrupt Service Routines (ISRs)
  • Mutex-based Critical Section Protection — Thread-safe batch state management using threading.Lock()
  • Deadlock Avoidance — Safe resource allocation prevents circular wait conditions
  • Quality Management System (QMS) — CAPA workflow, audit trail, and quality checks
  • JWT Authentication — Secure login and role-based access
  • PDF & CSV Reports — Auto-generated batch and quality reports using ReportLab
  • Live Web Dashboard — Real-time monitoring via polling

🗂️ Project Structure

pharma/
├── app.py                      # Main FastAPI application entry point
├── database.py                 # SQLAlchemy DB setup
├── models.py                   # Data models (Pydantic + SQLAlchemy)
├── requirements.txt
│
├── simulation/
│   ├── machines.py             # Threaded machine simulation + predictive analytics
│   ├── scheduler.py            # Priority CPU scheduling algorithm
│   └── fault_handler.py        # Interrupt Vector Table + ISRs
│
├── mes/
│   └── batch_manager.py        # Batch lifecycle management (MES)
│
├── qms/
│   ├── quality.py              # Quality checks engine
│   ├── capa.py                 # Corrective & Preventive Action workflow
│   └── audit.py                # Audit trail manager
│
├── auth/
│   └── auth.py                 # JWT authentication manager
│
├── reports/
│   └── reports.py              # PDF/CSV report generation
│
├── static/                     # CSS & JavaScript frontend
└── templates/                  # Jinja2 HTML templates

⚙️ Getting Started

Prerequisites

  • Python 3.10+
  • pip

Installation

# Clone the repository
git clone https://github.com/YOUR_USERNAME/pharma-mes-simulator.git
cd pharma-mes-simulator

# Create a virtual environment
python -m venv venv
source venv/bin/activate      # On Windows: venv\Scripts\activate

# Install dependencies
pip install -r requirements.txt

Running the App

uvicorn app:app --reload

Then open your browser at http://localhost:8000


🧠 OS Concepts Demonstrated

OS Concept Implementation
Threads & Multiprogramming Each machine runs as a threading.Thread
Mutex / Critical Section threading.Lock() and threading.RLock() on shared state
CPU Scheduling (Priority) heapq-based priority queue in scheduler.py
Interrupt Handling (IVT + ISR) fault_handler.py routes hardware faults to specific ISR functions
Deadlock Avoidance Lock acquired only when machine is fully free (no Hold-and-Wait)
FIFO Memory / Buffering alerts_log ring buffer capped at 200 entries with FIFO eviction
I/O Spooling Async file logging via Python FileHandler

See OS_Project_Documentation.md for the full mapping to the B.Tech OS syllabus.


🛠️ Tech Stack


🤝 Contributing

Contributions are welcome! Please read CONTRIBUTING.md before opening a pull request.


📄 License

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

About

No description, website, or topics provided.

Resources

License

Contributing

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors