# sachinggsingh/pawperfection architecture

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

- Interactive diagram: https://gitdiagram.com/sachinggsingh/pawperfection
- Repository: https://github.com/sachinggsingh/pawperfection

## Overview

##### Project type and purpose
- PawPerfection is a full-stack web application for personalized pet training.
- The frontend is built with React (Vite, Redux, Tailwind CSS), and the backend uses Node.js/Express with a MongoDB Atlas database. Authentication is handled via JWT/OAuth.

##### File structure
- Top level: two main directories, `Backend` and `Frontend/client`.
- Backend follows an MVC-style layout:
- `/controllers` – request handlers
- `/models` – Mongoose schemas for users, pets, training programs
- `/routes` – Express routers (user, pet, training)
- `/middleware/auth.js` – JWT validation
- `index.js` – application entry point, Express server setup
- Frontend is a single-page React app under `client`:
- `/components`, `/pages` – presentational and page components
- `/redux` – Redux slice for auth and store configuration
- `/util/api.js` – central API client for making HTTP calls
- Vite config and HTML entry point
- Common configuration: `.gitignore`, `package.json` files in both root and subdirectories.

##### Key architecture points from the README
- REST API layer (Express)
- MongoDB Atlas for data persistence
- JWT and third-party OAuth for authentication
- Cross-platform client (web) with offline mode (service workers or local cache)
- CI/CD via GitHub Actions (implied)

##### Main components
a. Frontend Application
- React SPA (pages, components, Redux store)
- Service worker or local storage for offline mode
b. API Gateway (Express server)
- Route handlers → Controllers → Models
- Auth middleware (JWT / OAuth integration)
c. Database
- MongoDB Atlas cluster (collections: users, pets, trainingPrograms)
d. External Services
- OAuth provider (Google/Facebook)
- Email/Notification service (reminders, schedules)
- Video CDN (host training tutorials)
e. CI/CD Pipeline
- GitHub Actions for build/test/deploy

##### Relationships & data flow
- User’s browser ↔ (HTTPS) → React frontend
- Frontend dispatches Redux actions → util/api.js → Express REST endpoints
- Express middleware validates JWT, calls controllers
- Controllers query/update MongoDB via models
- Controllers return JSON → frontend updates UI
- Offline mode: service worker intercepts network calls, serves cached assets/data
- For authentication: frontend redirects to OAuth provider, receives token, stores in Redux

##### Architectural patterns & design principles
- Client–Server separation (React vs. Express)
- MVC on the backend
- Flux (Redux) on the frontend
- RESTful API design
- Layered security: JWT, auth middleware
- Modular, folder-based separation of concerns

##### Detail level
- Major folder as a component: controllers, models, routes
- Redux store and API utility as separate pieces in the frontend
- Middleware chain in the backend
- Don’t overcomplicate—focus on clear, logical separation of concerns

## Diagram (Mermaid)

