# akshay-gurav-31/expirytracker-pro architecture

> Architecture diagram of the GitHub repository akshay-gurav-31/expirytracker-pro, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2025-11-28). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/akshay-gurav-31/expirytracker-pro
- Repository: https://github.com/akshay-gurav-31/expirytracker-pro

## Overview

##### Project Type and Purpose
- This is a single-page, client-heavy web application (“modern web app”) built with vanilla JavaScript and static HTML/CSS pages.
- It uses Supabase as its backend (authentication, PostgreSQL database, real-time synchronization, and object storage).
- Key user flows: signup/login, CRUD operations on items with expiry dates, real-time updates, profile management, notifications, image upload, import/export.

##### File Structure
- Top-level HTML entry points: login.html, signup.html, dashboard.html, profile.html
- JavaScript modules for feature areas:
- auth.js (authentication logic)
- dashboard.js (item list, add/edit/delete, filtering)
- profile.js (avatar upload, settings)
- notifications.js (trigger browser alerts)
- utils.js (shared helpers)
- config.js (Supabase URL and anon key)
- CSS organization: style.css + per-page files under styles/
- database-schema.sql defines tables and storage policies for avatars and item images.

##### README for Additional Insights
- Authentication: Supabase Auth with email confirmation and RLS policies
- Database: PostgreSQL
- Storage: Supabase Storage buckets (“avatars”, “items”)
- Real-time: uses Supabase Realtime to push DB changes to clients
- Browser Notifications: Notification API integration
- Import/Export: JSON file persisted locally (no backend storage)

##### Main Components and Their Relationships
a. Client (Browser)
- Static assets served by any web server (Live Server in dev, S3/Netlify in prod)
- HTML pages load JS modules that call Supabase client library
b. Supabase Platform
- Auth Service (signup, login, JWT issuance)
- Database (PostgreSQL + RLS policies)
- Realtime Layer (WebSocket push of table changes)
- Storage Service (public buckets for avatars & item images)
- Email Delivery (managed by Supabase for confirmations)
c. Browser Notifications API
- Subscribed by notifications.js after user opt-in
d. Local File System (Import/Export)
- JSON read/write via utils.js

##### Data Flow and Interactions
1. User loads login.html ⇒ auth.js calls Supabase Auth.signIn/signUp APIs
2. Supabase Auth returns JWT ⇒ stored in browser (localStorage or Supabase client)
3. User navigates to dashboard.html ⇒ dashboard.js subscribes to Realtime tables, fetches item data
4. CRUD operations on items ⇒ REST calls to Supabase Database
5. Image upload ⇒ HTTP PUT to Supabase Storage bucket “items” or “avatars”
6. Database triggers real-time broadcasts ⇒ dashboard.js updates UI immediately
7. notifications.js schedules browser notifications based on item expiry dates
8. Profile updates ⇒ profile.js modifies user metadata and avatar in Storage
9. Import/Export ⇒ utils.js serializes item data to JSON / restores it

##### Architectural Patterns and Design Principles
- Frontend-centric: thin static host, all business logic in client
- BaaS (Backend-as-a-Service): Supabase for all backend needs
- Event-driven UI: real-time DB subscriptions for instant sync
- Separation of concerns: distinct modules for auth, dashboard, profile, notifications, utils
- Security: RLS policies, email verification, secure public buckets

## Diagram (Mermaid)

