# vilmaponce/sprint5 architecture

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

- Interactive diagram: https://gitdiagram.com/vilmaponce/sprint5
- Repository: https://github.com/vilmaponce/sprint5

## Overview

##### Project Type and Purpose
- This is a single‑page front‑end application built with React (via Vite) that provides a CRUD interface for “interstellar pets.”
- It leverages a mock external API (MockAPI) for data persistence, uses React Router for navigation, Context for global state, and various UI libraries for styling, animations, and alerts.

##### File Structure Analysis
- public/
- Static assets (images, videos, favicon).
- src/
- components/: Reusable UI pieces (Header, Footer, PetCard, PetForm, LoadingPlanet, StarCursor, GalaxyBackground, AdoptionModal).
- pages/: Route‑specific views (Home, PetList, PetDetail, PetCreate, PetEdit, AdoptedPets, NotFound).
- Router/: AppRouter.jsx defines route→page mapping.
- context/: PetContext.jsx provides global state and dispatch functions for pets.
- services/: api.js encapsulates all HTTP calls (get/list/create/update/delete).
- utils/: Validation schemas (petSchema), configuration for SweetAlert2 and toast notifications.
- main.jsx / App.jsx / App.css: Entry point, root component, and global styles.

##### Key Architectural Patterns
- Component‑based UI (React).
- Unidirectional data flow: Pages/components dispatch actions → Context → API calls → Context updates state → Components re‑render.
- Separation of concerns:
- UI in components and pages
- State management in Context
- Data access in services/api.js
- Validation and config in utils.

##### Main Components
a. Client Browser (User Interface)
b. React Application Layers:
- Presentation Layer: Pages & Components
- State Layer: PetContext (Provider & Consumer)
- Service Layer: api.js (Axios HTTP client)
- Utility Layer: petSchema, swalConfig, toastConfig
c. External Mock API Service
d. Static Asset Server (serving public/images, public/video)
e. Build & Dev Tools: Vite (bundler, dev server)

##### Relationships and Interactions
- From Context to api.js for HTTP operations.
- From api.js to External MockAPI (illustrate GET/POST/PUT/DELETE).
- Assets (images/videos) are fetched by Components at runtime from the public folder.
- Vite sits beneath the entire app, providing bundling and hot‑reload during development, and produces the final static bundle for deployment.

##### Architectural Notes
- The Router sits at the top of the React tree (AppRouter wraps pages).
- Context Provider wraps Router to give any page access to pet state/actions.
- Utility modules are side‑connected to both Context (for validation before dispatch) and Components (for alerts and toasts).

## Diagram (Mermaid)

