# abikrit18/p-40-underdog-project architecture

> Architecture diagram of the GitHub repository abikrit18/p-40-underdog-project, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2025-06-10). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/abikrit18/p-40-underdog-project
- Repository: https://github.com/abikrit18/p-40-underdog-project

## Overview

##### Project type and purpose
- This is a full-stack web application (“P-40-Underdog-Project”) for a dog shelter’s walk-booking system.
- Backend is a Node.js/Express REST API; frontend is a React single-page app built with Vite; database is MongoDB; image storage is Cloudinary; notification systems include email and Web Push.

##### File structure
- Top-level folders:
- backend/ (Express server, MVC layers: config, controllers, middleware, models, routes, services, scripts)
- frontend/ (React app: public assets & service worker, src folder with Pages, components, context, styles, utils, config)
- root contains global tests and package configs.
- Architectural patterns:
- Backend uses MVC (models → controllers → routes → services → database)
- Frontend uses component-based UI with a Context for notifications and a service worker for push.
- Configuration & deployment files: .env files, cloudinary.js, vercel.json, tailwind.config.js, vite.config.js.

##### README insights
- Confirms the tech stack and outlines deployment steps.
- Mentions external dependencies: MongoDB Atlas, Cloudinary, VAPID keys for Web Push, email (Gmail SMTP).

## Diagram (Mermaid)