```mermaid
flowchart TD
    %% Browser Client
    subgraph "Browser (Client)"
        direction TB
        subgraph "HTML Pages" 
            direction TB
            Login["login.html"]:::client
            Signup["signup.html"]:::client
            DashboardPage["dashboard.html"]:::client
            ProfilePage["profile.html"]:::client
            Index["index.html"]:::client
        end
        subgraph "JS Modules"
            direction TB
            AuthJS["auth.js"]:::client
            DashboardJS["dashboard.js"]:::client
            ProfileJS["profile.js"]:::client
            NotificationsJS["notifications.js"]:::client
            UtilsJS["utils.js"]:::client
            ConfigJS["config.js"]:::client
        end
        subgraph "Styles & Assets"
            direction TB
            GlobalCSS["style.css"]:::client
            AuthCSS["styles/auth.css"]:::client
            DashboardCSS["styles/dashboard.css"]:::client
            ProfileCSS["styles/profile.css"]:::client
            ImagesFolder["images/"]:::client
        end
    end

    %% Supabase Backend
    subgraph "Supabase Platform"
        direction TB
        AuthService["Auth Service"]:::supabase
        Database["PostgreSQL Database\n(+ RLS)"]:::supabase
        Realtime["Realtime Engine"]:::supabase
        subgraph "Storage"
            direction TB
            AvatarsBucket["avatars (bucket)"]:::supabase
            ItemsBucket["items (bucket)"]:::supabase
        end
    end

    %% External Services
    EmailService["Email Service"]:::external
    BrowserNotifAPI["Browser Notifications API"]:::external
    LocalFS["Local File System\n(JSON Import/Export)"]:::external
    Schema["database-schema.sql"]:::client

    %% Connections
    Login -->|loads| AuthJS
    Signup -->|loads| AuthJS
    DashboardPage -->|loads| DashboardJS
    ProfilePage -->|loads| ProfileJS

    AuthJS -->|calls signup/login| AuthService
    AuthService -->|returns JWT| AuthJS

    DashboardJS -->|fetches items CRUD| Database
    DashboardJS -->|subscribes| Realtime
    Realtime -->|push updates| DashboardJS

    DashboardJS -->|upload image| ItemsBucket
    ProfileJS -->|upload avatar| AvatarsBucket

    NotificationsJS -->|uses| BrowserNotifAPI

    UtilsJS -->|reads/writes JSON| LocalFS

    Schema -->|defines tables/policies| Database

    AuthService -->|sends confirmation| EmailService

    %% Click Events
    click Login "https://github.com/akshay-gurav-31/expirytracker-pro/blob/main/login.html"
    click Signup "https://github.com/akshay-gurav-31/expirytracker-pro/blob/main/signup.html"
    click DashboardPage "https://github.com/akshay-gurav-31/expirytracker-pro/blob/main/dashboard.html"
    click ProfilePage "https://github.com/akshay-gurav-31/expirytracker-pro/blob/main/profile.html"
    click Index "https://github.com/akshay-gurav-31/expirytracker-pro/blob/main/index.html"
    click AuthJS "https://github.com/akshay-gurav-31/expirytracker-pro/blob/main/auth.js"
    click DashboardJS "https://github.com/akshay-gurav-31/expirytracker-pro/blob/main/dashboard.js"
    click ProfileJS "https://github.com/akshay-gurav-31/expirytracker-pro/blob/main/profile.js"
    click NotificationsJS "https://github.com/akshay-gurav-31/expirytracker-pro/blob/main/notifications.js"
    click UtilsJS "https://github.com/akshay-gurav-31/expirytracker-pro/blob/main/utils.js"
    click ConfigJS "https://github.com/akshay-gurav-31/expirytracker-pro/blob/main/config.js"
    click GlobalCSS "https://github.com/akshay-gurav-31/expirytracker-pro/blob/main/style.css"
    click AuthCSS "https://github.com/akshay-gurav-31/expirytracker-pro/blob/main/styles/auth.css"
    click DashboardCSS "https://github.com/akshay-gurav-31/expirytracker-pro/blob/main/styles/dashboard.css"
    click ProfileCSS "https://github.com/akshay-gurav-31/expirytracker-pro/blob/main/styles/profile.css"
    click ImagesFolder "https://github.com/akshay-gurav-31/expirytracker-pro/tree/main/images/"
    click Schema "https://github.com/akshay-gurav-31/expirytracker-pro/blob/main/database-schema.sql"

    %% Styles
    classDef client fill:#e0ffe0,stroke:#2d7a2d
    classDef supabase fill:#e0f0ff,stroke:#2378b5
    classDef external fill:#fff5e6,stroke:#b56e23
```
