Overview
The permits management system is a Node.js web application built for managing municipal permits (alcohol sales, special events, and advertising). The system uses a traditional MVC architecture with server-side rendering and real-time updates.Technology Stack
Core Dependencies
Technology Details
Technology Details
- Express.js: Web framework for routing and middleware
- MySQL: Relational database (asuntos_publicos)
- EJS: Server-side templating engine
- Socket.io: Real-time bidirectional communication
- bcryptjs: Password hashing and authentication
- multer: Multipart form data handling (file uploads)
- html-pdf + phantomjs: PDF generation from HTML templates
- express-session: Session-based authentication
Directory Structure
Server Initialization
The application starts by initializing Express and configuring middleware:Request Flow
The application follows a standard middleware-based request pipeline:Authentication Check
verifySession middleware ensures user is logged inSource: src/middlewares/verifySession.js
Authorization Check
verifyRoles middleware checks user permissionsSource: src/middlewares/verifyRoles.js
File Upload Handling
The system uses multer for processing file uploads with a two-stage approach:1. Temporary Storage
Files are initially saved to a temporary directory:2. File Movement
After validation, files are moved from temps/ to their final location in the appropriate permit directory.File Upload Flow
File Upload Flow
- Client submits multipart/form-data with file
- Multer middleware intercepts request
- File saved to
/public/server-files/temps/with timestamped name - Route handler validates file and request data
- File moved to final destination (e.g.,
/server-files/asuntos_publicos/permisos_municipales/bebidas/) - Database updated with file path reference
PDF Generation Pipeline
The system generates PDF permits using the html-pdf library with phantomjs as the rendering engine:Database Connection
The application uses a MySQL connection pool for efficient database access:Security Features
Session Management
express-session with server-side storage
Password Hashing
bcryptjs for secure password storage
Role-Based Access
verifyRoles middleware for authorization
Session Validation
verifySession guards protected routes
Related Documentation
Database Schema
Complete database structure and relationships
WebSocket Integration
Real-time communication with Socket.io