# pionl/laravel-chunk-upload architecture

> Architecture diagram of the GitHub repository pionl/laravel-chunk-upload, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2025-01-06). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/pionl/laravel-chunk-upload
- Repository: https://github.com/pionl/laravel-chunk-upload

## Overview

##### Main Components

a) Client-Side Components:
- Multiple supported JavaScript libraries (Resumable.js, DropZone, jQuery-File-Upload, etc.)
- File chunking mechanism
- Upload progress tracking

b) Server-Side Components:
- Upload Handlers (Different implementations for each supported client library)
- File Receiver
- Chunk Storage System
- File Merger
- Configuration Management
- Service Provider

##### Client Layer
- Them to a common "Upload Request" interface

##### Server Layer
- HandlerFactory as the entry point
- Individual Upload Handlers
- FileReceiver as the central processing unit
- Storage and Save components

##### Specific Implementation Details

- Blue rectangles for client-side components
- Green rectangles for request handlers
- Yellow diamonds for decision points (HandlerFactory)
- Orange rectangles for storage components
- Purple rectangles for save operations

**[Client Libraries] → [Upload Request]**
- ↓
**[HandlerFactory] → [Specific Upload Handlers]**
- ↓
**[FileReceiver]**
- ↓
**[ChunkStorage] ←→ [FileMerger]**
- ↓
**[Save Operations]**

##### Important Elements to Highlight

- Parallel upload support for specific handlers
- Chunk management flow
- Error handling pathways
- Configuration injection points
- Service provider integration

##### Technical Details

- Relationship between AbstractHandler and specific implementations
- Save process flow (SingleSave, ChunkSave, ParallelSave)
- Demonstrate how the ChunkStorage interacts with Laravel's storage system
- Command system for chunk cleanup

##### Implementation Notes

- The package's modular design
- The handler factory pattern implementation
- The separation of concerns between upload handling and storage
- The extensibility points for new upload handlers

## Diagram (Mermaid)

