How rahatahmed171/food-expiry-tracker works
Project type and purpose
• This is a full-stack web application (“Food Expiry Tracker App”) built with Vanilla Node.js (backend), static HTML/CSS (frontend), Sequelize ORM and MySQL (database), and cron-based scheduled tasks with email notifications.
• Purpose: allow users to register/login, perform CRUD operations on their food products, and receive automated email alerts three days before product expiry.
File structure
• Top-level entry points:
• auth.js – main HTTP server handling authentication, JWT issuance, and API endpoints for CRUD and store info
• schedule_task.js – cron job scheduler that periodically checks for near-expiry products
• email_sender.js – encapsulates email delivery logic (using Nodemailer)
• Static UI:
• static/*.html – login.html, register.html, home.html
• Database models and setup:
• databases/users.js, databases/products.js – Sequelize connection and schema definitions
• models/users_model.js, models/products_model.js – ORM model files, sync routines
• Tests:
• test/*.js – Mocha/Chai unit tests for authentication
• Configuration:
• package.json / package-lock.json – dependencies (Sequelize, JWT, bcrypt, node-cron, nodemailer, etc.)
• .env – holds ACCESS_TOKEN_SECRET, email credentials
Extract key architectural insights from README
• Two main verticals: Authentication/Authorization and Core Application Logic (CRUD + notifications)
• Observer pattern for notifications: Notifier (abstract) → ExpiryDateNotifier → uses EmailSender
• API endpoints are all HTTP POST operations with FormData requests, protected via JWT.
a. Components to include:
• Client (Browser) – static HTML/CSS, JavaScript code making FormData HTTP requests
• Node.js Server (auth.js)
– Auth Module (registration/login, JWT validation)
– CRUD Module (ProductInserterDeleter, ProductUpdater, ProductDisplayer)
• Scheduler Process (schedule_task.js)
• Notification Subsystem
– ExpiryDateNotifier (Observer)
– EmailSender
• Database (MySQL via Sequelize) – User table, Product table
• External Email Service (Gmail SMTP via Nodemailer)
b. Relationships and data flows:
1. Browser → Server: HTTP POST (FormData) → endpoints (/login, /register, /add_a_product, etc.)
2. Server ↔ Database: Sequelize ORM models perform queries/updates on User and Product tables
3. Server → Browser: JSON responses with messages, JWT tokens, product lists
4. Scheduler → Server Modules: schedule_task.js triggers ExpiryDateNotifier logic
5. ExpiryDateNotifier → EmailSender → External Email Service → User’s Email
c. Architectural patterns and principles:
• MVC-like separation: Controller (auth.js endpoints) → Model (Sequelize) → “View” is static HTML/JSON
• Observer pattern for notifications (Notifier → concrete notifier)
• Layered security: JWT-based authentication and authorization layer
• Cron scheduler for background jobs
d. Key technologies to annotate:
• Node.js, Express-style routing in auth.js
• Sequelize ORM, MySQL
• JWT (jsonwebtoken) and bcrypt
• node-cron
• Nodemailer for emails
• Static HTML/CSS frontend
Final recommendations
• Be detailed: capture all API endpoints and background tasks
• Data flow: show how data moves from user input → DB → scheduled checks → email alerts
• Extensibility: leave room to add future notification channels (SMS, push) by showing EmailSender as one concrete strategy of a Notifier interface