# neuroflip/itacademy-sprint5-imagegallery architecture

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

- Interactive diagram: https://gitdiagram.com/neuroflip/itacademy-sprint5-imagegallery
- Repository: https://github.com/neuroflip/itacademy-sprint5-imagegallery

## Overview

##### Project Type and Purpose
- This is a single-page application (SPA) image gallery built with React (TypeScript) and Vite.
- Its purpose is to fetch placeholder images (via Picsum), allow users to drag & drop and manage a gallery, and display images with lazy loading.

##### File Structure Analysis
- Top level
- public, index.html, package.json, tsconfig.json, vite.config.ts, .github/workflows
- CI/CD workflows deploy to GitHub Pages and run lint/tests.
- src
- main.tsx + index.css → application entry point and global styles (Tailwind imported here).
- App.tsx + App.css → root React component.
- ImagesManager/ → data-provider module
– ImagesManager.ts + .d.ts → ContextAPI provider for image data
– providers/PicSumImagesDataProvider.ts → fetch logic from external API
- components/ → self-contained UI components (each folder has .tsx, styles, tests, custom hooks)
– DragAndDropImagesManager → drag/drop context + hooks
– Gallery → grid layout of ImageItem
– ImageItem, ImageButton, CustomAlertDialog, ContextualMenu → supportive UI widgets
- lib/utils.ts → shared utility functions
- test & vitest.config.js → unit testing setup

##### README Insights
- Emphasizes functional components, ContextAPI for drag/drop, lazy loading and async decode, render-props dialog, Tailwind with Vite.
- CI pipeline handles build, preview, tests, lint, and GitHub Pages deployment.

a. Main Components
- Browser (User Agent)
- React SPA
– Entry: index.html → main.tsx
– App Shell (App.tsx)
– ImagesManager Context Provider (handles data & drag/drop)
– UI Layer: DragAndDropImagesManager, Gallery, ImageItem, ContextualMenu, CustomAlertDialog, ImageButton
- External Service: Picsum API
- Build & Deployment: Vite dev server, Vite build, GitHub Actions, GitHub Pages

b. Relationships & Data Flows
1. Browser requests index.html → Vite dev server (dev) or static host (prod) serves assets.
2. main.tsx mounts App and wraps it with ImagesManager Context.
3. ImagesManager fetches image list from Picsum API via PicSumImagesDataProvider → caches into context state.
4. UI Components consume context:
– DragAndDropImagesManager listens for drag/drop events and updates context
– Gallery reads image list and renders ImageItem(s) with lazy loading
– ImageItem uses shared utils for helpers
– CustomAlertDialog & ContextualMenu invoked as needed (render-props)
5. User interactions (drag/drop, button clicks) propagate through Context API and custom hooks back into state

c. Architectural Patterns & Principles
- Single Context Provider for state & event handling → avoids prop drilling
- Functional components + React hooks (custom hooks under DragAndDropImagesManager/hooks)
- Modular structure: each component folder contains its code, styles, tests, and d.ts definitions
- Externalizing data-fetch logic into a provider module (ImagesDataProvider pattern)
- CI/CD via GitHub Actions, Vite build for production, GitHub Pages for hosting

d. Key Technologies & Frameworks
- React 18 + TypeScript
- Vite (dev server & build tool)
- TailwindCSS (via @tailwindcss/vite plugin)
- Context API + custom React hooks
- Vitest + Testing Library for unit tests
- GitHub Actions for CI/CD, GitHub Pages for deployment

## Diagram (Mermaid)

