# maximeperrindev/archive-manager architecture

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

- Interactive diagram: https://gitdiagram.com/maximeperrindev/archive-manager
- Repository: https://github.com/maximeperrindev/archive-manager

## Overview

##### Project Overview & Purpose
- Archive Manager is a Python-based utility designed to automatically manage the archiving process. It takes a compressed folder containing a SQL dump, downloads it from a specified URL, extracts the SQL file, and then uploads it to a remote WebDAV server.
- It also handles logging, notifications (via Mattermost and email), and supports execution via manual command line or scheduled Cron jobs.

##### Main Components
- Command Line / Cron Trigger: This represents the user or scheduler that runs the archive.py script.
- Main Application (archive.py): The central component that orchestrates the process.
- Configuration Module: Uses the conf.ini file (provided as conf_example.ini) to specify parameters like file URLs, server credentials, conservation time, and notification settings.
- File Downloader: Handles the retrieval of the compressed folder from a designated URL.
- Extraction Module: Unzips the downloaded file and extracts the SQL file.
- Logging System: Generates the archive.log file where all operational logs and error messages are recorded.
- Remote Server Client: Connects to the WebDAV server to upload the prepared archive.
- Notification System: Optionally sends notifications using Mail and Mattermost (if enabled in the configuration).
- Resources Folder: The directory that gets created by the script (stores the downloaded zip and extracted SQL file).

##### System Interactions & Data Flow
- The process starts when the script is invoked (either by a user manually or via a Cron job).
- The script reads the configuration from conf.ini to fetch settings (URLs, file names, server credentials, notification preferences).
- Using these settings, the File Downloader component downloads the compressed file.
- The Extraction Module processes the downloaded archive to extract the SQL file.
- Throughout these steps, each action (including errors) is logged by the Logging System.
- Next, the Remote Server Client connects (using provided credentials) to the WebDAV server to upload the processed archive.
- Upon completion of the above steps, the Notification System sends alerts (via email or Mattermost) to indicate the success or failure of each step.
- Finally, the system may also call a clean-up or verification module (if needed) to check for expired files based on the conservation time setting.

##### Architectural Patterns & Design Principles
- Modular Design: Although it’s a single script, the functionality is conceptually partitioned into discrete responsibilities (configuration, downloading, extraction, logging, uploading, notification).
- Separation of Concerns: Each functional component (e.g., file download vs. upload) is distinct, making it easier to maintain or extend.
- Automation & Scheduling: The design supports both manual execution and periodic execution through Cron.
- Fault Tolerance via Logging: Detailed logs ensure that error diagnosis is straightforward.

## Diagram (Mermaid)

```mermaid
flowchart TD
    T("User/Cron Trigger"):::trigger
    A("Archive Manager (archive.py)"):::process
    C("Configuration Module (conf)"):::process
    D("File Downloader"):::process
    F("File Source"):::external
    E("Extraction Module"):::process
    R("Resources Folder"):::storage
    L("Logging System"):::process
    U("Remote Server Client"):::process
    W("WebDAV Server"):::external
    N("Notification System"):::process
    Doc("Documentation & User Guides"):::doc
    Dep("Dependency Management (requirements.txt)"):::doc

    %% Main process flow
    T -->|"triggers"| A
    A -->|"reads"| C
    A -->|"initiates"| D
    D -->|"downloads"| F
    D -->|"passes"| E
    E -->|"produces"| R

    %% Logging at different stages
    A -->|"logs"| L
    D -->|"logs"| L
    E -->|"logs"| L
    U -->|"logs"| L

    %% Upload and notification flows
    A -->|"uploads"| U
    U -->|"uploads"| W
    A -->|"notifies"| N
    U -->|"notifies"| N

    %% Supporting components
    A ---|"refers"| Doc
    A ---|"uses"| Dep

    %% Styles
    classDef trigger fill:#FFD700,stroke:#333,stroke-width:2px;
    classDef process fill:#90EE90,stroke:#333,stroke-width:2px;
    classDef external fill:#ADD8E6,stroke:#333,stroke-width:2px;
    classDef storage fill:#F0E68C,stroke:#333,stroke-width:2px;
    classDef doc fill:#FFB6C1,stroke:#333,stroke-width:2px;

    %% Click Events
    click A "https://github.com/maximeperrindev/archive-manager/blob/master/archive.py"
    click C "https://github.com/maximeperrindev/archive-manager/blob/master/conf_example.ini"
    click Doc "https://github.com/maximeperrindev/archive-manager/tree/master/docs"
    click Dep "https://github.com/maximeperrindev/archive-manager/blob/master/requirements.txt"
```