```mermaid
graph TB
  %% Presentation Layer
  subgraph "Presentation Layer"
    direction TB
    Router["AppRouter"]:::ui
    subgraph "Pages"
      direction TB
      Home["Home Page"]:::ui
      PetList["Pet List Page"]:::ui
      PetDetail["Pet Detail Page"]:::ui
      PetCreate["Pet Create Page"]:::ui
      PetEdit["Pet Edit Page"]:::ui
      AdoptedPets["Adopted Pets Page"]:::ui
      NotFound["Not Found Page"]:::ui
    end
    subgraph "Components"
      direction TB
      Header["Header"]:::ui
      Footer["Footer"]:::ui
      PetCard["Pet Card"]:::ui
      PetForm["Pet Form"]:::ui
      LoadingPlanet["Loading Planet Animation"]:::ui
      StarCursor["Star Cursor Animation"]:::ui
      GalaxyBackground["Galaxy Background"]:::ui
      AdoptionModal["Adoption Modal"]:::ui
    end
  end

  %% State Layer
  subgraph "State Layer"
    direction TB
    PetContext["PetContext (Provider & Consumer)"]:::state
  end

  %% Service Layer
  subgraph "Service Layer"
    direction TB
    APIService["API Service (api.js)"]:::service
  end

  %% Utility Layer
  subgraph "Utility Layer"
    direction TB
    PetSchema["petSchema"]:::utils
    SwalConfig["swalConfig"]:::utils
    ToastConfig["toastConfig"]:::utils
  end

  %% External Layer
  subgraph "External Services"
    direction TB
    MockAPI["MockAPI Service"]:::external
    AssetsServer["Static Assets Server"]:::external
  end

  %% Dev Tools
  subgraph "Build & Dev Tools"
    direction TB
    Vite["Vite (Dev Server & Bundler)"]:::devtools
  end

  %% Connections
  Router -->|renders| Home
  Router -->|renders| PetList
  Router -->|renders| PetDetail
  Router -->|renders| PetCreate
  Router -->|renders| PetEdit
  Router -->|renders| AdoptedPets
  Router -->|renders| NotFound

  Home -->|"uses"| Header
  Home -->|"uses"| Footer
  PetList -->|"uses"| PetCard
  PetDetail -->|"uses"| PetCard
  PetCreate -->|"uses"| PetForm
  PetEdit -->|"uses"| PetForm
  PetList -->|"uses"| GalaxyBackground
  PetDetail -->|"uses"| GalaxyBackground
  Home -->|"uses"| LoadingPlanet
  Home -->|"uses"| StarCursor
  PetDetail -->|"uses"| AdoptionModal

  %% Data Flow
  Home -->|"dispatch action"| PetContext
  PetList -->|"dispatch action"| PetContext
  PetDetail -->|"dispatch action"| PetContext
  PetCreate -->|"dispatch action"| PetContext
  PetEdit -->|"dispatch action"| PetContext
  AdoptedPets -->|"dispatch action"| PetContext

  Header -->|"consumes state"| PetContext
  Footer -->|"consumes state"| PetContext
  PetCard -->|"consumes state"| PetContext
  PetForm -->|"consumes state"| PetContext
  AdoptionModal -->|"consumes state"| PetContext

  PetContext -->|"calls fetchAllPets(), createPet(), updatePet(), deletePet()"| APIService
  APIService -->|"GET/POST/PUT/DELETE /pets"| MockAPI

  %% Asset Fetch
  GalaxyBackground -->|“fetch /images and /video”| AssetsServer
  LoadingPlanet -->|“fetch assets”| AssetsServer
  StarCursor -->|“fetch assets”| AssetsServer

  %% Utils Connections
  PetSchema -.->|“validate data”| PetContext
  PetSchema -.->|“validate form”| PetForm
  SwalConfig -.->|“alert config”| PetContext
  SwalConfig -.->|“alert config”| AdoptionModal
  ToastConfig -.->|“toast config”| PetContext
  ToastConfig -.->|“toast config”| PetForm

  %% DevTools Connections
  Vite -->|“bundles & serves”| Router
  Vite -->|“serves assets”| AssetsServer

  %% Click Events
  click Home "https://github.com/vilmaponce/sprint5/blob/main/src/pages/Home.jsx"
  click PetList "https://github.com/vilmaponce/sprint5/blob/main/src/pages/PetList.jsx"
  click PetDetail "https://github.com/vilmaponce/sprint5/blob/main/src/pages/PetDetail.jsx"
  click PetCreate "https://github.com/vilmaponce/sprint5/blob/main/src/pages/PetCreate.jsx"
  click PetEdit "https://github.com/vilmaponce/sprint5/blob/main/src/pages/PetEdit.jsx"
  click AdoptedPets "https://github.com/vilmaponce/sprint5/blob/main/src/pages/AdoptedPets.jsx"
  click NotFound "https://github.com/vilmaponce/sprint5/blob/main/src/pages/NotFound.jsx"
  click Header "https://github.com/vilmaponce/sprint5/blob/main/src/components/Header.jsx"
  click Footer "https://github.com/vilmaponce/sprint5/blob/main/src/components/Footer.jsx"
  click PetCard "https://github.com/vilmaponce/sprint5/blob/main/src/components/PetCard.jsx"
  click PetForm "https://github.com/vilmaponce/sprint5/blob/main/src/components/PetForm.jsx"
  click LoadingPlanet "https://github.com/vilmaponce/sprint5/blob/main/src/components/LoadingPlanet.jsx"
  click StarCursor "https://github.com/vilmaponce/sprint5/blob/main/src/components/StarCursor.jsx"
  click GalaxyBackground "https://github.com/vilmaponce/sprint5/blob/main/src/components/GalaxyBackground.jsx"
  click AdoptionModal "https://github.com/vilmaponce/sprint5/blob/main/src/components/AdoptionModal.jsx"
  click Router "https://github.com/vilmaponce/sprint5/blob/main/src/Router/AppRouter.jsx"
  click PetContext "https://github.com/vilmaponce/sprint5/blob/main/src/context/PetContext.jsx"
  click APIService "https://github.com/vilmaponce/sprint5/blob/main/src/services/api.js"
  click PetSchema "https://github.com/vilmaponce/sprint5/blob/main/src/utils/petSchema.js"
  click SwalConfig "https://github.com/vilmaponce/sprint5/blob/main/src/utils/swalConfig.js"
  click ToastConfig "https://github.com/vilmaponce/sprint5/blob/main/src/utils/toastConfig.js"
  click Vite "https://github.com/vilmaponce/sprint5/blob/main/vite.config.js"

  %% Styles
  classDef ui fill:#ADD8E6,stroke:#333,stroke-width:1px
  classDef state fill:#90EE90,stroke:#333,stroke-width:1px
  classDef service fill:#FFA500,stroke:#333,stroke-width:1px
  classDef utils fill:#FFFF99,stroke:#333,stroke-width:1px
  classDef external fill:#D3D3D3,stroke:#333,stroke-width:1px
  classDef devtools fill:#E6E6FA,stroke:#333,stroke-width:1px
```
