# rioacosta/s5-02-virtual-pet-app-front architecture

> Architecture diagram of the GitHub repository rioacosta/s5-02-virtual-pet-app-front, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2025-08-07). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/rioacosta/s5-02-virtual-pet-app-front
- Repository: https://github.com/rioacosta/s5-02-virtual-pet-app-front

## Overview

##### Project type and purpose
- This is a front-end Single Page Application (SPA) for a “Virtual Pet App” built with React and Vite.
- It provides user authentication, a main dashboard, admin dashboard, pet detail views, creation flows, and a meditation session page, plus static assets (avatars, sounds, etc.).

##### File structure
Top-level folders & files
- public/ – static assets served at root (images, sounds)
- src/ – application source code
– App.jsx, main.jsx – React entry points
– config/config.js – app configuration (e.g., base API URL)
– pages/ – React page components (AuthPage, Dashboard, AdminDashboard, BuddyDetailPage, CreateBuddyPage, MeditationSessionPage)
– services/ – API client layer
· api.ts – axios instance or fetch wrapper with baseURL
· authService.ts – authentication endpoints
· adminService.ts – admin-only endpoints
– utils/ – helper functions (e.g., authUtils.ts)
- dist/ – production build artifacts
- vite.config.js – Vite build config
- .env, package.json, package-lock.json

##### Elements
– Clear labels for each component (e.g., “AuthService (src/services/authService.ts)”)
- Blue for UI components
- Green for service/API layer
- Orange for data stores
- Gray for static asset hosting

##### “Add all the path calls” – Extract and annotate each endpoint from the service files
AuthService (src/services/authService.ts)
- POST /api/auth/login
- POST /api/auth/register
- POST /api/auth/logout
- GET  /api/auth/me

AdminService (src/services/adminService.ts)
- GET    /api/admin/buddies
- GET    /api/admin/buddies/:id
- POST   /api/admin/buddies
- /api/admin/buddies/:id
- DELETE /api/admin/buddies/:id
- (similarly for users or other admin resources)

Generic API (src/services/api.ts)
- Base URL configured via src/config/config.js
- Interceptors for auth token injection

Other service calls implied by pages:
- GET    /api/buddies
- GET    /api/buddies/:id
- POST   /api/buddies
- GET    /api/sessions/:sessionId
- POST   /api/sessions

##### Detail level guidance
- For each page component, show which service methods it invokes.
- Config.js baseURL usage.
- Public/assets folder as part of “Static Asset Host.”

## Diagram (Mermaid)