```mermaid
flowchart TD
    %% Client Layer
    subgraph "Client Layer" 
        direction TB
        Browser["User's Browser"]:::external
        HTML["HTML Entry Point"]:::frontend
        Main["React Entry Point (main.jsx)"]:::frontend
        Pages["React Pages"]:::frontend
        Components["Presentational Components"]:::frontend
        Store["Redux Store Config"]:::frontend
        LoginSlice["Auth Redux Slice"]:::frontend
        APIUtil["API Client Utility"]:::frontend
        SW["Service Worker / Offline Handler"]:::frontend
    end

    %% API Layer
    subgraph "API Layer" 
        direction TB
        Server["API Gateway (Express)"]:::api
        AuthMW["Auth Middleware (JWT/OAuth)"]:::api
        subgraph "Routes"
            direction TB
            UserRoutes["User Routes"]:::api
            PetRoutes["Pet Routes"]:::api
            TrainingRoutes["Training Routes"]:::api
        end
        subgraph "Controllers"
            direction TB
            UserCTRL["User Controller"]:::api
            PetCTRL["Pet Controller"]:::api
            TrainingCTRL["Training Controller"]:::api
        end
        subgraph "Models"
            direction TB
            UserModel["User Model"]:::data
            PetModel["Pet Model"]:::data
            TrainingModel["Training Program Model"]:::data
        end
    end

    %% Data Layer
    DB["MongoDB Atlas"]:::data

    %% External Services
    subgraph "External Services"
        direction TB
        OAuth["OAuth Provider"]:::external
        EmailService["Email/Notification Service"]:::external
        VideoCDN["Video CDN"]:::external
    end

    %% CI/CD
    CICD["GitHub Actions (CI/CD)"]:::cicd

    %% Connections
    Browser -->|"loads"| HTML
    HTML -->|"mounts"| Main
    Main -->|"renders"| Pages
    Main -->|"uses"| Components
    Pages -->|"dispatches"| Store
    Components -->|"dispatches"| Store
    Store -->|"calls"| APIUtil
    APIUtil -->|"HTTP requests"| Server
    Server -->|"uses"| AuthMW
    Server -->|"routes to"| UserRoutes
    Server -->|"routes to"| PetRoutes
    Server -->|"routes to"| TrainingRoutes
    UserRoutes -->|"calls"| UserCTRL
    PetRoutes -->|"calls"| PetCTRL
    TrainingRoutes -->|"calls"| TrainingCTRL
    AuthMW -->|"verifies token"| OAuth
    UserCTRL -->|"queries"| UserModel
    PetCTRL -->|"queries"| PetModel
    TrainingCTRL -->|"queries"| TrainingModel
    UserCTRL -->|"sends email"| EmailService
    TrainingCTRL -->|"fetches video"| VideoCDN
    UserModel -->|"reads/writes"| DB
    PetModel -->|"reads/writes"| DB
    TrainingModel -->|"reads/writes"| DB
    SW -->|"intercepts"| APIUtil
    CICD -->|"build/test/deploy"| Server
    CICD -->|"build/test/deploy"| Main

    %% Click Events
    click HTML "https://github.com/sachinggsingh/pawperfection/blob/main/Frontend/client/index.html"
    click Main "https://github.com/sachinggsingh/pawperfection/blob/main/Frontend/client/src/main.jsx"
    click Pages "https://github.com/sachinggsingh/pawperfection/tree/main/Frontend/client/src/pages"
    click Components "https://github.com/sachinggsingh/pawperfection/tree/main/Frontend/client/src/components"
    click Store "https://github.com/sachinggsingh/pawperfection/blob/main/Frontend/client/src/redux/store.js"
    click LoginSlice "https://github.com/sachinggsingh/pawperfection/blob/main/Frontend/client/src/redux/auth/loginSlice.js"
    click APIUtil "https://github.com/sachinggsingh/pawperfection/blob/main/Frontend/client/src/util/api.js"
    click Server "https://github.com/sachinggsingh/pawperfection/blob/main/Backend/index.js"
    click UserCTRL "https://github.com/sachinggsingh/pawperfection/blob/main/Backend/controllers/userCTRL.js"
    click PetCTRL "https://github.com/sachinggsingh/pawperfection/blob/main/Backend/controllers/petCTRL.js"
    click TrainingCTRL "https://github.com/sachinggsingh/pawperfection/blob/main/Backend/controllers/trainingCTRL.js"
    click UserModel "https://github.com/sachinggsingh/pawperfection/blob/main/Backend/models/user.js"
    click PetModel "https://github.com/sachinggsingh/pawperfection/blob/main/Backend/models/petModel.js"
    click TrainingModel "https://github.com/sachinggsingh/pawperfection/blob/main/Backend/models/trainingProgram.js"
    click UserRoutes "https://github.com/sachinggsingh/pawperfection/blob/main/Backend/routes/userRoutes.js"
    click PetRoutes "https://github.com/sachinggsingh/pawperfection/blob/main/Backend/routes/petRoute.js"
    click TrainingRoutes "https://github.com/sachinggsingh/pawperfection/blob/main/Backend/routes/trainingRoutes.js"
    click AuthMW "https://github.com/sachinggsingh/pawperfection/blob/main/Backend/middleware/auth.js"
    click CICD "https://github.com/sachinggsingh/pawperfection/blob/main/README.md"

    %% Styles
    classDef frontend fill:#E0F7FA,stroke:#006064,color:#004D40
    classDef api fill:#E8F5E9,stroke:#2E7D32,color:#1B5E20
    classDef data fill:#FFF3E0,stroke:#FB8C00,color:#E65100
    classDef external fill:#F3E5F5,stroke:#6A1B9A,color:#4A148C
    classDef cicd fill:#ECEFF1,stroke:#607D8B,color:#263238
```
