Skip to content

kevinThulnith/Factory-Management-System

Folders and files

NameName
Last commit message
Last commit date

Latest commit

Β 

History

68 Commits
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 

Repository files navigation

Django DRF JWT PostgreSQL Redis Vite React Tailwind Axios NodeJS npm Docker Nginx

🏭 Factory Management System (FMS)

A Full-stack Factory Management System (FMS) built using Django, React, PostgreSQL, Redis, and Docker. Designed for seamless real-time operations, this web application provides an interactive platform for production monitoring, equipment management, labor allocation, and inventory tracking, while also offering robust administrative capabilities for supervisors, managers, and production staff. Built with comprehensive REST API endpoints, WebSocket real-time broadcasting, and Google OAuth2 authentication for secure access.

picture

✨ Key Features

🏭 Core Manufacturing Operations

  • Real-Time Production Monitoring β€” Live dashboards showing machine status, production progress, and KPIs
  • Production Scheduling β€” Manage production lines and schedules with workflow tracking
  • Equipment Management β€” Full machine lifecycle with operator assignment (8-hour auto-removal), maintenance scheduling
  • Manufacturing Processes β€” Define and link standard manufacturing processes to products

πŸ“¦ Inventory Management

  • Material Tracking β€” Real-time stock levels with automatic low-stock alerts
  • Supplier Management β€” Maintain supplier database with contact information
  • Purchase Orders β€” Full procurement workflow (Draft β†’ Ordered β†’ Received/Cancelled)
  • Material Consumption β€” Track material usage against tasks or production schedules
  • Invoice Management β€” File upload support for order documentation

πŸ‘₯ Labor & Workforce Management

  • Labor Allocation β€” Track employee hours across projects, tasks, and production lines
  • Skill Matrix β€” Record and manage employee competencies across 12 skill categories
  • Project Assignment β€” Assign employees to projects with automatic labor hour calculation
  • Time Management β€” Daily labor allocation with automatic calculations

πŸ“Š Project & Task Management

  • Project Lifecycle β€” Full status tracking (Planning β†’ In Progress β†’ Completed/On Hold/Cancelled)
  • Task Dependencies β€” Complex task relationships with self-referential dependencies
  • Resource Allocation β€” Automatic labor allocation on task assignment
  • Progress Tracking β€” Real-time task and project status updates

πŸ” Security & Access Control

  • 6-Role RBAC System β€” Admin, Manager, Supervisor, Operator, Technician, Purchasing
  • JWT Authentication β€” 30-minute token lifetime with automatic rotation and blacklisting
  • Google OAuth 2.0 β€” Social authentication with pre-registration validation
  • Object-Level Permissions β€” Fine-grained access control at the API and WebSocket level
  • Automated Role Management β€” Roles automatically upgrade/downgrade based on appointments
  • WebSocket Security β€” Socket handshake with auth token.

πŸ“‘ Real-Time Capabilities

  • WebSocket Broadcasting β€” Instant updates to all connected clients on CRUD operations
  • Permission-Filtered Updates β€” Each user only receives data they're authorized to see
  • Live Dashboard β€” Real-time statistics and KPI updates without page refresh
  • Automatic Sync β€” Backend changes instantly reflect in all connected frontends

πŸ“± User Experience

  • Responsive Design β€” Mobile, tablet, and desktop support with dark theme
  • Lazy-Loaded Pages β€” Fast load times with on-demand component loading
  • Intuitive Navigation β€” Role-based sidebar with dynamic menu items
  • Bulk Operations β€” CSV export and import for data management

πŸ› οΈ Tech Stack

Layer Technology
Backend Python 3.14, Django 5.2.6, Django REST Framework 3.16.1
Real-Time Django Channels 4.3.1, Redis 7, Daphne (ASGI)
Auth SimpleJWT 5.5.1, Google OAuth 2.0 (django-allauth)
Frontend React 19.1.1, Vite 7.1.7 (SWC), Tailwind CSS 3.4.18
Database SQLite (dev / main branch) Β· PostgreSQL 14 (docker branches)
Infrastructure Docker, Docker Compose, Nginx 1.25

πŸ—οΈ System Architecture

pic2


πŸš€ Getting Started

πŸ“‹ Prerequisites

Tool Version Link
Git Latest git-scm.com
Python β‰₯ 3.14 python.org
Node.js β‰₯ 18 nodejs.org
Docker Desktop Latest docker.com
Redis β‰₯ 7 redis.io
PostgreSQL β‰₯ 14 postgresql.org

Note (Windows Users): If using Python 3.14, also install:


⛓️‍πŸ’₯ Project Setup

git clone https://github.com/kevinThulnith/Factory-Management-System.git
cd Factory-Management-System

