# aiden-lee11/nufood architecture

> Architecture diagram of the GitHub repository aiden-lee11/nufood, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2025-03-29). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/aiden-lee11/nufood
- Repository: https://github.com/aiden-lee11/nufood

## Overview

##### Overall Project Breakdown
- Recognize that this is a full-stack application with a clear separation between a frontend (React/TypeScript) and a backend (Go). It also integrates with third-party services such as Firebase for authentication and likely Twilio for notifications.
- Understand that daily menus are updated via an automated scraping mechanism and that the system deals with real-time data updates.

##### Main Components
a. Frontend:
- React-based UI deployed on Vercel.
- Components such as pages (e.g., Weekly Items, Operation Hours, Favorites) and context providers (for authentication and theme management).
- Use of Vite, Tailwind CSS, and Firebase Authentication.

b. Backend:
- Go-based API server responsible for handling business logic, database interactions, and scraping tasks.
- Split backend functionality into modules:
- API routes (handled in backend/internal/api),
- Database operations (backend/internal/db, PostgreSQL access),
- Authentication verification (using Firebase Admin SDK),
- Scraping service (backend/internal/scraper) for updating daily menus,
- Notification functionalities (backend/internal/twilio) for email/SMS notifications.
- That the backend is deployed on Railway.

c. Database:
- PostgreSQL database instance hosted on Railway.

d. External Services and Tools:
- Firebase: Show the authentication flow. Include both Firebase for user login (in the frontend) and the Firebase Admin SDK for auth verification (in the backend).
- Twilio (if used for notifications): Illustrate its integration with the backend.
- GitHub workflows: Represent the automated schedule/job (as hinted by .github/workflows/schedule-job.yml) that triggers backend tasks such as scraping.

##### Relationships and Interactions
- From end users (clients on mobile/desktop browsers) to the Frontend.
- From the Frontend to the Backend API (for fetching dining hall menus, user favorite activities, etc.).
- From the Backend to the Database for CRUD operations and updates.
- From the Backend to external services (Firebase Admin for authentication verification, Twilio for notifications).
- A separate scheduled task (via GitHub workflows) that triggers the scraper to update menu information.

##### Architectural Patterns and Design Principles
- A clear separation of concerns: presentation (frontend), business logic (backend API), data persistence (PostgreSQL), and external communication (Firebase, Twilio).
- If applicable, note that the backend modules are organized in a modular structure (for example, "api", "db", "auth", "scraper") which suggests a layered architecture.
- That the real-time data updates and scheduled scraping indicate asynchronous background processing.

##### Relevant Technologies and Frameworks
- Frontend: React, TypeScript, Vite, Tailwind CSS, Firebase Authentication.
- Backend: Go (with clear separation into API, middleware, and scraping components), PostgreSQL, Firebase Admin SDK, and possibly Twilio.
- Deployment: Vercel for the frontend, Railway for the backend and database.

##### Additional Detailed Elements
- In the frontend section, you might break down logical groupings such as “Pages”, “Components”, “Context Providers”, and “Firebase integration”.
- Do not forget to include auxiliary elements like GitHub workflows/schedulers that play an essential role in regular data updates.

## Diagram (Mermaid)

```mermaid
flowchart TD
    %% Global Nodes
    EndUser("End User"):::external

    %% Frontend Layer
    subgraph "Frontend (React/Vercel)"
        FE("React Frontend (Vercel)"):::frontend
        Pages("Pages (Weekly,Daily,OperationHours,Favorites)"):::frontend
        Context("Context Providers (Auth/Theme)"):::frontend
        FEFirebase("Firebase Integration (User Login)"):::frontend
    end

    %% Backend Layer
    subgraph "Backend (Go/Railway)"
        BE("Go API Backend (Railway)"):::backend
        APIRoutes("API Routes"):::backend
        DBOps("Database Operations"):::backend
        Auth("Authentication (Firebase Admin SDK)"):::backend
        Scraper("Scraping Service"):::backend
        Notification("Notification Service (Twilio)"):::backend
    end

    %% Database and External Services
    Database("PostgreSQL Database (Railway PostgreSQL)"):::database
    Firebase("Firebase Auth Service"):::external
    Twilio("Twilio Notifications"):::external
    GitHub("GitHub Scheduler"):::external

    %% Connections
    EndUser -->|"access"| FE
    FE -->|"fetchData"| BE
    Pages --- FE
    Context --- FE
    FEFirebase --- FE
    FEFirebase -->|"calls"| Firebase

    BE -->|"handlesRoutes"| APIRoutes
    BE -->|"performsCRUD"| DBOps
    BE -->|"verifiesAuth"| Auth
    BE -->|"triggersScraping"| Scraper
    BE -->|"sendsNotifications"| Notification

    DBOps -->|"queries"| Database
    Auth -->|"verifiesVia"| Firebase
    Notification -->|"sendsVia"| Twilio
    GitHub -->|"triggers"| Scraper

    %% Styles
    classDef frontend fill:#a2d5f2,stroke:#333,stroke-width:2px;
    classDef backend fill:#f4a261,stroke:#333,stroke-width:2px;
    classDef database fill:#e9c46a,stroke:#333,stroke-width:2px;
    classDef external fill:#2a9d8f,stroke:#333,stroke-width:2px;

    %% Click Events
    click FE "https://github.com/aiden-lee11/nufood/tree/master/frontend"
    click Pages "https://github.com/aiden-lee11/nufood/tree/master/frontend/src/pages"
    click Context "https://github.com/aiden-lee11/nufood/tree/master/frontend/src/context"
    click FEFirebase "https://github.com/aiden-lee11/nufood/tree/master/frontend/src/firebase"
    click BE "https://github.com/aiden-lee11/nufood/tree/master/backend"
    click APIRoutes "https://github.com/aiden-lee11/nufood/blob/master/backend/internal/api/api.go"
    click DBOps "https://github.com/aiden-lee11/nufood/tree/master/backend/internal/db"
    click Auth "https://github.com/aiden-lee11/nufood/blob/master/backend/internal/auth/auth.go"
    click Scraper "https://github.com/aiden-lee11/nufood/tree/master/backend/internal/scraper"
    click Notification "https://github.com/aiden-lee11/nufood/tree/master/backend/internal/twilio"
    click GitHub "https://github.com/aiden-lee11/nufood/blob/master/.github/workflows/schedule-job.yml"
```
