# thoprr/mlops_celebfaces_gan architecture

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

- Interactive diagram: https://gitdiagram.com/thoprr/mlops_celebfaces_gan
- Repository: https://github.com/thoprr/mlops_celebfaces_gan

## Overview

##### Project Type & Purpose
- This project is an MLOps-focused implementation of a Generative Adversarial Network (GAN) designed to generate celebrity face images using the CelebA dataset.
- Its primary objectives include:
- Training a GAN to generate images.
- Modularizing components for data preparation, model training, image generation, monitoring, and visualization.
- Ensuring MLOps best practices (logging, configuration, modular design) are followed.

##### Analyzing the File Structure
- The project is organized into several top-level directories:
- GAN_Project: Contains subdirectories such as:
◦ application: Handles API-like functions and external interfacing (image generation, GIF creation, monitoring).
◦ domain: Houses core GAN functionality, including model definitions, loss functions, training routines, optimizers, and utility functions.
◦ infrastructure: Manages external interactions such as data downloading, preprocessing (transformation), and image selection.
- config: Contains the configuration JSON file specifying paths and hyperparameters.
- data: Serves as the repository for input data.
- training: Contains directories for generated images and saved models from training.
- logs: Stores CSV logs recording training progress and metrics.
- docs: Provides additional documentation and examples (MLOps documentation with visualizations).
- Demo GAN.ipynb (in GAN_Project): Serves as a Jupyter Notebook demo for executing the data loading, training, image generation, and GIF creation routines.
- The separation into application, domain, and infrastructure clearly reflects a layered (or hexagonal) architecture where responsibilities are distinctly partitioned.

##### Key System Components
a. Configuration Component:
- Use the config directory and config.json file.
- This as the central configuration hub controlling directories (data, logs, models) and training hyperparameters.
b. Data & Preprocessing:
- The data directory acts as the source of input data.
- Within the infrastructure and domain layers, the data_loader and transform modules facilitate data ingestion and preprocessing.
c. Core GAN Functionality (Domain Layer):
- Components for:
- GAN Models (gan_models.py)
- Training routine (gan_training.py)
- Loss Calculations (gan_losses.py)
- Optimizers (gan_optimizers.py)
- Utility functions (gan_utils.py)
- Custom logger (gan_logger.py)
d. Application Layer:
- Responsible for exposing functionality through API-like endpoints:
- Image generation (gan_generator.py, generate_image.py)
- GIF creation for tracking training evolution (generate_gif.py)
- Monitoring training logs (monitoring.py)
- Components that can be triggered via the Notebook (Demo GAN.ipynb).
e. Infrastructure Layer:
- Supports external operations:
- Data download (download.py)
- Image selection and transformation (image_selector.py, transform.py)
f. Training & Persistence:
- Training directory that stores:
- Generated images (for visualization)
- Saved models (generator checkpoints)
g. Logging & Monitoring:
- Logs directory containing CSV files that capture model training metrics.
- Monitoring utilities contained in the application code.

##### Relationships and Interactions
- The config component provides settings to all layers.
- The Data component (and its preprocessing modules) feeds into the domain layer for training.
- The domain layer (model, training, loss, optimizers) performs the core computations.
- The application layer triggers domain methods via exposed functions to generate images or GIFs.
- The infrastructure layer supplements the domain and application with data operations (downloading, transforming).
- Training outputs (models, generated images) are logged and saved, and monitoring is handled by a dedicated component.

##### Architectural Patterns & Technologies to Highlight
- Layered architecture (Application, Domain, Infrastructure) that promotes separation of concerns.
- MLOps design pattern with modular components for:
- Model training and data management.
- Visualization via GIF generation.
- Detailed logging and monitoring.
- Recognize that the notebook (Demo GAN.ipynb) serves both as a demo and as an interactive interface to the system.
- Pointers to key frameworks/libraries (e.g., Keras for model saving, Python for scripting) as indicated by the file types (.keras, Python files).

## Diagram (Mermaid)

