# microbialgenomics/shiny-phyloseq architecture

> Architecture diagram of the GitHub repository microbialgenomics/shiny-phyloseq, 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/microbialgenomics/shiny-phyloseq
- Repository: https://github.com/microbialgenomics/shiny-phyloseq

## Overview

##### Project Type and Purpose
- The README and file structure clearly indicate that this is an interactive web application built with R’s Shiny framework.
- Its purpose is to provide a graphical user interface to the phyloseq package, streamlining microbiome analysis.
- It is intended to be run as a local web application (or potentially hosted remotely), where the backend is an R session and the frontend is rendered in a web browser.

##### File Structure
- Top-level files like server.R, ui.R, and global.R signify the standard Shiny application structure.
- The “panels” directory contains several R scripts for UI and server panels (e.g., panel-server-bar.R, panel-ui-bar.R, etc.) that modularize different visualization and data interaction components.
- The “core” directory includes custom R functions (for example, default parameters and plotting utilities like ggsave.R) used throughout the application.
- Directories such as “js-scripts” and “www” indicate integration of custom JavaScript (for extra interactivity, e.g., inactivity handling) and possibly CSS or static assets that style the UI.
- The “data” directory holds sample or saved sessions, which, while not a database, reflects data inputs or persisted analysis states.
- Other directories like “r-moduls” and “provenance-staging” further indicate modular code components and areas for tracking analysis provenance (important in reproducible research).

##### README for Additional Insights
- The README emphasizes both the front end (browser-based) and the back end (R session) components, noting that the complete experience is created by the integration of Shiny and the phyloseq package.
- It outlines launching instructions, reinforcing that the application is both a full-stack (backend with R and frontend via web browser) and modular application.

a. Main Components:
- Frontend (User Interface):
- Represented by the ui.R file, the “panels” directory (which contains UI-specific panels like panel-ui-bar.R, panel-ui-data.R, etc.), and static files in the “www” directory.
- Integration with custom JavaScript from “js-scripts” for client-side behavior.
- Backend (Server Logic):
- Defined in server.R, along with supporting files such as global.R and helper functions in the “core” directory.
- The “r-moduls” directory provides modules for tasks like data loading.
- Data & Session Management:
- The “data” directory holding session data and possibly other input data used by phyloseq.
- “provenance-staging” suggests a mechanism for tracking analytical provenance, which could be showcased as an element that logs or visualizes the steps/transformations during analysis.
- External Dependencies & Runtime:
- The project relies on R, Shiny, phyloseq, and associated R packages.
- The Dockerfile indicates containerization for deployment, so include a component for deployment/runtime environment.

b. Relationships and Interactions:
- Flow from the User’s Web Browser (Frontend) sending requests/input events to the Shiny Server (backend).
- The backend (server.R) processes these inputs by leveraging global settings, core functions, and specialized panel modules.
- Once processed, data and computed results are sent back to the UI panels for interactive display.
- Optional communication with external scripts (e.g., js-scripts) provides additional interactivity.
- The Dockerfile points to an environment layer ensuring consistency in the runtime deployment.

c. Architectural Patterns and Design Principles:
- Modular design: Clearly separated UI panels and server logic for maintainability.
- MVC-like separation: The UI layer (views) is distinct from the server logic (model and controller) managed by R scripts.
- Provenance tracking: Highlighting how user actions and analysis steps are captured and could be replayed or audited.
- Use of containerization: Dockerfile indicates best practices for reproducible deployments.

d. Relevant Technologies and Frameworks:
- R and Shiny as the primary platform.
- phyloseq – the underlying library for microbiome analysis.
- Docker for containerized deployment.
- Standard web technologies (HTML, CSS, JavaScript) for the frontend interactions.
- Possibly ggplot2 (inferred from the use of ggsave) for graphical output.