βš™οΈ Backend Setup

  1. Go to backend directory:

    cd backend
  2. πŸ”§ Setting up environment variables

    The backend requires a .env file before running. These files are not committed β€” create them manually.

πŸͺ„ Google OAuth Credentials

Required for both Google sign-in and the GOOGLE_CLIENT_ID / GOOGLE_CLIENT_SECRET / VITE_CLIENT_ID variables.

  1. Go to Google Cloud Console and create a project (or select an existing one).

  2. Navigate to APIs & Services β†’ Credentials β†’ Create Credentials β†’ OAuth 2.0 Client ID.

  3. Set Application type to Web application.

  4. Under Authorised JavaScript origins add:

    http://localhost
    http://localhost:5173
  5. Under Authorised redirect URIs add:

    http://localhost
    http://localhost:5173
    http://localhost:8000/accounts/google/login/callback/
  6. Click Create β€” copy the Client ID and Client Secret into the env files below.

Only email addresses that already exist as users in the system can sign in via Google. New Google accounts are rejected by the custom adapter.

πŸ”‘ Django Secret Key

Generate a secure key with:

python -c "from django.core.management.utils import get_random_secret_key; print(get_random_secret_key())"

backend/.env

Create a .env file in the backend directory with the following content:

DEBUG=True
SECRET_KEY=your-django-secret-key        # ← generated above

# Comma-separated, no spaces
ALLOWED_HOSTS=localhost,127.0.0.1,localhost:5173,localhost:8000

# Google OAuth β€” from Google Cloud Console (step 6 above)
GOOGLE_CLIENT_ID=your-google-client-id
GOOGLE_CLIENT_SECRET=your-google-client-secret
GOOGLE_CALLBACK_URL=http://localhost:5173

# Redis (defaults shown β€” change if Redis runs elsewhere)
REDIS_HOST=127.0.0.1
REDIS_PORT=6379
  1. πŸ“¦ Download required packages

    pip install uv
    uv sync --frozen
  2. πŸ—„οΈ Run database migrations and create super-user

    uv run manage.py migrate
    uv run manage.py createsuperuser
  3. 🌱 Run data seeder scripts (to populate initial data)

    uv run scripts/script1.py
    uv run scripts/script2.py
    uv run scripts/script3.py
    uv run scripts/script4.py
    uv run scripts/script5.py
    uv run scripts/script6.py
    uv run scripts/script7.py
    uv run scripts/script8.py
    uv run scripts/script9.py
    uv run scripts/script10.py
    uv run scripts/script11.py
  4. πŸš€ Run backend server

    uv run daphne -b 0.0.0.0 -p 8000 backend.asgi:application

    Backend will be available at: http://localhost:8000


🎨 Frontend Setup

  1. Go to frontend directory:

    cd ../frontend
  2. πŸ“¦ Install dependencies

    npm install
  3. πŸ”§ Create frontend .env file

    Create frontend/.env with:

    VITE_WS_URL="ws://localhost:8000"
    VITE_API_URL="http://localhost:8000"
    VITE_CLIENT_ID=your-google-client-id  # ← from Google Cloud Console
  4. ▢️ Run development server

    npm run host

    Frontend will be available at: http://localhost:5173


🌿 Branch Strategy

Branch Database Frontend Notes
main SQLite Vite dev server Local development
docker-compose PostgreSQL Separate container Full docker stack
docker-slim PostgreSQL Dist files in volume, served via Nginx Optimized production

🐳 Docker Setup

Create .env and .env.prod files in project root directory. Add both frontend and backend .env file data in both of them.

# frontend .env data

# backend .env data
GOOGLE_CALLBACK_URL = "http://localhost" # must set correctly

For .env.prod add this

# Database Settings
DATABASE_ENGINE=postgresql_psycopg2
DATABASE_NAME=FmsDatabase
DATABASE_USERNAME=FmsDbUser
DATABASE_PASSWORD=FmsDB4080
DATABASE_HOST=fms-database
DATABASE_PORT=5432
DATABASE_URL=postgresql://FmsDbUser:FmsDB4080@fms-database:5432/FmsDatabase

# Postgres Settings
POSTGRES_DB=FmsDatabase
POSTGRES_USER=FmsDbUser
POSTGRES_PASSWORD=FmsDB4080

# Redis Settings
REDIS_HOST=fms-redis
REDIS_PORT=6379

For .env add this

# Postgres Settings
POSTGRES_DB=FmsSlimDatabase
POSTGRES_USER=FmsSlimDbUser
POSTGRES_PASSWORD=FmsSlimDB4080

# Redis Settings
REDIS_HOST=fms-slim-redis
REDIS_PORT=6379

# Database Settings
DATABASE_ENGINE=postgresql_psycopg2
DATABASE_NAME=FmsSlimDatabase
DATABASE_USERNAME=FmsSlimDbUser
DATABASE_PASSWORD=FmsSlimDB4080
DATABASE_HOST=fms-slim-database
DATABASE_PORT=5432
DATABASE_URL=postgresql://FmsSlimDbUser:FmsSlimDB4080@fms-slim-database:5432/FmsSlimDatabase

