Sign inSign up

lecroissant2003/fms-backend

By lecroissant2003

•Updated 17 days ago

FMS (Factory Management System) backend image. Includes API, WebSocket and OAuth2 integration.

Buildkit cache
Image
Languages & frameworks
API management
Web servers
0

4.7K

lecroissant2003/fms-backend repository overview

⁠Factory Management System (FMS) - Backend Microservice

High-performance, asynchronous Django 5 REST API & WebSocket backend powering the Factory Management System (FMS). Built with Django REST Framework, Django Channels, Redis caching/channel layer, and Google OAuth2.


⁠🏗️ Architecture & Core Modules

The backend is composed of domain-driven Django applications:

  • main: User management, custom authentication, role-based permissions (Admin, Manager, Supervisor).
  • core: Organization structure, departments, and workshop locations.
  • labor: Employee skill matrix, work shifts, and labor tracking.
  • project: Project lifecycles, milestone tracking, and task assignments.
  • product: Product catalogs, manufacturing processes, and BOM (Bill of Materials).
  • inventory: Suppliers, raw materials, stock levels, and consumption tracking.
  • production: Production lines, machine states, and manufacturing schedules.

⁠🔐 Google OAuth2 & Authentication Flow

  • Pre-Registered Account Enforcement: Uses a CustomSocialAccountAdapter extending django-allauth. Automatic signup is disabled (SOCIALACCOUNT_AUTO_SIGNUP = False). Only existing system users with matching Google emails are allowed access; unauthenticated attempts return HTTP 403 with administrator instructions.
  • JWT Token Management: Powered by rest_framework_simplejwt & dj-rest-auth.
    • Token Rotation: ROTATE_REFRESH_TOKENS = True
    • Blacklisting: TOKEN_BLACKLIST_ENABLED = True
    • Lifetimes: 30-minute access and refresh tokens.
    • Endpoints: /api/token/, /api/token/refresh/, /api/token/blacklist/, /api/rest-auth/google/.

⁠⚡ WebSockets & Asynchronous Messaging

  • ASGI Stack: Uses ProtocolTypeRouter (backend.asgi.application) combining HTTP and WebSocket protocols.
  • Handshake Authentication: Custom JWTAuthMiddleware and ConsumerBlock validate SimpleJWT access tokens upon initial WebSocket handshake connection.
  • Channel Layer: Backed by channels_redis.core.RedisChannelLayer for scalable multi-node message broadcasting.
  • Real-Time Security: Performs server-side DRF permission checks (check_object_permission) on WebSocket message payloads before sending updates to connected clients.

⁠📡 Event Listening & Django Signals

  • Automated Data Sync: Implements a generic model change factory create_model_change_signal listening on post_save and post_delete model signals.
  • Real-Time Serialization: Automatically serializes model instance mutations (created, updated, deleted) using DRF serializers.
  • Live Push: Broadcasts events asynchronously (async_to_sync) over Redis Channel Layer groups directly to active frontend WebSocket listeners.

⁠🚀 Backend Caching & Session Storage

Configured using django-redis with ZlibCompressor compression and JSONSerializer:

  1. Default Cache DB (redis://.../1):
    • Low-level object and view cache (KEY_PREFIX: fms).
    • Default TTL: 300 seconds.
    • Max connection pool size: 20 connections.
    • Resilience: IGNORE_EXCEPTIONS = True ensures graceful fallback to standard database queries if Redis is offline.
  2. Session Storage DB (redis://.../2):
    • SESSION_ENGINE = "django.contrib.sessions.backends.cache"
    • Dedicated Redis logical database (KEY_PREFIX: fms-session).
    • Session TTL: 24 hours (86400 seconds).

⁠📊 Observability & Health Probes

  • Metrics Scrape: Integrated django_prometheus middleware exposing Prometheus metrics at /metrics.
  • Health Check: Dedicated probe endpoint at /api/health/ handled by HealthCheckMiddleware (bypasses ALLOWED_HOSTS for Kubernetes / Docker compose probes).
  • Execution Logging: RequestTimeLoggingMiddleware records execution latency in JSON format to /app/logs/ and outputs colorized rich console logs during development.

⁠🛠️ Environment Variables Reference

VariableDescriptionDefault
SECRET_KEYDjango application secret keyRequired
JWT_SECRET_KEYKey used to sign JWTsRequired
DEBUGEnable debug modeFalse
API_PORTPort the ASGI server listens on8000
ALLOWED_HOSTSComma-separated allowed hostnameslocalhost,127.0.0.1
CORS_ORIGINSComma-separated allowed frontend originsRequired
DATABASE_ENGINEDatabase driver (postgresql_psycopg2 / sqlite3)sqlite3
DATABASE_NAMEDatabase nameRequired for PostgreSQL
DATABASE_USERNAMEDatabase userRequired for PostgreSQL
DATABASE_PASSWORDDatabase passwordRequired for PostgreSQL
DATABASE_HOSTDatabase hostnameRequired for PostgreSQL
DATABASE_PORTDatabase port5432
REDIS_HOSTRedis hostname (cache, sessions, channel layer)127.0.0.1
REDIS_PORTRedis port6379
GOOGLE_CLIENT_IDOAuth2 Google client IDRequired for auth
GOOGLE_CLIENT_SECRETOAuth2 Google client secretRequired for auth
GOOGLE_CALLBACK_URLOAuth2 redirect/callback URLRequired for auth

Tag summary

Content type

Image

Digest

sha256:4cefd19e0…

Size

49.6 MB

Last updated

17 days ago

docker pull lecroissant2003/fms-backend