```mermaid
flowchart TD
    %% Client Layer
    subgraph "Client (Browser/React SPA)"
        direction TB
        Main["main.jsx"]:::ui
        App["App.jsx"]:::ui
        Pages["Pages (AuthPage.jsx, Dashboard.jsx, AdminDashboard.jsx,<br/>BuddyDetailPage.jsx, CreateBuddyPage.jsx,<br/>MeditationSessionPage.jsx)"]:::ui
        AuthUtils["authUtils.ts"]:::ui
    end

    %% Static Asset Host
    subgraph "Static File Host / CDN"
        direction TB
        IndexHTML["index.html"]:::static
        Avatars["public/assets/avatars/"]:::static
        AvatarsNOBG["public/assets/avatarsNOBG/"]:::static
        Chakras["public/assets/chakras/"]:::static
        Habitats["public/assets/habitats/"]:::static
        Sounds["public/assets/sounds/"]:::static
        ViteConfig["vite.config.js"]:::static
    end

    %% API Layer
    subgraph "API Layer (Service Module)"
        direction TB
        APIClient["api.ts<br>Axios/fetch wrapper<br>BaseURL via Config"]:::service
        AuthService["authService.ts<br>POST /api/auth/login<br>POST /api/auth/register<br>POST /api/auth/logout<br>GET /api/auth/me"]:::service
        AdminService["adminService.ts<br>GET /api/admin/buddies<br>GET /api/admin/buddies/:id<br>POST /api/admin/buddies<br>PUT /api/admin/buddies/:id<br>DELETE /api/admin/buddies/:id"]:::service
    end

    %% Configuration
    Config["config.js<br>base API URL"]:::config

    %% Production Build Artifacts
    subgraph "Production Build Artifacts"
        direction TB
        DistDir["dist/"]:::static
        DistIndex["dist/index.html"]:::static
        DistAssets["dist/assets/*.js"]:::static
    end

    %% Package & Environment
    subgraph "Package & Environment"
        direction TB
        PackageJSON["package.json"]:::static
        PackageLock["package-lock.json"]:::static
        EnvFile[".env"]:::static
    end

    %% Data Layer
    subgraph "Data Layer"
        direction TB
        Database["Database"]:::data
        Storage["Storage (Asset files)"]:::data
    end

    %% Client to Services
    Pages -->|uses login/register/logout/me| AuthService
    Pages -->|uses admin endpoints| AdminService
    Pages -->|uses generic endpoints| APIClient
    AuthService --> APIClient
    AdminService --> APIClient
    APIClient -->|reads baseURL| Config

    %% Client asset loading
    Pages -->|loads avatars, sounds, etc.| IndexHTML
    Pages --> Avatars
    Pages --> AvatarsNOBG
    Pages --> Chakras
    Pages --> Habitats
    Pages --> Sounds

    %% API Client to Backend
    APIClient -->|"HTTP requests"| APIBackend["API Backend"]:::service
    APIBackend -->|CRUD| Database
    APIBackend -->|serves asset files| Storage

    %% Build artifacts serve
    DistDir --> DistIndex
    DistDir --> DistAssets

    %% Click Events
    click Main "https://github.com/rioacosta/s5-02-virtual-pet-app-front/blob/master/src/main.jsx"
    click App "https://github.com/rioacosta/s5-02-virtual-pet-app-front/blob/master/src/App.jsx"
    click Pages "https://github.com/rioacosta/s5-02-virtual-pet-app-front/tree/master/src/pages/"
    click AuthUtils "https://github.com/rioacosta/s5-02-virtual-pet-app-front/blob/master/src/utils/authUtils.ts"
    click IndexHTML "https://github.com/rioacosta/s5-02-virtual-pet-app-front/blob/master/index.html"
    click Avatars "https://github.com/rioacosta/s5-02-virtual-pet-app-front/tree/master/public/assets/avatars/"
    click AvatarsNOBG "https://github.com/rioacosta/s5-02-virtual-pet-app-front/tree/master/public/assets/avatarsNOBG/"
    click Chakras "https://github.com/rioacosta/s5-02-virtual-pet-app-front/tree/master/public/assets/chakras/"
    click Habitats "https://github.com/rioacosta/s5-02-virtual-pet-app-front/tree/master/public/assets/habitats/"
    click Sounds "https://github.com/rioacosta/s5-02-virtual-pet-app-front/tree/master/public/assets/sounds/"
    click ViteConfig "https://github.com/rioacosta/s5-02-virtual-pet-app-front/blob/master/vite.config.js"
    click APIClient "https://github.com/rioacosta/s5-02-virtual-pet-app-front/blob/master/src/services/api.ts"
    click AuthService "https://github.com/rioacosta/s5-02-virtual-pet-app-front/blob/master/src/services/authService.ts"
    click AdminService "https://github.com/rioacosta/s5-02-virtual-pet-app-front/blob/master/src/services/adminService.ts"
    click Config "https://github.com/rioacosta/s5-02-virtual-pet-app-front/blob/master/src/config/config.js"
    click DistDir "https://github.com/rioacosta/s5-02-virtual-pet-app-front/tree/master/dist/"
    click DistIndex "https://github.com/rioacosta/s5-02-virtual-pet-app-front/blob/master/dist/index.html"
    click DistAssets "https://github.com/rioacosta/s5-02-virtual-pet-app-front/tree/master/dist/assets/"
    click PackageJSON "https://github.com/rioacosta/s5-02-virtual-pet-app-front/blob/master/package.json"
    click PackageLock "https://github.com/rioacosta/s5-02-virtual-pet-app-front/blob/master/package-lock.json"
    click EnvFile "https://github.com/rioacosta/s5-02-virtual-pet-app-front/blob/master/.env"

    %% Styles
    classDef ui fill:#ADD8E6,stroke:#000,stroke-width:1px;
    classDef service fill:#90EE90,stroke:#000,stroke-width:1px;
    classDef data fill:#FFA500,stroke:#000,stroke-width:1px;
    classDef static fill:#D3D3D3,stroke:#000,stroke-width:1px;
    classDef config fill:#FFFFE0,stroke:#000,stroke-width:1px;
```