πŸ–₯️ Make sure Docker Desktop is running before executing the commands below.

πŸ™ docker-compose branch

Switch branch

git switch docker-compose

Create | Run docker setup

docker-compose -p fms --env-file .env.prod up --build -d

πŸͺΆ docker-slim branch

Switch branch

git switch docker-slim

Create | Run docker setup

docker-compose -p fmsslim --env-file .env up --build -d

πŸ“– API Documentation

Once the backend is running, explore the API at:

Interface URL
Swagger UI http://localhost:8000/api/schema/swagger-ui/
ReDoc http://localhost:8000/api/schema/redoc/
Admin Panel http://localhost:8000/admin/

πŸ”Œ WebSockets

The system uses Django Channels over ASGI (Daphne) to provide real-time bidirectional communication between the server and all connected clients.

⚑ How It Works

Client ──── ws://localhost:8000/ws/<resource>/ ────▢ Django Channels (Redis Layer)
  β–²                                                          β”‚
  └──────────── broadcast to authorized clients β—€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜
  1. 🀝 Client connects and sends a JWT token in the WebSocket handshake
  2. πŸ” Server validates the token β€” unauthenticated connections are rejected
  3. πŸ“‘ On any CRUD operation (create / update / delete), the backend broadcasts the change
  4. 🎯 Each user only receives updates for resources they are authorized to see
  5. βš›οΈ The React frontend automatically updates state without a page refresh

🌐 Connection URL

ws://localhost:8000/ws/<resource>/

Configure the base WebSocket URL in frontend/.env:

VITE_WS_URL="ws://localhost:8000"

πŸ” Authentication

WebSocket connections are secured with JWT. The token is passed during the handshake:

const socket = new WebSocket(`${import.meta.env.VITE_WS_URL}/ws/<resource>/`);

⚠️ The server rejects any connection attempt that does not carry a valid, non-expired JWT token.

πŸ“‹ What Gets Broadcast

Event Trigger Payload
created New record added to the database New object
updated Existing record modified Updated object
deleted Record removed from the database Object ID
stats Any change that affects dashboard KPIs Stats object

πŸ› οΈ Backend Stack

Component Role
Django Channels WebSocket consumer routing & group layer
Daphne (ASGI) Async server β€” handles WS + HTTP together
Redis Channel layer backend for message passing

πŸ› Troubleshooting

❌ Redis Connection Error

  • Ensure Redis is running on localhost:6379
  • Update REDIS_HOST and REDIS_PORT in backend/.env if Redis is elsewhere

❌ Database Error

  • Run migrations: uv run manage.py migrate
  • For PostgreSQL: ensure it's running and credentials are correct in .env

❌ CORS / WebSocket Issues

  • Add your frontend URL to ALLOWED_HOSTS in backend/.env
  • WebSockets require Daphne β€” Django's built-in dev server won't work

❌ Google OAuth Not Working

  • Verify GOOGLE_CLIENT_ID and GOOGLE_CLIENT_SECRET in backend/.env
  • Ensure redirect URIs in Google Cloud Console exactly match those in setup

❌ Python Build Errors (Windows)


πŸ“š Project Structure

Factory-Management-System/
β”œβ”€β”€ 🐍 backend/              # Django REST API & WebSockets
β”‚   β”œβ”€β”€ manage.py
β”‚   β”œβ”€β”€ pyproject.toml
β”‚   β”œβ”€β”€ .env                # ← Create this (not in repo)
β”‚   β”œβ”€β”€ scripts/            # Data seeder scripts
β”‚   └── ...
β”œβ”€β”€ βš›οΈ  frontend/            # React + Vite application
β”‚   β”œβ”€β”€ package.json
β”‚   β”œβ”€β”€ .env               # ← Create this (not in repo)
β”‚   └── ...
β”œβ”€β”€ 🐳 docker-compose.yml   # Docker | Nginx orchestration on branches except `main`
β”œβ”€β”€ πŸ›‘οΈ nginx.conf
└── πŸ“„ README.md

🀝 Contributing

  1. 🍴 Fork the repository
  2. 🌿 Create a feature branch: git checkout -b feature/your-feature
  3. βœ… Commit your changes: git commit -m "Add your feature"
  4. πŸ“€ Push to your branch: git push origin feature/your-feature
  5. πŸ“¬ Open a Pull Request

πŸ“„ License

This project is licensed under the MIT License.


πŸ“ž Support & Contact

For issues, questions, or suggestions, please open a ticket at: πŸ‘‰ GitHub Issues

Releases

No releases published

Packages

 
 
 

Contributors