```mermaid
flowchart TB
    subgraph Client["Client Layer"]
        direction TB
        ResumableJS["Resumable.js"]:::client
        DropZone["DropZone"]:::client
        NgFileUpload["Ng-File-Upload"]:::client
        ContentRange["Content Range"]:::client
        SingleUpload["Single Upload"]:::client
    end

    subgraph Handler["Handler Layer"]
        direction TB
        HandlerFactory["Handler Factory"]:::factory
        AbstractHandler["Abstract Handler"]:::abstract
        ResumableHandler["Resumable Handler"]:::handler
        DropZoneHandler["DropZone Handler"]:::handler
        NgHandler["NgFileUpload Handler"]:::handler
        ContentRangeHandler["Content Range Handler"]:::handler
        SingleHandler["Single Upload Handler"]:::handler
        ParallelTrait["Parallel Upload Trait"]:::trait
    end

    subgraph Core["Core Components"]
        direction TB
        FileReceiver["File Receiver"]:::core
        ChunkStorage["Chunk Storage"]:::storage
        FileMerger["File Merger"]:::core
        ChunkFile["Chunk File"]:::model
    end

    subgraph Save["Save Operations"]
        direction TB
        AbstractSave["Abstract Save"]:::abstract
        SingleSave["Single Save"]:::save
        ChunkSave["Chunk Save"]:::save
        ParallelSave["Parallel Save"]:::save
    end

    subgraph Config["Configuration"]
        direction TB
        AbstractConfig["Abstract Config"]:::abstract
        FileConfig["File Config"]:::config
        ConfigFile["Config File"]:::config
    end

    subgraph Provider["Service Layer"]
        direction TB
        ServiceProvider["Upload Service Provider"]:::provider
        ChunkCleanup["Chunk Cleanup Command"]:::maintenance
    end

    %% Relationships
    ResumableJS --> ResumableHandler
    DropZone --> DropZoneHandler
    NgFileUpload --> NgHandler
    ContentRange --> ContentRangeHandler
    SingleUpload --> SingleHandler

    HandlerFactory --> AbstractHandler
    AbstractHandler --> |extends| ResumableHandler
    AbstractHandler --> |extends| DropZoneHandler
    AbstractHandler --> |extends| NgHandler
    AbstractHandler --> |extends| ContentRangeHandler
    AbstractHandler --> |extends| SingleHandler
    ParallelTrait --> ResumableHandler
    ParallelTrait --> DropZoneHandler

    HandlerFactory --> FileReceiver
    FileReceiver --> ChunkStorage
    FileReceiver --> FileMerger
    ChunkStorage --> ChunkFile
    FileMerger --> ChunkFile

    AbstractSave --> SingleSave
    AbstractSave --> ChunkSave
    AbstractSave --> ParallelSave
    FileReceiver --> AbstractSave

    AbstractConfig --> FileConfig
    FileConfig --> ConfigFile
    ServiceProvider --> ChunkCleanup
    ServiceProvider --> HandlerFactory

    %% Click Events
    click ResumableHandler "https://github.com/pionl/laravel-chunk-upload/blob/master/src/Handler/ResumableJSUploadHandler.php"
    click DropZoneHandler "https://github.com/pionl/laravel-chunk-upload/blob/master/src/Handler/DropZoneUploadHandler.php"
    click NgHandler "https://github.com/pionl/laravel-chunk-upload/blob/master/src/Handler/NgFileUploadHandler.php"
    click ContentRangeHandler "https://github.com/pionl/laravel-chunk-upload/blob/master/src/Handler/ContentRangeUploadHandler.php"
    click SingleHandler "https://github.com/pionl/laravel-chunk-upload/blob/master/src/Handler/SingleUploadHandler.php"
    click HandlerFactory "https://github.com/pionl/laravel-chunk-upload/blob/master/src/Handler/HandlerFactory.php"
    click FileReceiver "https://github.com/pionl/laravel-chunk-upload/blob/master/src/Receiver/FileReceiver.php"
    click ChunkStorage "https://github.com/pionl/laravel-chunk-upload/blob/master/src/Storage/ChunkStorage.php"
    click FileMerger "https://github.com/pionl/laravel-chunk-upload/blob/master/src/FileMerger.php"
    click AbstractHandler "https://github.com/pionl/laravel-chunk-upload/blob/master/src/Handler/AbstractHandler.php"
    click AbstractSave "https://github.com/pionl/laravel-chunk-upload/blob/master/src/Save/AbstractSave.php"
    click SingleSave "https://github.com/pionl/laravel-chunk-upload/blob/master/src/Save/SingleSave.php"
    click ChunkSave "https://github.com/pionl/laravel-chunk-upload/blob/master/src/Save/ChunkSave.php"
    click ParallelSave "https://github.com/pionl/laravel-chunk-upload/blob/master/src/Save/ParallelSave.php"
    click AbstractConfig "https://github.com/pionl/laravel-chunk-upload/blob/master/src/Config/AbstractConfig.php"
    click FileConfig "https://github.com/pionl/laravel-chunk-upload/blob/master/src/Config/FileConfig.php"
    click ConfigFile "https://github.com/pionl/laravel-chunk-upload/blob/master/config/chunk-upload.php"
    click ServiceProvider "https://github.com/pionl/laravel-chunk-upload/blob/master/src/Providers/ChunkUploadServiceProvider.php"
    click ChunkCleanup "https://github.com/pionl/laravel-chunk-upload/blob/master/src/Commands/ClearChunksCommand.php"
    click ParallelTrait "https://github.com/pionl/laravel-chunk-upload/blob/master/src/Handler/Traits/HandleParallelUploadTrait.php"
    click ChunkFile "https://github.com/pionl/laravel-chunk-upload/blob/master/src/ChunkFile.php"

    %% Styles
    classDef client fill:#2196F3,stroke:#1565C0,color:white
    classDef handler fill:#4CAF50,stroke:#2E7D32,color:white
    classDef factory fill:#FFC107,stroke:#FFA000,color:black
    classDef core fill:#9C27B0,stroke:#7B1FA2,color:white
    classDef storage fill:#FF5722,stroke:#E64A19,color:white
    classDef save fill:#795548,stroke:#5D4037,color:white
    classDef config fill:#607D8B,stroke:#455A64,color:white
    classDef provider fill:#009688,stroke:#00796B,color:white
    classDef maintenance fill:#F44336,stroke:#D32F2F,color:white
    classDef abstract fill:#9E9E9E,stroke:#616161,color:white
    classDef model fill:#3F51B5,stroke:#303F9F,color:white
    classDef trait fill:#8BC34A,stroke:#689F38,color:white
```
