# hamza-el-khatib/pdfgenerator architecture

> Architecture diagram of the GitHub repository hamza-el-khatib/pdfgenerator, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2024-12-27). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/hamza-el-khatib/pdfgenerator
- Repository: https://github.com/hamza-el-khatib/pdfgenerator

## Overview

##### Main Components

a) Core Components:
- Web Layer (Controllers)
- Service Layer
- Configuration Layer
- Utility Layer
- File Storage System
- Async Task Management System

b) External Components:
- Web Content Source (Inditex Export Service)
- Playwright Browser Instance
- PDFBox Processing Engine
- File System Storage

**┌─ Client Layer ─────────────────────────────────┐**
- HTTP Requests                  │
- ┬─────────────────────────────┘
- ↓
**┌─ API Layer ───────────────────────────────────┐**
- PdfController (REST APIs)            │
- ┬─────────────────────────────┘
- ↓
**┌─ Service Layer ───────────────────────────────┐**
- ┌─────────────┐  ┌──────────┐  ┌───────────┐  │
- PdfGenerator │  │PdfTask   │  │FileCleanup│  │
- Service      │←→│Manager   │←→│Service    │  │
- ┘  └──────────┘  └───────────┘  │
- ┬─────────────┬──────────────┬──────────┘
- ↓             ↓              ↓
**┌─ External Services ─────────────────────────────┐**
- ┌─────────┐ ┌────────┐ ┌───────┐ ┌──────────┐ │
- Playwright│ │PDFBox  │ │Storage│ │Web Source│ │
- ┘ └────────┘ └───────┘ └──────────┘ │
- ┘

##### Key Relationships to Highlight

a) Request Flow:
- Client → PdfController → PdfGeneratorService
- Async task creation and management
- PDF chunk processing and merging
- File cleanup processes

b) Data Flow:
- Web content fetching
- PDF generation and manipulation
- Storage operations
- Cleanup procedures

##### Important Details

a) Configuration Properties:
- PDF storage paths
- Cleanup intervals
- Batch sizes
- Thread pool configurations

b) Async Operations:
- Thread pool executor
- Task management
- Parallel PDF processing

c) Security:
- Cookie handling
- CORS configuration
- Domain restrictions

##### Technical Specifications

- Java 17 runtime
- Spring Boot framework
- Playwright/PDFBox versions
- Memory/CPU requirements

##### Monitoring Points

Highlight:
- Task status checkpoints
- File system monitoring
- Performance metrics
- Error logging points

This design should reflect the Spring Boot architecture while highlighting the unique aspects of this PDF generation service, particularly its handling of large-scale PDF processing through chunking and parallel execution.

## Diagram (Mermaid)

```mermaid
flowchart TB
    %% Styles
    classDef controller fill:#2196F3,stroke:#1565C0,color:white
    classDef service fill:#4CAF50,stroke:#2E7D32,color:white
    classDef config fill:#FF9800,stroke:#F57C00,color:white
    classDef utils fill:#9C27B0,stroke:#7B1FA2,color:white
    classDef external fill:#607D8B,stroke:#455A64,color:white
    classDef storage fill:#795548,stroke:#5D4037,color:white
    classDef async fill:#FFC107,stroke:#FFA000,color:black
    
    %% Client Layer
    Client[Client Requests]:::external
    
    %% API Layer
    PdfController["PDF Controller"]:::controller
    click PdfController "https://github.com/Hamza-EL-KHATIB/pdfgenerator/blob/master/src/main/java/com/hamzaelkhatib/pdfgenerator/controller/PdfController.java"
    
    %% Service Layer
    PdfGenService["PDF Generator Service"]:::service
    click PdfGenService "https://github.com/Hamza-EL-KHATIB/pdfgenerator/blob/master/src/main/java/com/hamzaelkhatib/pdfgenerator/service/PdfGeneratorService.java"
    
    TaskManager["PDF Task Manager"]:::async
    click TaskManager "https://github.com/Hamza-EL-KHATIB/pdfgenerator/blob/master/src/main/java/com/hamzaelkhatib/pdfgenerator/service/PdfTaskManager.java"
    
    CleanupService["File Cleanup Service"]:::service
    click CleanupService "https://github.com/Hamza-EL-KHATIB/pdfgenerator/blob/master/src/main/java/com/hamzaelkhatib/pdfgenerator/service/FileCleanupService.java"
    
    %% Configuration Layer
    AsyncConfig["Async Configuration"]:::config
    click AsyncConfig "https://github.com/Hamza-EL-KHATIB/pdfgenerator/blob/master/src/main/java/com/hamzaelkhatib/pdfgenerator/config/AsyncConfig.java"
    
    ConfigProps["Config Properties"]:::config
    click ConfigProps "https://github.com/Hamza-EL-KHATIB/pdfgenerator/blob/master/src/main/java/com/hamzaelkhatib/pdfgenerator/config/ConfigProperties.java"
    
    %% Utility Layer
    PdfUtils["PDF Utilities"]:::utils
    click PdfUtils "https://github.com/Hamza-EL-KHATIB/pdfgenerator/blob/master/src/main/java/com/hamzaelkhatib/pdfgenerator/utils/PdfUtils.java"
    
    CookieHelper["Cookie Helper"]:::utils
    click CookieHelper "https://github.com/Hamza-EL-KHATIB/pdfgenerator/blob/master/src/main/java/com/hamzaelkhatib/pdfgenerator/utils/CookieHelper.java"
    
    %% External Services
    Playwright["Playwright Browser"]:::external
    PDFBox["PDFBox Engine"]:::external
    Storage["File System Storage"]:::storage
    WebSource["Web Content Source"]:::external
    
    %% Main Application
    MainApp["PDF Generator Application"]:::service
    click MainApp "https://github.com/Hamza-EL-KHATIB/pdfgenerator/blob/master/src/main/java/com/hamzaelkhatib/pdfgenerator/PdfgeneratorApplication.java"
    
    %% Relationships
    Client --> PdfController
    PdfController --> PdfGenService
    PdfGenService --> TaskManager
    TaskManager --> CleanupService
    
    PdfGenService --> Playwright
    PdfGenService --> PDFBox
    PdfGenService --> Storage
    PdfGenService --> WebSource
    
    TaskManager --> AsyncConfig
    MainApp --> ConfigProps
    
    PdfGenService --> PdfUtils
    PdfController --> CookieHelper
    
    %% Legend
    subgraph Legend
        Controller["Controller"]:::controller
        Service["Service"]:::service
        Configuration["Configuration"]:::config
        Utility["Utility"]:::utils
        ExternalService["External Service"]:::external
        StorageSystem["Storage"]:::storage
        AsyncComponent["Async Component"]:::async
    end
```