- Each component should have a clear label:
- Example: “User Browser (Frontend)” with UI elements, “Shiny Server (Backend)”, “Core Functions”, “Data Input/Output”, “Provenance Logger”, “Dockerized Environment”.
- From User Browser to Shiny Server (input events), from Shiny Server to UI panels (rendered output), and from core modules to data stores.
- Incorporate any configuration/deployment cues:

This detailed breakdown should enable a precise and comprehensive visualization of the application’s architecture tailored to the specifics of the Shiny-phyloseq project.

## Diagram (Mermaid)

```mermaid
flowchart TD
    %% Global Entities
    Browser["User Browser (Frontend)"]:::frontend
    
    %% Frontend Layer
    subgraph "Frontend (User Interface)"
        UI["ui.R"]:::frontend
        Panels["panels/ (UI Panels)"]:::frontend
        WWW["www/ (Static Assets)"]:::frontend
        JS["js-scripts/ (Inactivity Handling)"]:::frontend
    end

    %% Backend Layer
    subgraph "Backend (Server Logic)"
        Server["server.R"]:::backend
        Global["global.R"]:::backend
        Core["core/ (Default Parameters, ggsave)"]:::backend
        RModules["r-moduls/ (Load Data)"]:::backend
    end

    %% Data & Session Management
    subgraph "Data & Session Management"
        Data["data/ (Session Data)"]:::data
        Provenance["provenance-staging/ (Provenance Tracking)"]:::data
    end

    %% Deployment Environment
    Deployment["Docker Container (Dockerfile)"]:::deploy

    %% Connections from User Browser to Frontend
    Browser -->|"loads"| UI
    Browser -->|"loads"| WWW
    Browser -->|"loads"| JS

    %% Frontend internal flow
    UI -->|"navigates"| Panels

    %% Frontend to Backend communication
    Panels -->|"triggers"| Server
    UI -->|"sendsInputTo"| Server

    %% Backend internal interactions
    Server -->|"uses"| Global
    Server -->|"calls"| Core
    Server -->|"invokes"| RModules

    %% Backend Data interactions
    Server -->|"retrieves"| Data
    Server -->|"logsTo"| Provenance

    %% Backend to Frontend feedback
    Server -->|"rendersOutputTo"| UI

    %% Deployment (Runtime Environment)
    UI -->|"runsIn"| Deployment
    Server -->|"runsIn"| Deployment
    Data -->|"runsIn"| Deployment

    %% Click Events
    click UI "https://github.com/microbialgenomics/shiny-phyloseq/blob/master/ui.R"
    click Panels "https://github.com/microbialgenomics/shiny-phyloseq/tree/master/panels/"
    click WWW "https://github.com/microbialgenomics/shiny-phyloseq/tree/master/www/"
    click JS "https://github.com/microbialgenomics/shiny-phyloseq/blob/master/js-scripts/inactivity.R"
    click Server "https://github.com/microbialgenomics/shiny-phyloseq/blob/master/server.R"
    click Global "https://github.com/microbialgenomics/shiny-phyloseq/blob/master/global.R"
    click Core "https://github.com/microbialgenomics/shiny-phyloseq/blob/master/core/default-parameters.R"
    click RModules "https://github.com/microbialgenomics/shiny-phyloseq/blob/master/r-moduls/load-data.R"
    click Data "https://github.com/microbialgenomics/shiny-phyloseq/blob/master/data/DADA2_Rsession.RData"
    click Provenance "https://github.com/microbialgenomics/shiny-phyloseq/tree/master/provenance-staging/"
    click Deployment "https://github.com/microbialgenomics/shiny-phyloseq/tree/master/Dockerfile"

    %% Styles
    classDef frontend fill:#CEF,stroke:#333,stroke-width:2px;
    classDef backend fill:#CFC,stroke:#333,stroke-width:2px;
    classDef data fill:#FCC,stroke:#333,stroke-width:2px;
    classDef deploy fill:#FCF,stroke:#333,stroke-width:2px;
```
