# phuuthanh-dev/pet-love-platform architecture

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

- Interactive diagram: https://gitdiagram.com/phuuthanh-dev/pet-love-platform
- Repository: https://github.com/phuuthanh-dev/pet-love-platform

## Overview

##### Main Components
- Frontend – This is built with React (using Vite, Redux, Tailwind, etc.) and contains pages, components, API service wrappers, context providers (such as a SocketProvider), and routing. It also includes a dedicated “ai” directory with Python scripts and models (for tasks such as dog breed prediction or similar functionality).
- Backend – A Node.js (likely Express-based) server organized using an MVC-like pattern. It is structured into directories such as:
– controllers (handling incoming HTTP requests, including authentication, blog, pet, donation, etc.)
– services (business logic for handling data)
– repositories (data persistence abstractions)
– models (data schema definitions, plugins for pagination and toJSON conversion)
– middlewares (authentication, error handling, validations)
– configurations and utilities (JWT, database connection, cloudinary integration, etc.)
– Socket integration (for real-time features like chat)
– Swagger/OpenAPI files for API documentation.
- Supporting Infrastructure – Dockerfiles for both frontend and backend, docker-compose.yml for container orchestration, CI/CD workflows in .github/workflows, and configuration files (ecosystem.config, eslint, prettier, etc.).
- External Services – Cloudinary for media management, potential external databases (implied by backend/src/utils/db.js), and possibly third-party integrations for payments, notifications, etc.

##### Out the Relationships and Interactions
- Frontend communicates with the Backend REST APIs to fetch and send data (authentication, pet details, adoptions, messaging, etc.).
- The Backend follows a layered architecture (controllers → services → repositories) to validate, process, and persist data.
- Real-Time Communication: A dedicated socket module in the backend supports functionalities like live chat or notifications, while the frontend integrates it through a SocketProvider.
- The AI component in the frontend (with Python scripts and pretrained models) may either operate independently or be called by the frontend to analyze data (for example, handling pet breed predictions or related processing).
- Docker and CI/CD components allow both frontend and backend to be containerized and deployed in a reliable manner.

##### Architectural Patterns and Design Principles
- MVC / Layered Architecture: Clear separation of concerns within the backend.
- Component-Based UI: The frontend is modular with reusable components, pages, and contexts.
- API-Driven Communication: RESTful endpoints defined via Swagger/OpenAPI documentation.
- Microservices-style Containerization: Using Docker (and docker-compose) to orchestrate and isolate services, ensuring clean separation between frontend, backend, and supporting processes.
- Repository and Service Patterns: Clean abstraction between data access (repositories) and business logic (services).

## Diagram (Mermaid)

```mermaid
flowchart TD
    %% Client Layer
    subgraph "Client"
        Browser["Browser/Client"]:::external
    end

    %% Frontend Layer
    subgraph "Frontend"
        Frontend_UI["Frontend UI (React Application)"]:::frontend
        Frontend_AI["Frontend AI Module"]:::frontend
        Socket_Provider["SocketProvider (Frontend)"]:::frontend
    end

    %% Backend Layer
    subgraph "Backend"
        Controllers["Controllers (HTTP Endpoints)"]:::backend
        Services["Services (Business Logic)"]:::backend
        Repositories["Repositories (Data Persistence)"]:::backend
        Models["Models & Plugins"]:::backend
        Middlewares["Middlewares"]:::backend
        Socket["Socket Integration"]:::backend
        API_Doc["API Documentation (Swagger)"]:::backend
    end

    %% Containerization & Deployment
    subgraph "Containerization & Deployment"
        Docker_Frontend["Dockerfile (Frontend)"]:::container
        Docker_Backend["Dockerfile (Backend)"]:::container
        Docker_Compose["docker-compose.yml"]:::container
        CICD["CI/CD Workflows"]:::container
    end

    %% External Services
    subgraph "External Services"
        Database["Database"]:::external
        Cloudinary["Cloudinary"]:::external
        ThirdParty["Third-Party Services"]:::external
    end

    %% Connections
    Browser -->|"HTTPRequest"| Frontend_UI
    Frontend_UI -->|"RESTAPI"| Controllers
    Frontend_UI ---|"InternalLink"| Frontend_AI
    Controllers -->|"Executes"| Services
    Services -->|"Calls"| Repositories
    Repositories -->|"Queries"| Database
    Controllers -->|"Applies"| Middlewares
    Services -->|"UsesSchema"| Models
    Controllers -->|"DocsGen"| API_Doc
    Controllers -->|"Integrates"| ThirdParty
    Repositories -->|"MediaStore"| Cloudinary
    Socket_Provider <-->|"WebSocket"| Socket

    %% Containerization linking to Frontend & Backend
    Docker_Frontend -->|"Builds"| Frontend_UI
    Docker_Backend -->|"Builds"| Controllers
    Docker_Compose --> Docker_Frontend
    Docker_Compose --> Docker_Backend
    CICD -->|"DeploysVia"| Docker_Compose

    %% Class definitions for coloring
    classDef frontend fill:#ADD8E6,stroke:#333,stroke-width:2px;
    classDef backend fill:#90EE90,stroke:#333,stroke-width:2px;
    classDef container fill:#FFDEAD,stroke:#333,stroke-width:2px;
    classDef external fill:#FFD700,stroke:#333,stroke-width:2px;

    %% Click Events for Component Mapping
    click Frontend_UI "https://github.com/phuuthanh-dev/pet-love-platform/tree/main/frontend/src"
    click Frontend_AI "https://github.com/phuuthanh-dev/pet-love-platform/tree/main/frontend/ai"
    click Controllers "https://github.com/phuuthanh-dev/pet-love-platform/tree/main/backend/src/controllers"
    click Services "https://github.com/phuuthanh-dev/pet-love-platform/tree/main/backend/src/services"
    click Repositories "https://github.com/phuuthanh-dev/pet-love-platform/tree/main/backend/src/repositories"
    click Models "https://github.com/phuuthanh-dev/pet-love-platform/tree/main/backend/src/models"
    click Middlewares "https://github.com/phuuthanh-dev/pet-love-platform/tree/main/backend/src/middlewares"
    click Socket "https://github.com/phuuthanh-dev/pet-love-platform/tree/main/backend/src/socket"
    click API_Doc "https://github.com/phuuthanh-dev/pet-love-platform/blob/main/backend/docs/openapi.yaml"
    click Docker_Frontend "https://github.com/phuuthanh-dev/pet-love-platform/tree/main/frontend/Dockerfile"
    click Docker_Backend "https://github.com/phuuthanh-dev/pet-love-platform/tree/main/backend/Dockerfile"
    click Docker_Compose "https://github.com/phuuthanh-dev/pet-love-platform/blob/main/docker-compose.yml"
    click CICD "https://github.com/phuuthanh-dev/pet-love-platform/tree/main/.github/workflows"
```