```mermaid
flowchart TD
    %% Configuration Layer
    subgraph "Configuration"
        config["Configuration (config.json)"]
    end

    %% Data & Preprocessing Layer
    subgraph "Data & Preprocessing"
        data["Data Directory"]
        transformModule["Transform Module"]
        infraDataLoader["Infra Data Loader"]
        domainDataLoader["Domain Data Loader"]
    end

    %% Domain Layer (GAN Core)
    subgraph "Domain Layer (GAN Core)"
        ganModels["GAN Models"]
        ganLosses["GAN Loss Functions"]
        ganOptimizers["GAN Optimizers"]
        ganUtils["GAN Utility Functions"]
        ganLogger["Custom Logger"]
        ganTraining["GAN Training Routine"]
    end

    %% Application Layer
    subgraph "Application Layer"
        ganGen["Image Generation API"]
        generateImage["Generate Image Module"]
        gifGen["GIF Generation Module"]
        monitoring["Monitoring Module"]
        notebook["Demo GAN Notebook"]
    end

    %% Infrastructure Layer
    subgraph "Infrastructure Layer"
        downloader["Data Downloader"]
        imgSelector["Image Selector"]
    end

    %% Training & Persistence
    subgraph "Training & Persistence"
        savedModels["Saved Models"]
        genImages["Generated Images"]
    end

    %% Logging & Monitoring
    subgraph "Logging & Monitoring"
        logs["Logs Directory"]
    end

    %% Connections
    config --> data
    config --> ganLogger
    config --> downloader

    data --> domainDataLoader
    data --> infraDataLoader

    transformModule --> domainDataLoader

    domainDataLoader --> ganTraining
    infraDataLoader --> ganTraining

    ganModels --- ganTraining
    ganLosses --- ganTraining
    ganOptimizers --- ganTraining
    ganUtils --- ganTraining
    ganLogger --- ganTraining

    ganTraining --> savedModels
    ganTraining --> genImages

    ganTraining --> ganGen
    ganTraining --> gifGen

    notebook --> ganGen
    notebook --> generateImage
    notebook --> gifGen
    notebook --> monitoring

    downloader --> data
    imgSelector --> transformModule

    ganLogger --> logs
    monitoring --> logs

    %% Click Events
    click config "https://github.com/thoprr/mlops_celebfaces_gan/blob/main/config/config.json"
    click data "https://github.com/thoprr/mlops_celebfaces_gan/tree/main/data"
    click transformModule "https://github.com/thoprr/mlops_celebfaces_gan/blob/main/GAN_Project/infrastructure/transform.py"
    click infraDataLoader "https://github.com/thoprr/mlops_celebfaces_gan/blob/main/GAN_Project/infrastructure/data_loader.py"
    click domainDataLoader "https://github.com/thoprr/mlops_celebfaces_gan/blob/main/GAN_Project/domain/data_loader.py"
    click ganModels "https://github.com/thoprr/mlops_celebfaces_gan/blob/main/GAN_Project/domain/gan_models.py"
    click ganLosses "https://github.com/thoprr/mlops_celebfaces_gan/blob/main/GAN_Project/domain/gan_losses.py"
    click ganTraining "https://github.com/thoprr/mlops_celebfaces_gan/blob/main/GAN_Project/domain/gan_training.py"
    click ganOptimizers "https://github.com/thoprr/mlops_celebfaces_gan/blob/main/GAN_Project/domain/gan_optimizers.py"
    click ganUtils "https://github.com/thoprr/mlops_celebfaces_gan/blob/main/GAN_Project/domain/gan_utils.py"
    click ganLogger "https://github.com/thoprr/mlops_celebfaces_gan/blob/main/GAN_Project/domain/gan_logger.py"
    click ganGen "https://github.com/thoprr/mlops_celebfaces_gan/blob/main/GAN_Project/application/gan_generator.py"
    click generateImage "https://github.com/thoprr/mlops_celebfaces_gan/blob/main/GAN_Project/application/generate_image.py"
    click gifGen "https://github.com/thoprr/mlops_celebfaces_gan/blob/main/GAN_Project/application/generate_gif.py"
    click monitoring "https://github.com/thoprr/mlops_celebfaces_gan/blob/main/GAN_Project/application/monitoring.py"
    click notebook "https://github.com/thoprr/mlops_celebfaces_gan/blob/main/GAN_Project/Demo GAN.ipynb"
    click downloader "https://github.com/thoprr/mlops_celebfaces_gan/blob/main/GAN_Project/infrastructure/download.py"
    click imgSelector "https://github.com/thoprr/mlops_celebfaces_gan/blob/main/GAN_Project/infrastructure/image_selector.py"
    click savedModels "https://github.com/thoprr/mlops_celebfaces_gan/tree/main/training/saved_models"
    click genImages "https://github.com/thoprr/mlops_celebfaces_gan/tree/main/training/generated_images"
    click logs "https://github.com/thoprr/mlops_celebfaces_gan/tree/main/logs"

    %% Styles
    classDef configStyle fill:#FFD700,stroke:#333,stroke-width:2px;
    classDef dataStyle fill:#ADD8E6,stroke:#333,stroke-width:2px;
    classDef domainStyle fill:#90EE90,stroke:#333,stroke-width:2px;
    classDef appStyle fill:#FFB6C1,stroke:#333,stroke-width:2px;
    classDef infraStyle fill:#FFA07A,stroke:#333,stroke-width:2px;
    classDef trainingStyle fill:#D3D3D3,stroke:#333,stroke-width:2px;
    classDef logStyle fill:#D8BFD8,stroke:#333,stroke-width:2px;

    class config configStyle;
    class data,transformModule,infraDataLoader,domainDataLoader dataStyle;
    class ganModels,ganLosses,ganOptimizers,ganUtils,ganLogger,ganTraining domainStyle;
    class ganGen,generateImage,gifGen,monitoring,notebook appStyle;
    class downloader,imgSelector infraStyle;
    class savedModels,genImages trainingStyle;
    class logs logStyle;
```