```mermaid
flowchart TD
    %% Browser and Hosting
    Browser["Browser (User Agent)"]:::client
    ViteServer["Vite Dev Server / Static Host"]:::pipeline
    click ViteServer "https://github.com/neuroflip/itacademy-sprint5-imagegallery/blob/main/vite.config.ts"
    Browser -->|"GET index.html"| ViteServer

    %% React SPA Layer
    subgraph "React SPA" 
        direction TB
        indexHTML["index.html"]:::client
        click indexHTML "https://github.com/neuroflip/itacademy-sprint5-imagegallery/blob/main/index.html"

        main["src/main.tsx"]:::client
        click main "https://github.com/neuroflip/itacademy-sprint5-imagegallery/blob/main/src/main.tsx"

        GlobalStyles["Global Styles (Tailwind)"]:::client
        click GlobalStyles "https://github.com/neuroflip/itacademy-sprint5-imagegallery/blob/main/src/index.css"

        AppShell["App Shell (App.tsx)"]:::client
        click AppShell "https://github.com/neuroflip/itacademy-sprint5-imagegallery/blob/main/src/App.tsx"

        subgraph "State & Data Layer"
            direction TB
            ImagesContext["ImagesManager Context Provider"]:::client
            click ImagesContext "https://github.com/neuroflip/itacademy-sprint5-imagegallery/blob/main/src/ImagesManager/ImagesManager.ts"
            PicSumProvider["Picsum Data Provider"]:::client
            click PicSumProvider "https://github.com/neuroflip/itacademy-sprint5-imagegallery/blob/main/src/ImagesManager/providers/PicSumImagesDataProvider.ts"
        end

        subgraph "UI Components"
            direction TB
            DragDropManager["DragAndDropImagesManager"]:::client
            click DragDropManager "https://github.com/neuroflip/itacademy-sprint5-imagegallery/blob/main/src/components/DragAndDropImagesManager/DragAndDropImagesManager.tsx"
            Gallery["Gallery"]:::client
            click Gallery "https://github.com/neuroflip/itacademy-sprint5-imagegallery/blob/main/src/components/Gallery/Gallery.tsx"
            ImageItem["ImageItem"]:::client
            click ImageItem "https://github.com/neuroflip/itacademy-sprint5-imagegallery/blob/main/src/components/ImageItem/ImageItem.tsx"
            ContextMenu["ContextualMenu"]:::client
            click ContextMenu "https://github.com/neuroflip/itacademy-sprint5-imagegallery/blob/main/src/components/ContextualMenu/ContextualMenu.tsx"
            AlertDialog["CustomAlertDialog"]:::client
            click AlertDialog "https://github.com/neuroflip/itacademy-sprint5-imagegallery/blob/main/src/components/CustomAlertDialog/CustomAlertDialog.tsx"
            ImageButton["ImageButton"]:::client
            click ImageButton "https://github.com/neuroflip/itacademy-sprint5-imagegallery/blob/main/src/components/ImageButton/CustomButton.tsx"
            Utils["Shared Utils"]:::client
            click Utils "https://github.com/neuroflip/itacademy-sprint5-imagegallery/blob/main/src/lib/utils.ts"
        end

        %% Internal Flows
        Browser -->|load| indexHTML
        indexHTML --> main
        main --> GlobalStyles
        main --> AppShell
        AppShell --> ImagesContext
        ImagesContext --> PicSumProvider
        PicSumProvider -->|fetch| Picsum
        Picsum -->|response| PicSumProvider
        PicSumProvider --> ImagesContext
        ImagesContext --> DragDropManager
        ImagesContext --> Gallery
        Gallery --> ImageItem
        DragDropManager --> ImagesContext
        ImageItem --> Utils
    end

    %% External API
    Picsum["Picsum API"]:::external

    %% CI/CD Pipeline
    subgraph "CI/CD Pipeline"
        direction TB
        ViteBuild["Vite Build"]:::pipeline
        click ViteBuild "https://github.com/neuroflip/itacademy-sprint5-imagegallery/blob/main/vite.config.ts"
        GitHubActions["GitHub Actions"]:::pipeline
        click GitHubActions "https://github.com/neuroflip/itacademy-sprint5-imagegallery/blob/main/.github/workflows/main.yml"
        Deploy["GitHub Pages"]:::pipeline
        click Deploy "https://github.com/neuroflip/itacademy-sprint5-imagegallery/blob/main/.github/workflows/ghpages.yml"
        ViteBuild --> GitHubActions --> Deploy
    end

    %% Styles
    classDef client fill:#D0E8FF,stroke:#0277BD,stroke-width:1px
    classDef pipeline fill:#FFE0B2,stroke:#EF6C00,stroke-width:1px
    classDef external fill:#C8E6C9,stroke:#2E7D32,stroke-width:1px
```
