How omar290904/app-backend works
Project type and purpose
• This is a monolithic backend API service (“JALADO BACKEND”) written in Node.js and Express, persisting data in a MySQL database.
• Its core responsibilities are user authentication (JWT + bcrypt + HMAC), attendance management (marking punctual or late), scheduled cron tasks, and integration with WhatsApp for notifications.
File structure
• Top-level files
• .env, package.json/lock, nodemon.json, readme.md
• auth/ folder containing WhatsApp authentication keys and sessions
• src/
• index.js – application entry point, sets up Express server
• config.js – loads environment variables, common configuration
• db/ – MySQL connection (db.js) and SQL schema (jaladope.sql)
• routes/ – Express route definitions grouped by resource (auth, assistance, parents, students, teachers, admin, report, whatsapp)
• controllers/ – handlers for business logic and request processing, mirroring routes
• cron/ – scheduled job (markAbsent.js)
• Whatsapp/ – client.js for WhatsApp API integration
README for additional insights
• Describes routes (POST /login, POST /sign, POST /assistence, upcoming GET endpoints)
• Lists key technologies: Node.js, Express, MySQL, bcrypt, crypto/HMAC, jsonwebtoken, dotenv
• No front-end; strictly an HTTP JSON API plus background jobs and third-party messaging
a. Main components
1. Client Applications (e.g., Web/Mobile)
2. API Gateway / Express Server
3. Route Layer (routes/*.js)
4. Controller Layer (controllers/*.js)
5. Service/Utility modules
– Authentication (JWT issuance/verification, bcrypt, HMAC)
– WhatsApp Client (src/Whatsapp/client.js)
– Cron Scheduler (markAbsent.js)
6. Data Layer
– MySQL Database
– SQL schema (jaladope.sql)
7. External Services
– WhatsApp service (via WhatsApp API)
b. Relationships and data flows
• Clients → HTTP(S) → Express (index.js)
• Express → route dispatcher → controllers
• Controllers → service modules (auth logic, notification logic)
• Controllers → db.js (MySQL queries) → MySQL
• Cron Scheduler → runs markAbsent job at scheduled intervals → controllers/db
• WhatsApp Client ↔ External WhatsApp API
• Auth module issues/verifies JWT on login; controllers enforce token validation
c. Architectural patterns & principles
• Layered architecture (Presentation: routes → Business: controllers → Data: db)
• Single codebase (monolith) with clear separation of concerns
• Dependency injection of config via dotenv
• Scheduled background processing decoupled via cron module
d. Key technologies/frameworks
• Node.js runtime, Express framework
• MySQL via mysql2 or similar driver
• dotenv for config
• jsonwebtoken, bcrypt, crypto for security
• nodemon for development auto-reload
• cron or node-schedule for background tasks
• External WhatsApp API integration