# huynhlephcvinh/swp391_petsocial_petlover architecture

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

- Interactive diagram: https://gitdiagram.com/huynhlephcvinh/swp391_petsocial_petlover
- Repository: https://github.com/huynhlephcvinh/swp391_petsocial_petlover

## Overview

##### Project Type and Purpose
- This is a full-stack social networking web application (“DC Social Network”) for cat and dog lovers.
- Frontend is built with React (SPA) providing pages for posts, pets, exchanges, chat, admin dashboards, user authentication, payments, etc.
- Backend is a Spring Boot application exposing REST endpoints, handling security (JWT + OAuth2), processing payments (PayPal), managing media (Cloudinary), persisting data, and supporting real-time features via WebSocket.

##### File-Structure Analysis
- Top level:
- /frontend – React app with component hierarchy (pages, shared components, context providers, socket.js for real-time).
- /backend – Spring Boot service structured in config, controller, service/serviceImp, repository, model, payload, exception, websocket folders.
- Key patterns:
- MVC REST layer (Controller → Service → Repository → Database)
- Layered architecture: config components (security, JWT, OAuth2, PayPal, Cloudinary), service interfaces + implementations, data access (Spring Data JPA repositories), domain entities.
- Real-time messaging: WebSocketConfig, event listener, controllers and domain/dto/repository/service under websocket package.
- Deployment config: Maven wrapper, application.properties, React’s package.json.

##### README Insights
- Describes features: user auth, posting pets, admin moderation, item exchange, real-time chat/notifications, payment integration.
- Illustrates tech stack: Java, Spring Boot, React, WebSocket/STOMP, JWT, OAuth2, Cloudinary, PayPal.

a. Main Components
- User’s Browser (React SPA)
- REST API Layer (Spring Boot Controllers)
- Authentication & Authorization (JWT + OAuth2 Config)
- Business Logic Layer (Services)
- Data Layer (Spring Data Repositories → Relational DB)
- Real-Time Messaging Layer (WebSocket Endpoints + Message Broker)
- External Services: OAuth Providers (Google/Facebook), PayPal API, Cloudinary Media Storage
- Admin Dashboard Module (React)

b. Relationships & Interactions
- Browser ↔ REST API: HTTP(S) JSON calls via Axios (login, CRUD on posts/pets/exchanges/comments/reactions)
- Browser ↔ WebSocket: STOMP over WS for chat messages and notifications
- REST API ↔ Database: JPA repositories reading/writing entities
- REST API ↔ OAuth Providers: OAuth2UserService for social login
- REST API ↔ PayPal: PaypalService for payment orders and callbacks
- REST API ↔ Cloudinary: CloudinaryService for image upload URLs
- Service layer orchestrates calls between controllers, repositories, and external services

c. Architectural Patterns & Design Principles
- Layered Architecture (Presentation, Service, Data)
- Dependency Injection for decoupling config, controllers, services, repos
- Repository Pattern via Spring Data JPA
- Security separated into JwtProvider, JwtTokenValidator, SecurityConfig
- Real-time communication using WebSocketConfig + domain-specific controllers/services

d. Key Technologies & Frameworks
- Frontend: React, React Context, React Router, Axios, Socket.IO (or STOMP client)
- Backend: Spring Boot, Spring Security (JWT + OAuth2), Spring Data JPA, WebSocket (STOMP), Maven
- External: PayPal API, Cloudinary API, Google/Facebook OAuth2

## Diagram (Mermaid)

