# bibashjaprel/pethub architecture

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

- Interactive diagram: https://gitdiagram.com/bibashjaprel/pethub
- Repository: https://github.com/bibashjaprel/pethub

## Overview

##### Project Type and Purpose
- PetHub is a full-stack pet adoption platform.
- The system allows users to browse available pets, donate pets, and make adoption requests.
- It incorporates role-based access control (admin, user, donor) and uses Cloudinary for pet image storage.
- The frontend is built in React.js (with Material UI and Tailwind CSS) while the backend uses Node.js, Express.js, and MongoDB via Mongoose.

##### Analyzing the File Structure
- The repository is clearly split into two main sections: “frontend” and “backend”.
- The backend contains specific folders such as “controllers”, “models”, “routes”, and “config”.
– Controllers: handle business logic for pet adoption, donations, and user-related actions.
– Models: represent the database structure (for pets, adoption, donation, and users).
– Routes: define the API endpoints.
– Configuration scripts (like cloudinary.js and dbconfig.js) manage integrations with external services.
- The frontend includes directories like “components”, “pages”, and “utils” which are used to render the UI, manage navigation (using React Router), and assist with API calls and authentication.
- There are also configuration files (e.g., tailwind.config.js) and build scripts that hint at modern frontend tooling.

##### Key Architectural Components
a. Frontend Component:
- Built with React.js.
- Organized into pages (Home, Login, Signup, Dashboard subpages) and reusable components (Navbar, Footer, etc.).
- Manages routing and state for user interactions.

b. Backend API:
- Constructed using Node.js and Express.js.
- Contains controllers, models, and route definitions.
- Handles user authentication (using JWT) and role-based access.
- Manages image uploads via Cloudinary (see cloudinary.js in config).
- Includes middleware for authentication and file uploads.

c. Database:
- Utilizes MongoDB with Mongoose ORM.
- Models define data structures like pets, adoption requests, donations, and users.

d. External Services & Utilities:
- Cloudinary for storing pet images.
- JWT for secure authentication.
- Environmental variables (via .env) for configuration.

## Diagram (Mermaid)

```mermaid
flowchart TD
    %% Frontend Sector
    subgraph "Frontend"
        F1["React Frontend"]:::frontend
        F2["Auth Helpers"]:::frontend
    end

    %% Backend Sector
    subgraph "Backend"
        B1["Express API Server"]:::backend
        B2["Controllers"]:::backend
        B3["Routes"]:::backend
        B4["Auth Module"]:::backend
        B5["Cloudinary Integration"]:::backend
    end

    %% External Components
    DB["MongoDB Database"]:::database

    %% Connections between Frontend and Backend
    F1 -->|"APIcalls"| B1
    B1 -->|"BusinessLogic"| B2
    B1 -->|"API Endpoints"| B3
    B1 -->|"AuthChecks"| B4
    B1 -->|"CRUD"| DB
    B1 -->|"upload"| B5
    B5 -->|"response"| B1
    B1 -->|"JWTtoken"| F1
    F1 -->|"Utilizes"| F2

    %% Click Events
    click F1 "https://github.com/bibashjaprel/pethub/tree/main/frontend/src"
    click F2 "https://github.com/bibashjaprel/pethub/blob/main/frontend/src/utils/authHelpers.js"
    click B1 "https://github.com/bibashjaprel/pethub/tree/main/backend"
    click B2 "https://github.com/bibashjaprel/pethub/tree/main/backend/controllers"
    click B3 "https://github.com/bibashjaprel/pethub/tree/main/backend/routes"
    click B4 "https://github.com/bibashjaprel/pethub/blob/main/backend/middlewares/authMiddleware.js"
    click B5 "https://github.com/bibashjaprel/pethub/blob/main/backend/config/cloudinary.js"
    click DB "https://github.com/bibashjaprel/pethub/tree/main/backend/models"

    %% Styles
    classDef frontend fill:#a2d2ff,stroke:#023e8a,stroke-width:2px;
    classDef backend fill:#bde0fe,stroke:#03045e,stroke-width:2px;
    classDef database fill:#ffc8dd,stroke:#ff007f,stroke-width:2px;
```