```mermaid
flowchart TB
    %% Client Layer
    subgraph "Client (Browser)"
        direction TB
        SPA["React SPA"]:::frontend
        subgraph "Notification System" 
            direction TB
            Context["Notification Context"]:::frontend
            Manager["PushNotificationManager"]:::frontend
            Bell["NotificationBell"]:::frontend
            Panel["NotificationPanel"]:::frontend
        end
        SW["Service Worker"]:::frontend
    end

    %% Backend Layer
    subgraph "Backend Service"
        direction TB
        Config["Environment Config & Cloudinary"]:::backend
        AuthMW["Auth Middleware"]:::backend

        subgraph "Routes"
            direction TB
            UR["userRoutes"]:::backend
            WR["walkRoutes"]:::backend
            NR["notificationRoutes"]:::backend
            PNR["pushNotificationRoutes"]:::backend
            ER["emailRoutes"]:::backend
            URP["uploadRoutes"]:::backend
            DR["dogRoutes"]:::backend
            DSR["dogStatsRoutes"]:::backend
            STR["shelterTimeRoutes"]:::backend
        end

        subgraph "Controllers"
            direction TB
            UC["userController"]:::backend
            NC["notificationController"]:::backend
            PNC["pushNotificationController"]:::backend
        end

        subgraph "Services"
            direction TB
            ES["emailService"]:::backend
            PNS["pushNotificationService"]:::backend
        end

        subgraph "Models (MongoDB Schemas)"
            direction TB
            MUser["User"]:::backend
            MUserWalk["UserWalk"]:::backend
            MWalk["Walk"]:::backend
            MWalkLog["WalkLog"]:::backend
            MPushSub["PushSubscription"]:::backend
            MNotification["Notification"]:::backend
            MShelterTime["ShelterTime"]:::backend
        end

        Script["Migration Script"]:::backend
        Server["Express Server (server.js)"]:::backend
    end

    %% Database and External Services
    subgraph "External Services"
        direction TB
        MongoDB[(MongoDB Atlas)]:::external
        Cloudinary["Cloudinary API"]:::external
        SMTP["SMTP Email"]:::external
        VAPID["Web-Push Gateway"]:::external
    end

    %% Client to Backend
    SPA -->|"HTTP Requests"| UR
    SPA -->|"HTTP Requests"| WR
    SPA -->|"HTTP Requests"| NR
    SPA -->|"HTTP Requests"| PNR
    SPA -->|"HTTP Requests"| ER
    SPA -->|"HTTP Requests"| URP
    SPA -->|"HTTP Requests"| DR
    SPA -->|"HTTP Requests"| DSR
    SPA -->|"HTTP Requests"| STR

    %% Notification Flow
    SPA -->|"Subscribe"| PNR
    VAPID -->|"Push Messages"| SW
    PNS -->|"Send Push"| VAPID

    %% Backend internal flow
    UR --> UC
    WR --> UC
    NR --> NC
    PNR --> PNC
    ER --> UC
    URP --> UC
    DR --> UC
    DSR --> UC
    STR --> UC

    AuthMW --> UR
    AuthMW --> WR
    AuthMW --> NR
    AuthMW --> PNR
    AuthMW --> ER
    AuthMW --> URP
    AuthMW --> DR
    AuthMW --> DSR
    AuthMW --> STR

    UC --> ES
    UC --> PNS
    NC --> PNS
    PNC --> PNS

    ES --> SMTP
    PNS --> VAPID

    UC --> MUser
    UC --> MUserWalk
    UC --> MWalk
    UC --> MWalkLog
    NC --> MNotification
    PNC --> MPushSub
    UC --> MShelterTime

    MUser --> MongoDB
    MUserWalk --> MongoDB
    MWalk --> MongoDB
    MWalkLog --> MongoDB
    MPushSub --> MongoDB
    MNotification --> MongoDB
    MShelterTime --> MongoDB

    Server --> UR
    Server --> AuthMW
    Server --> Config
    Server --> Script

    %% Client click events
    click SPA "https://github.com/abikrit18/p-40-underdog-project/blob/main/frontend/src/App.jsx"
    click SPA "https://github.com/abikrit18/p-40-underdog-project/blob/main/frontend/src/main.jsx"
    click SPA "https://github.com/abikrit18/p-40-underdog-project/blob/main/frontend/index.html"
    click Context "https://github.com/abikrit18/p-40-underdog-project/blob/main/frontend/src/context/NotificationContext.jsx"
    click Manager "https://github.com/abikrit18/p-40-underdog-project/blob/main/frontend/src/components/PushNotificationManager.jsx"
    click Bell "https://github.com/abikrit18/p-40-underdog-project/blob/main/frontend/src/components/NotificationBell.jsx"
    click Panel "https://github.com/abikrit18/p-40-underdog-project/blob/main/frontend/src/components/NotificationPanel.jsx"
    click SW "https://github.com/abikrit18/p-40-underdog-project/blob/main/frontend/public/service-worker.js"
    click SPA "https://github.com/abikrit18/p-40-underdog-project/tree/main/frontend/src/Pages/"
    click SPA "https://github.com/abikrit18/p-40-underdog-project/tree/main/frontend/src/components/"
    click SPA "https://github.com/abikrit18/p-40-underdog-project/blob/main/frontend/src/utils/dateUtils.js"
    click SPA "https://github.com/abikrit18/p-40-underdog-project/blob/main/frontend/src/styles/notifications.css"
    click SPA "https://github.com/abikrit18/p-40-underdog-project/blob/main/frontend/tailwind.config.js"
    click SPA "https://github.com/abikrit18/p-40-underdog-project/blob/main/frontend/vite.config.js"

    %% Backend click events
    click Server "https://github.com/abikrit18/p-40-underdog-project/blob/main/backend/server.js"
    click Config "https://github.com/abikrit18/p-40-underdog-project/blob/main/backend/.env"
    click Config "https://github.com/abikrit18/p-40-underdog-project/blob/main/backend/config/cloudinary.js"
    click UR "https://github.com/abikrit18/p-40-underdog-project/blob/main/backend/routes/userRoutes.js"
    click WR "https://github.com/abikrit18/p-40-underdog-project/blob/main/backend/routes/walkRoutes.js"
    click NR "https://github.com/abikrit18/p-40-underdog-project/blob/main/backend/routes/notificationRoutes.js"
    click PNR "https://github.com/abikrit18/p-40-underdog-project/blob/main/backend/routes/pushNotificationRoutes.js"
    click ER "https://github.com/abikrit18/p-40-underdog-project/blob/main/backend/routes/emailRoutes.js"
    click URP "https://github.com/abikrit18/p-40-underdog-project/blob/main/backend/routes/uploadRoutes.js"
    click DR "https://github.com/abikrit18/p-40-underdog-project/blob/main/backend/routes/dogRoutes.js"
    click DSR "https://github.com/abikrit18/p-40-underdog-project/blob/main/backend/routes/dogStatsRoutes.js"
    click STR "https://github.com/abikrit18/p-40-underdog-project/blob/main/backend/routes/shelterTimeRoutes.js"
    click UC "https://github.com/abikrit18/p-40-underdog-project/blob/main/backend/controllers/userController.js"
    click NC "https://github.com/abikrit18/p-40-underdog-project/blob/main/backend/controllers/notificationController.js"
    click PNC "https://github.com/abikrit18/p-40-underdog-project/blob/main/backend/controllers/pushNotificationController.js"
    click ES "https://github.com/abikrit18/p-40-underdog-project/blob/main/backend/services/emailService.js"
    click PNS "https://github.com/abikrit18/p-40-underdog-project/blob/main/backend/services/pushNotificationService.js"
    click MUser "https://github.com/abikrit18/p-40-underdog-project/blob/main/backend/models/User.js"
    click MUserWalk "https://github.com/abikrit18/p-40-underdog-project/blob/main/backend/models/UserWalk.js"
    click MWalk "https://github.com/abikrit18/p-40-underdog-project/blob/main/backend/models/walk.js"
    click MWalkLog "https://github.com/abikrit18/p-40-underdog-project/blob/main/backend/models/walkLog.js"
    click MPushSub "https://github.com/abikrit18/p-40-underdog-project/blob/main/backend/models/PushSubscription.js"
    click MNotification "https://github.com/abikrit18/p-40-underdog-project/blob/main/backend/models/Notification.js"
    click MShelterTime "https://github.com/abikrit18/p-40-underdog-project/blob/main/backend/models/ShelterTime.js"
    click AuthMW "https://github.com/abikrit18/p-40-underdog-project/blob/main/backend/middleware/auth.js"
    click Script "https://github.com/abikrit18/p-40-underdog-project/blob/main/backend/scripts/migrateWalksToUserWalks.js"
    click Server "https://github.com/abikrit18/p-40-underdog-project/blob/main/backend/package.json"
    click Server "https://github.com/abikrit18/p-40-underdog-project/blob/main/backend/package-lock.json"

    %% External click events
    click MongoDB "https://github.com/abikrit18/p-40-underdog-project/blob/main/README.md"
    click SMTP "https://github.com/abikrit18/p-40-underdog-project/blob/main/.gitignore"
    click SMTP "https://github.com/abikrit18/p-40-underdog-project/blob/main/package.json"
    click SMTP "https://github.com/abikrit18/p-40-underdog-project/blob/main/package-lock.json"

    %% Styles
    classDef frontend fill:#cce5ff,stroke:#333,stroke-width:1px
    classDef backend fill:#d4edda,stroke:#333,stroke-width:1px
    classDef external fill:#fff3cd,stroke:#333,stroke-width:1px
```