```mermaid
flowchart TB
    %% Client Layer
    subgraph "Frontend (React SPA)" 
        direction TB
        UI[/"React SPA"/]:::frontend
        AuthContext["Auth Context"]:::frontend
        AuthService["AuthenticationService"]:::frontend
        SocketClient["Socket Client"]:::frontend
        AdminPages["Admin Pages"]:::frontend
        AdminWidgets["Admin Widgets"]:::frontend
        PostComponents["Post Components"]:::frontend
        HomePage["Home Page"]:::frontend
        PetComponents["Pet Components"]:::frontend
        MyPetsPage["MyPets Page"]:::frontend
        ExchangeComponents["Exchange Components"]:::frontend
        MarketplacePage["MarketPlace Page"]:::frontend
        AppliedPage["Applied Page"]:::frontend
        PaymentComponent["Payment Component"]:::frontend
        ChatUI["Chat UI Components"]:::frontend
        NotificationUI["Notification Component"]:::frontend
        MessengerPage["Messenger Page"]:::frontend
    end

    %% Server Layer
    subgraph "Server (Spring Boot)" 
        direction TB
        subgraph "Config Module"
            direction TB
            JwtProvider["JwtProvider"]:::config
            JwtValidator["JwtTokenValidator"]:::config
            JwtConstants["JwtConstant"]:::config
            OAuthConfig["OAuth2 Config"]:::config
            SecurityConfig["SecurityConfig"]:::config
            PaypalConfig["PaypalConfig"]:::config
        end
        subgraph "API Layer (Controllers)"
            direction TB
            RestControllers["REST API Controllers"]:::api
            PaypalController["PaypalController"]:::api
        end
        subgraph "Service Layer"
            direction TB
            Services["Business Services"]:::service
            PaypalService["PaypalService"]:::service
            PaypalServiceImp["PaypalServiceImp"]:::service
            CloudinaryService["CloudinaryService"]:::service
        end
        subgraph "Data Layer"
            direction TB
            Repositories["Repositories"]:::data
            Entities["Domain Entities"]:::data
        end
        subgraph "WebSocket Module"
            direction TB
            WSConfig["WebSocketConfig & Events"]:::ws
            WSControllers["WS Controllers"]:::ws
            WSServices["WS Services"]:::ws
        end
    end

    %% External Services and DB
    Database[(Relational Database)]:::database
    OAuthProviders{{"OAuth Providers"}}:::external
    PayPalAPI{{"PayPal API"}}:::external
    CloudinaryAPI{{"Cloudinary API"}}:::external

    %% Interactions
    UI -->|"HTTP JSON"| RestControllers
    UI -->|"WS STOMP"| WSConfig
    RestControllers -->|"calls"| Services
    Services -->|"CRUD"| Repositories
    Repositories -->|"manages"| Entities
    RestControllers -->|"uses"| JwtProvider
    RestControllers -->|"uses"| JwtValidator
    RestControllers -->|"uses"| SecurityConfig
    RestControllers -->|"calls"| PaypalService
    PaypalService -->|"calls"| PayPalAPI
    RestControllers -->|"calls"| CloudinaryService
    WSConfig -->|"routes"| WSControllers
    WSControllers -->|"uses"| WSServices
    Services -->|"writes/reads"| Database
    RestControllers -->|"OAuth2UserService"| OAuthProviders
    PaypalController -->|"callback"| PayPalAPI
    CloudinaryService -->|"upload"| CloudinaryAPI

    %% Client Detailed interactions
    UI --> AuthContext
    AuthContext --> AuthService
    UI --> SocketClient
    UI --> AdminPages
    UI --> AdminWidgets
    UI --> PostComponents
    PostComponents --> HomePage
    UI --> PetComponents
    PetComponents --> MyPetsPage
    UI --> ExchangeComponents
    ExchangeComponents --> MarketplacePage
    ExchangeComponents --> AppliedPage
    UI --> PaymentComponent
    UI --> ChatUI
    ChatUI --> MessengerPage
    UI --> NotificationUI

    %% Click Events - Frontend
    click UI "https://github.com/huynhlephcvinh/swp391_petsocial_petlover/blob/main/frontend/src/index.js"
    click UI "https://github.com/huynhlephcvinh/swp391_petsocial_petlover/blob/main/frontend/src/App.js"
    click AuthContext "https://github.com/huynhlephcvinh/swp391_petsocial_petlover/blob/main/frontend/src/context/authContext.js"
    click AuthService "https://github.com/huynhlephcvinh/swp391_petsocial_petlover/blob/main/frontend/src/components/post/AuthenticationService.js"
    click SocketClient "https://github.com/huynhlephcvinh/swp391_petsocial_petlover/blob/main/frontend/src/socket.js"
    click AdminPages "https://github.com/huynhlephcvinh/swp391_petsocial_petlover/tree/main/frontend/src/pages/adminpage"
    click AdminWidgets "https://github.com/huynhlephcvinh/swp391_petsocial_petlover/tree/main/frontend/src/components/admin"
    click PostComponents "https://github.com/huynhlephcvinh/swp391_petsocial_petlover/tree/main/frontend/src/components/post"
    click HomePage "https://github.com/huynhlephcvinh/swp391_petsocial_petlover/blob/main/frontend/src/pages/home/Home.jsx"
    click PetComponents "https://github.com/huynhlephcvinh/swp391_petsocial_petlover/tree/main/frontend/src/components/pet"
    click MyPetsPage "https://github.com/huynhlephcvinh/swp391_petsocial_petlover/blob/main/frontend/src/pages/MyPets/MyPets.jsx"
    click ExchangeComponents "https://github.com/huynhlephcvinh/swp391_petsocial_petlover/tree/main/frontend/src/components/exchange"
    click MarketplacePage "https://github.com/huynhlephcvinh/swp391_petsocial_petlover/blob/main/frontend/src/pages/MarketPlace/MarketPlace.jsx"
    click AppliedPage "https://github.com/huynhlephcvinh/swp391_petsocial_petlover/blob/main/frontend/src/pages/appliedpage/Applied.jsx"
    click PaymentComponent "https://github.com/huynhlephcvinh/swp391_petsocial_petlover/blob/main/frontend/src/components/payment/Payment.jsx"
    click ChatUI "https://github.com/huynhlephcvinh/swp391_petsocial_petlover/tree/main/frontend/src/components/conversation"
    click MessengerPage "https://github.com/huynhlephcvinh/swp391_petsocial_petlover/blob/main/frontend/src/pages/messenger/Messenger.jsx"
    click NotificationUI "https://github.com/huynhlephcvinh/swp391_petsocial_petlover/blob/main/frontend/src/components/notification/Notification.jsx"

    %% Click Events - Backend
    click JwtProvider "https://github.com/huynhlephcvinh/swp391_petsocial_petlover/blob/main/backend/src/main/java/com/petlover/petsocial/config/JwtProvider.java"
    click JwtValidator "https://github.com/huynhlephcvinh/swp391_petsocial_petlover/blob/main/backend/src/main/java/com/petlover/petsocial/config/JwtTokenValidator.java"
    click JwtConstants "https://github.com/huynhlephcvinh/swp391_petsocial_petlover/blob/main/backend/src/main/java/com/petlover/petsocial/config/JwtConstant.java"
    click OAuthConfig "https://github.com/huynhlephcvinh/swp391_petsocial_petlover/tree/main/backend/src/main/java/com/petlover/petsocial/config/oauth"
    click SecurityConfig "https://github.com/huynhlephcvinh/swp391_petsocial_petlover/blob/main/backend/src/main/java/com/petlover/petsocial/config/SecurityConfig.java"
    click PaypalConfig "https://github.com/huynhlephcvinh/swp391_petsocial_petlover/blob/main/backend/src/main/java/com/petlover/petsocial/config/PaypalConfig.java"
    click PaypalController "https://github.com/huynhlephcvinh/swp391_petsocial_petlover/blob/main/backend/src/main/java/com/petlover/petsocial/controller/PaypalController.java"
    click PaypalService "https://github.com/huynhlephcvinh/swp391_petsocial_petlover/blob/main/backend/src/main/java/com/petlover/petsocial/service/PaypalService.java"
    click PaypalServiceImp "https://github.com/huynhlephcvinh/swp391_petsocial_petlover/blob/main/backend/src/main/java/com/petlover/petsocial/serviceImp/PaypalServiceImp.java"
    click CloudinaryService "https://github.com/huynhlephcvinh/swp391_petsocial_petlover/blob/main/backend/src/main/java/com/petlover/petsocial/service/CloudinaryService.java"
    click RestControllers "https://github.com/huynhlephcvinh/swp391_petsocial_petlover/tree/main/backend/src/main/java/com/petlover/petsocial/controller"
    click Services "https://github.com/huynhlephcvinh/swp391_petsocial_petlover/tree/main/backend/src/main/java/com/petlover/petsocial/service"
    click Repositories "https://github.com/huynhlephcvinh/swp391_petsocial_petlover/tree/main/backend/src/main/java/com/petlover/petsocial/repository"
    click WSConfig "https://github.com/huynhlephcvinh/swp391_petsocial_petlover/tree/main/backend/src/main/java/com/petlover/petsocial/websocket/config"
    click WSControllers "https://github.com/huynhlephcvinh/swp391_petsocial_petlover/tree/main/backend/src/main/java/com/petlover/petsocial/websocket/controller"
    click WSServices "https://github.com/huynhlephcvinh/swp391_petsocial_petlover/tree/main/backend/src/main/java/com/petlover/petsocial/websocket/service"

    %% Styles
    classDef frontend fill:#D0E6FF,stroke:#0366d6,stroke-width:1px
    classDef api fill:#DFFFE0,stroke:#28a745,stroke-width:1px
    classDef service fill:#FFE4B5,stroke:#e69500,stroke-width:1px
    classDef data fill:#F0F0F0,stroke:#6c757d,stroke-width:1px
    classDef database fill:#FFFFFF,stroke:#6c757d,stroke-width:2px,stroke-dasharray: 5 5
    classDef external fill:#E8E8E8,stroke:#6c757d,stroke-width:1px,stroke-dasharray: 2 2
    classDef config fill:#FFF0F5,stroke:#c71585,stroke-width:1px
    classDef ws fill:#FFF5E1,stroke:#ff8c00,stroke-width:1px
```
