# brayandm/backup-manager architecture

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

- Interactive diagram: https://gitdiagram.com/brayandm/backup-manager
- Repository: https://github.com/brayandm/backup-manager

## Overview

##### Main Components
- Frontend: Represent the Next.js application housed in the “frontend” directory. Note that it handles user interface elements (login, dashboards, backup configuration, migration configurations, etc.) and communicates with the backend via API endpoints.
- Backend: Represent the Laravel (or similar PHP framework) application located in the “backend” directory. Its structure includes:
- Controllers to handle HTTP requests (e.g., AnalyticsController, AuthController, BackupController, etc.)
- Models and Entities that capture domain objects like Backup, DataSource, StorageServer, etc.
- Jobs for asynchronous tasks (BackupJob, RetentionPolicyJob, MigrationJob, etc.)
- Services that encapsulate business logic for backups, migrations, notifications, and analytics.
- Console commands that allow CLI operations (e.g., RunBackup, RunMigration).
- Docker Infrastructure: Represent how Docker is used to containerize both frontend and backend. Include components such as:
- Docker files for PHP (backend), MySQL (backend/docker/mysql), and the Next.js frontend.
- Docker Compose setups (docker-compose.yml) that empower deployment and orchestration.
- External Services and Integrations:
- AWS S3 integration for both data sources and storage servers.
- SSH and Docker container connections for chaining data transfers.
- Telegram for notifications.
- External API endpoints that might be utilized by both backend and frontend.

##### Relationships and Interactions
- The Frontend communicates with the Backend via RESTful API endpoints (as indicated by the routes/api in both the frontend and backend).
- The Backend interacts with the Database for CRUD operations corresponding to backups, migration configurations, and settings.
- The Backend uses Jobs and Queues to process scheduled or asynchronous tasks (backup operations, free-space calculations, availability checks, etc.).
- CLI commands (exposed via “backup-manager” shell script) interact with both the Docker orchestration and the backend application to manage installations, start, stop, update, and version operations.
- External integrations (AWS S3, Telegram, etc.) are invoked by the backend’s Services or Entities.
- Docker provides isolation and orchestration between the frontend, backend, and their dependencies (like MySQL).

##### Architectural Patterns and Design Principles
- Model-View-Controller (MVC): The backend clearly follows the MVC pattern for handling requests, processing logic (through jobs and services), and interacting with the database.
- Microservice-like Separation (within a monorepo): Although not technically microservices (everything is part of a single project), there is a clear separation of concerns between the “frontend” and “backend,” with both being managed via Docker.
- Command and Job Scheduling: The backend’s CLI commands and Jobs indicate a design that emphasizes asynchronous task processing.
- Containerization and Environment Configuration: Use Docker and environment files to manage different deployment environments.

##### Technologies and Frameworks
- Backend: PHP (likely Laravel), with artisan CLI, dependency injection through providers, and extensive use of jobs and config files.
- Frontend: Next.js with React, Tailwind CSS, Typescript, and associated modern JavaScript tooling (eslintrc, prettier, tsconfig).
- Databases: Both configuration and migration files imply a SQL database (MySQL/PostgreSQL).
- Docker: Multiple Dockerfiles for PHP, MySQL, and frontend deployment, along with Docker Compose orchestration.

## Diagram (Mermaid)

```mermaid
flowchart TD
    subgraph "Frontend Layer"
        F["Frontend (Next.js Application)"]:::frontend
    end

    subgraph "Backend Layer"
        B["Backend (Laravel API & Business Logic)"]:::backend
        B1["Controllers (HTTP Request Handling)"]:::backend
        B2["Models"]:::backend
        B3["Entities"]:::backend
        B4["Jobs (Asynchronous Tasks)"]:::backend
        B5["Services (Business Logic)"]:::backend
    end

    subgraph "Database"
        DB["Database"]:::database
    end

    subgraph "External Integrations"
        subgraph "AWS S3 Integration"
            E1["AWS S3 Data Source"]:::external
            E2["AWS S3 Storage"]:::external
        end
        subgraph "Telegram Integration"
            E3["Telegram Controller"]:::external
            E4["Telegram Service"]:::external
        end
    end

    subgraph "Deployment & Containerization"
        D1["Docker Compose"]:::deployment
        D2["Backend Dockerfiles"]:::deployment
        D3["Frontend Dockerfiles"]:::deployment
    end

    subgraph "CLI/Management"
        CLI["Backup Manager Script"]:::deployment
    end

    %% Relationships
    F -->|"API calls"| B
    B -->|"handles"| B1
    B -->|"uses"| B2
    B -->|"uses"| B3
    B -->|"schedules"| B4
    B -->|"delegates to"| B5
    B -->|"CRUD operations"| DB

    B5 -->|"invokes"| E1
    B5 -->|"invokes"| E2
    B5 -->|"invokes"| E4

    %% Docker relationships
    CLI -->|"orchestrates"| D1
    D1 -->|"containers for"| F
    D1 -->|"containers for"| B
    D1 -->|"containers for"| DB
    D2 --- B
    D3 --- F

    %% Click Events
    click F "https://github.com/brayandm/backup-manager/tree/main/frontend/"
    click B "https://github.com/brayandm/backup-manager/tree/main/backend/"
    click B1 "https://github.com/brayandm/backup-manager/tree/main/backend/app/Http/Controllers/"
    click B2 "https://github.com/brayandm/backup-manager/tree/main/backend/app/Models/"
    click B3 "https://github.com/brayandm/backup-manager/tree/main/backend/app/Entities/"
    click B4 "https://github.com/brayandm/backup-manager/tree/main/backend/app/Jobs/"
    click B5 "https://github.com/brayandm/backup-manager/tree/main/backend/app/Services/"
    click DB "https://github.com/brayandm/backup-manager/tree/main/backend/database/"
    click D1 "https://github.com/brayandm/backup-manager/blob/main/docker-compose.yml"
    click D2 "https://github.com/brayandm/backup-manager/tree/main/backend/docker/"
    click D3 "https://github.com/brayandm/backup-manager/tree/main/frontend/docker/"
    click E1 "https://github.com/brayandm/backup-manager/blob/main/backend/app/Entities/DataSourceDrivers/AwsS3Driver.php"
    click E2 "https://github.com/brayandm/backup-manager/blob/main/backend/app/Entities/StorageServerDrivers/AwsS3Driver.php"
    click E3 "https://github.com/brayandm/backup-manager/blob/main/backend/app/Http/Controllers/TelegramController.php"
    click E4 "https://github.com/brayandm/backup-manager/blob/main/backend/app/Services/TelegramService.php"
    click CLI "https://github.com/brayandm/backup-manager/blob/main/backup-manager.sh"

    %% Styles
    classDef frontend fill:#AEDFF7,stroke:#333,stroke-width:2px;
    classDef backend fill:#C1F0C1,stroke:#333,stroke-width:2px;
    classDef database fill:#F7E1AE,stroke:#333,stroke-width:2px;
    classDef deployment fill:#FFD9B3,stroke:#333,stroke-width:2px;
    classDef external fill:#D6B3FF,stroke:#333,stroke-width:2px;
```
