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.
- 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
- 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 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 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
- 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.
- 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
- 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
| 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 |
| 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:
- Visual Studio Build Tools (C++ compiler)
- PostgreSQL (for development headers)
git clone https://github.com/kevinThulnith/Factory-Management-System.git
cd Factory-Management-System-
Go to backend directory:
cd backend -
π§ Setting up environment variables
The backend requires a
.envfile before running. These files are not committed β create them manually.
Required for both Google sign-in and the GOOGLE_CLIENT_ID / GOOGLE_CLIENT_SECRET / VITE_CLIENT_ID variables.
-
Go to Google Cloud Console and create a project (or select an existing one).
-
Navigate to APIs & Services β Credentials β Create Credentials β OAuth 2.0 Client ID.
-
Set Application type to Web application.
-
Under Authorised JavaScript origins add:
http://localhost http://localhost:5173
-
Under Authorised redirect URIs add:
http://localhost http://localhost:5173 http://localhost:8000/accounts/google/login/callback/
-
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.
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-
π¦ Download required packages
pip install uv uv sync --frozen
-
ποΈ Run database migrations and create super-user
uv run manage.py migrate uv run manage.py createsuperuser
-
π± 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
-
π Run backend server
uv run daphne -b 0.0.0.0 -p 8000 backend.asgi:application
Backend will be available at:
http://localhost:8000
-
Go to frontend directory:
cd ../frontend -
π¦ Install dependencies
npm install
-
π§ Create frontend
.envfileCreate
frontend/.envwith:VITE_WS_URL="ws://localhost:8000" VITE_API_URL="http://localhost:8000" VITE_CLIENT_ID=your-google-client-id # β from Google Cloud Console
-
βΆοΈ Run development servernpm run host
Frontend will be available at:
http://localhost:5173
| 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 |
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 correctlyFor .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=6379For .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.
Switch branch
git switch docker-composeCreate | Run docker setup
docker-compose -p fms --env-file .env.prod up --build -dSwitch branch
git switch docker-slimCreate | Run docker setup
docker-compose -p fmsslim --env-file .env up --build -dOnce 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/ |
The system uses Django Channels over ASGI (Daphne) to provide real-time bidirectional communication between the server and all connected clients.
Client ββββ ws://localhost:8000/ws/<resource>/ βββββΆ Django Channels (Redis Layer)
β² β
βββββββββββββ broadcast to authorized clients ββββββββββββββ
- π€ Client connects and sends a JWT token in the WebSocket handshake
- π Server validates the token β unauthenticated connections are rejected
- π‘ On any CRUD operation (create / update / delete), the backend broadcasts the change
- π― Each user only receives updates for resources they are authorized to see
- βοΈ The React frontend automatically updates state without a page refresh
ws://localhost:8000/ws/<resource>/Configure the base WebSocket URL in frontend/.env:
VITE_WS_URL="ws://localhost:8000"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.
| 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 |
| Component | Role |
|---|---|
| Django Channels | WebSocket consumer routing & group layer |
| Daphne (ASGI) | Async server β handles WS + HTTP together |
| Redis | Channel layer backend for message passing |
- Ensure Redis is running on
localhost:6379 - Update
REDIS_HOSTandREDIS_PORTinbackend/.envif Redis is elsewhere
- Run migrations:
uv run manage.py migrate - For PostgreSQL: ensure it's running and credentials are correct in
.env
- Add your frontend URL to
ALLOWED_HOSTSinbackend/.env - WebSockets require Daphne β Django's built-in dev server won't work
- Verify
GOOGLE_CLIENT_IDandGOOGLE_CLIENT_SECRETinbackend/.env - Ensure redirect URIs in Google Cloud Console exactly match those in setup
- Install Visual Studio Build Tools with C++ workload
- Install PostgreSQL for development headers
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- π΄ Fork the repository
- πΏ Create a feature branch:
git checkout -b feature/your-feature - β
Commit your changes:
git commit -m "Add your feature" - π€ Push to your branch:
git push origin feature/your-feature - π¬ Open a Pull Request
This project is licensed under the MIT License.
For issues, questions, or suggestions, please open a ticket at: π GitHub Issues

