Documentation Index
Fetch the complete documentation index at: https://mintlify.com/EdgarJr30/proyecto-de-grado-cms/llms.txt
Use this file to discover all available pages before exploring further.
System Architecture
The MLM CMMS is a modern, full-stack maintenance management system built with a clear separation between frontend and backend concerns. This document provides a comprehensive overview of the system architecture, technology choices, and design patterns.Overview
MLM CMMS is a Computerized Maintenance Management System designed for managing maintenance operations including:- Work requests and work orders (tickets)
- Inventory and spare parts management
- Asset tracking and preventive maintenance
- User management with role-based access control (RBAC)
- Real-time notifications and push messaging
- Reporting and analytics
The system follows a single-page application (SPA) architecture with a PostgreSQL-backed API layer provided by Supabase.
Architecture Diagram
Tech Stack
Frontend
React 19
Modern React with hooks, strict mode, and functional components
TypeScript
Strict type checking with ES2020 target and comprehensive linting
Vite
Fast build tool with HMR, bundler module resolution, and optimized production builds
Tailwind CSS v4
Utility-first CSS framework via @tailwindcss/vite plugin
Key Frontend Libraries
| Library | Purpose | Version |
|---|---|---|
@supabase/supabase-js | Supabase client SDK | ^2.50.0 |
react-router-dom | SPA routing | ^7.6.1 |
framer-motion | Animations | ^12.23.24 |
chart.js + react-chartjs-2 | Data visualization | ^4.5.0 / ^5.3.0 |
@headlessui/react | Accessible UI primitives | ^2.2.4 |
@radix-ui/* | Accessible components | Various |
sweetalert2 | Modal dialogs | ^11.22.0 |
react-toastify | Toast notifications | ^11.0.5 |
Backend (Supabase)
PostgreSQL
Relational database with advanced features (RLS, triggers, functions)
Supabase Auth
JWT-based authentication with session management
Supabase Realtime
WebSocket-based real-time subscriptions to database changes
Edge Functions
Deno-based serverless functions for push notifications
Project Structure
- Frontend (src/)
- Backend (sql/)
- Deployment
Key Design Patterns
1. Service Layer Pattern
All data access is abstracted through service modules insrc/services/. Services handle:
- Supabase client interactions
- Error mapping and handling
- Data transformation
- RPC/function calls
Services provide a clean separation between UI components and data access, enabling easier testing and maintenance.
2. Context Provider Pattern
Global state is managed through React Context providers insrc/context/:
- AuthContext: Authentication state and session management
- UserContext: Current user profile data
- PermissionsContext: RBAC permissions and roles
- SettingsContext: Application settings
- BrandingContext: Multi-tenant branding (logos, colors)
- ThemeContext: Dark/light theme preferences
3. Lazy Route Loading
All page components are lazy-loaded to optimize bundle size:4. Row-Level Security (RLS)
Database security is enforced at the PostgreSQL level using RLS policies. All tables have RLS enabled and policies that check user permissions viapublic.me_has_permission(code).
5. Modular SQL Architecture
The database schema is organized into composable modules:- core_cmms: Foundation (RBAC, tickets, users, notifications)
- assets: Asset management and preventive maintenance
- inventory: Inventory, parts, warehouses, stock movements
Environment Configuration
Frontend Environment Variables
Build Modes
| Command | Mode | Use Case |
|---|---|---|
npm run dev | Development | Local development with HMR |
npm run build | Development | Standard build |
npm run build:qa | QA | QA environment build |
npm run build:prod | Production | Production-optimized build |
Progressive Web App (PWA)
The application includes PWA capabilities:- Service Worker: Registered in production mode (
src/main.tsx:106-123) - Install Prompt: Captured and deferred for custom install UI
- Offline Support: Service worker caching for static assets
- Push Notifications: Web Push API integration with VAPID keys
Service Worker Registration
Security Architecture
Authentication
JWT-based authentication via Supabase Auth with persistent sessions and automatic token refresh.
Authorization
Permission-based access control enforced through:
- Frontend route guards (
ProtectedRoute+RequirePerm) - Backend RLS policies checking
public.me_has_permission(code)
Row-Level Security
All tables have RLS enabled with policies that verify user permissions before allowing data access.
Real-time Features
The system uses Supabase Realtime for live updates:- Notification Deliveries: Real-time notification badge updates
- Ticket Comments: Live comment streams on ticket detail pages
- Change Tracking: Automatic UI updates when data changes
Realtime Configuration
Tables enabled for realtime insql/modules/core_cmms/13_realtime.sql:
notification_deliveries(REPLICA IDENTITY FULL)ticket_comments(REPLICA IDENTITY FULL)
Notification System
Multi-channel notification system with:- In-app Notifications: Notification center with delivery tracking
- Web Push: Browser push notifications via Edge Function
- Outbox Pattern: Reliable message delivery with retry logic
- Deduplication: Prevents duplicate notifications within 5-minute windows
Architecture
sql/modules/core_cmms/16_notifications.sql for implementation details.
Data Invalidation Strategy
The frontend uses a custom invalidation system (src/lib/dataInvalidation.ts) to coordinate cache refreshes across:
- Context providers
- Service layer caches (5-minute TTL)
- Component-level state
permissions, users, tickets, assignees, settings, etc.
Build & Bundle Configuration
Vite Configuration
TypeScript Configuration
- Target: ES2020
- Module: ESNext with bundler resolution
- Strict Mode: Enabled
- JSX: react-jsx (automatic runtime)
- Linting:
noUnusedLocals,noUnusedParameters,noFallthroughCasesInSwitch
tsconfig.app.json for full configuration.
Performance Considerations
The current build reports large chunks. Optimization strategies:
- Lazy loading for all route components
- Scoped imports to reduce bundle size
- Service-level caching (5-minute TTL) to reduce API calls
- Debounced event handlers for input normalization
Input Normalization
Global event listeners handle numeric input normalization:- On Input: Remove leading zeros from integers
- On Blur: Normalize comma to decimal, validate numeric values
src/main.tsx:48-78 for implementation.
Deployment Architecture
SPA Routing
SPA routing depends onpublic/_redirects:
Multi-Environment Support
Environment-specific builds via Vite modes:- Development: Full logging, source maps
- QA: Production-like with QA-specific configs
- Production: Optimized bundles, console suppression (except in dev)
Next Steps
Database Schema
Explore the database structure and table relationships
RBAC System
Learn about the permission-based access control system
Frontend Services
Browse the available services and functions
Installation Guide
Get started with local development