How mohamediliasskaddar/imk-monitors works
Project type and purpose
• IMK-Monitors is a full-stack web application (MEAN-style) for automated uptime monitoring of websites.
• Frontend: Angular standalone components, Bootstrap 5, ngx-translate.
• Backend: Node.js + Express, MongoDB (Mongoose), JWT authentication, cron-driven checks, nodemailer alerts.
File structure
• Top-level:
• backend/ (Express server, routes, models, middleware, monitor.js)
• frontend/ (Angular app, standalone components, services, assets for i18n & styling)
• backend/models contain Mongoose schemas (User, Site, Log, Config).
• backend/routes expose REST endpoints (auth, user, site, log, config).
• backend/monitor.js holds the cron job that reads Config → polls sites → writes Log → triggers alerts.
• frontend/src/app/pages maps to feature modules (login, register, dashboard, add-website, user-sites, admin-sites, sites-status, users-list, profile).
• frontend/src/app/services encapsulate API calls (auth.service, user.service, site.service).
• frontend/src/app/shared contains Navbar and Sidebar.
• Angular uses Router (app.routes.ts) and global config files.
README insights
• JWT-protected routes enforce roles (User vs. Admin).
• Global check interval stored in MongoDB Config collection and can be updated at runtime.
• Cron job invoked server-side (node-cron).
• Alerts via nodemailer (email/SMS placeholder).
Main components & relationships
a. Components
• Client Browser
• Angular Frontend
• Presentation Layer (Pages + Shared UI components)
• Services Layer (AuthService, SiteService, UserService)
• REST API (Express Server)
• Routes/Controllers (auth, user, site, log, config)
• Middleware (auth_mdw)
• Business Logic / monitor.js cron job
• Database (MongoDB)
• Collections: users, sites, logs, configs
• External Services
• Email/SMS provider (via nodemailer / Amazon SNS stub)
b. Interactions
1. User actions in browser → Angular components → call AuthService/SiteService/etc.
2. HTTP(S) requests → Express routes → Mongoose models → MongoDB read/write → response to frontend.
3. Cron job (node-cron) periodically executes monitor.js → fetch sites from DB → perform HTTP checks → write logs to DB → if failure threshold → send email/SMS.
4. Admin updates check interval via frontend → configRoute updates Config document → cron job picks up new interval without restart.
c. Architectural patterns
• Layered MVC-style backend (Express Controllers → Mongoose Models → Cron as a service).
• Angular standalone component architecture with Router and Services (separation of Presentation & Data layers).
• Token-based authentication (JWT) with role-based access in middleware.
• Configuration driven cron scheduling.
d. Technologies & frameworks
• Angular 15+ (Standalone Components, Router, ngx-translate)
• Bootstrap 5 for UI, CSS variables for theming (dark/light)
• Node.js + Express.js for REST API
• Mongoose ODM for MongoDB
• jsonwebtoken + bcrypt for auth
• node-cron for scheduling
• nodemailer for alerts