# rahatahmed171/food-expiry-tracker architecture

> Architecture diagram of the GitHub repository rahatahmed171/food-expiry-tracker, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2025-05-11). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/rahatahmed171/food-expiry-tracker
- Repository: https://github.com/rahatahmed171/food-expiry-tracker

## Overview

##### 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

## Diagram (Mermaid)

```mermaid
flowchart TB
    %% Client Layer
    subgraph "Client (Browser)"
        Login["Login Page"]:::frontend
        Register["Register Page"]:::frontend
        Home["Home Page"]:::frontend
    end

    %% Backend Server
    subgraph "Backend Server"
        Auth["Auth Module\n(/register, /login)"]:::backend
        CRUD["CRUD Module\n(/add_a_product, /update, /delete, /display_all)"]:::backend
    end

    Scheduler["Scheduler Process\n(schedule_task.js)"]:::backend

    subgraph "Notification Subsystem"
        Notifier["ExpiryDateNotifier"]:::backend
        Email["EmailSender"]:::backend
    end

    %% Database
    DB["MySQL Database\n(User & Product Tables)"]:::database

    %% External Services
    ExtEmail["Gmail SMTP\n(External Email Service)"]:::external

    %% Data Flows
    Login -->|"HTTP POST\nFormData"| Auth
    Register -->|"HTTP POST\nFormData"| Auth
    Auth -->|"issues JWT"| Home
    Home -->|"HTTP POST\nFormData"| CRUD

    Auth -->|"Sequelize CRUD"| DB
    CRUD -->|"Sequelize CRUD"| DB

    Scheduler -->|"triggers notification check"| Notifier
    Notifier -->|"uses"| Email
    Email -->|"SMTP"| ExtEmail

    %% Click Events
    click Login "https://github.com/rahatahmed171/food-expiry-tracker/blob/master/static/login.html"
    click Register "https://github.com/rahatahmed171/food-expiry-tracker/blob/master/static/register.html"
    click Home "https://github.com/rahatahmed171/food-expiry-tracker/blob/master/static/home.html"
    click Auth "https://github.com/rahatahmed171/food-expiry-tracker/blob/master/auth.js"
    click Scheduler "https://github.com/rahatahmed171/food-expiry-tracker/blob/master/schedule_task.js"
    click Email "https://github.com/rahatahmed171/food-expiry-tracker/blob/master/email_sender.js"
    click DB "https://github.com/rahatahmed171/food-expiry-tracker/blob/master/databases/users.js"
    click DB "https://github.com/rahatahmed171/food-expiry-tracker/blob/master/databases/products.js"

    %% Styles
    classDef frontend fill:#a2d2ff,stroke:#333,stroke-width:1px;
    classDef backend fill:#d0f4de,stroke:#333,stroke-width:1px;
    classDef database fill:#ffafcc,stroke:#333,stroke-width:1px;
    classDef external fill:#ffd6a5,stroke:#333,stroke-width:1px;
```
