# joxebus/micronautgroovywebconsole architecture

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

- Interactive diagram: https://gitdiagram.com/joxebus/micronautgroovywebconsole
- Repository: https://github.com/joxebus/micronautgroovywebconsole

## Overview

##### Project Type & Purpose
- The project is a web application that provides an online Groovy console, allowing users to write and execute Groovy scripts.
- It uses the Micronaut framework for the backend and integrates a web UI with static resources (HTML, CSS, JavaScript) using Thymeleaf templates and Bootstrap for styling.
- File storage is abstracted to support different profiles: local storage or Dropbox, and there is special handling for script execution security.

##### Main Components
A. Client / Frontend:
- Web Browser as the client accessing the console.
- Static assets (views, JavaScript, CSS, images) served from the “public” and “views” directories.
- That the frontend uses CodeMirror (for code editing), Bootstrap, and Thymeleaf for rendering pages.

B. Application Layer (Micronaut Backend):
- The Main Application (Application.groovy) bootstraps the Micronaut server.
- Controllers:
- HomeController: Serves home pages.
- ImageController: Likely handles image requests.
- ScriptController: Main endpoint for script submission and execution.
- Services:
- ScriptExecutorService: Executes Groovy scripts safely.
- ScriptFileGeneratorService: Manages file generation for saved scripts.
- Common File Services: Abstract file operations with different implementations.
- FileServiceLocal: Manages local file system storage.
- FileServiceDropbox: Option for Dropbox-backed file storage.
- Security Components:
- ScriptSecurityManager and ScriptSecurityClassLoader: Enforce security when executing user scripts.
- Exception Handling:
- ScriptSecurityException and other exception flows.

C. Configuration & Environment Setup:
- Various configuration files (application.yml, application-dropbox.yml, application-cloud.yml) to denote the use of multiple environments.
- That different profiles (local, dropbox, heroku) choose which file storage implementation or other environment-specific settings to use.

##### Relationships & Interactions
- Service components to the File Abstraction Layer: show a decision point/strategy pattern where, based on the active profile, either the "Local" or the "Dropbox" file service is utilized.
- Security module’s interaction with the ScriptExecutorService or even directly as a ‘wrapper’ around script execution (using ScriptSecurityManager and ScriptSecurityClassLoader).
- Optionally, include a block for testing components (from the src/test directory) to indicate that unit/integration tests cover these interactions.

##### Architectural Patterns and Design Principles
- MVC Pattern: As indicated by the clear separation between Controllers (handling HTTP requests), Services (business logic), and Views (Thymeleaf templates).
- Strategy/Abstraction Pattern: For file storage where different implementations (Local vs. Dropbox) exist.
- Security by Design: Using dedicated security classes to ensure that executed scripts do not compromise the system.
- Dependency Injection and configuration management are inherent in the Micronaut framework and are reflected by the multiple configuration files.

##### Technical Stack & Implementations
- Backend: Micronaut framework, Groovy.
- Build System: Gradle (build.gradle, gradlew scripts).
- Frontend: Thymeleaf templates, CodeMirror (in src/main/resources/public), Bootstrap.
- External Integrations: Dropbox API (for file storage within the dropbox profile).

## Diagram (Mermaid)

```mermaid
flowchart TD
    %% Frontend Layer
    subgraph "Client/Frontend"
        Browser["Web Browser"]:::frontend
        PublicAssets["Public Assets"]:::frontend
        ViewTemplates["View Templates"]:::frontend
    end

    %% Backend Layer
    subgraph "Micronaut Backend"
        App["Main Application Bootstrap"]:::backend
        subgraph "Controllers"
            HomeCtrl["HomeController"]:::controller
            ImageCtrl["ImageController"]:::controller
            ScriptCtrl["ScriptController"]:::controller
        end
        subgraph "Services"
            ScriptExec["ScriptExecutorService"]:::service
            ScriptFileGen["ScriptFileGeneratorService"]:::service
        end
        subgraph "File Storage"
            FS_Local["FileServiceLocal"]:::storage
            FS_Dropbox["FileServiceDropbox"]:::storage
        end
        subgraph "Security"
            SecurityMngr["ScriptSecurityManager"]:::security
            SecurityCL["ScriptSecurityClassLoader"]:::security
        end
        SSE["ScriptSecurityException"]:::exception
    end

    %% Configuration
    Config["Configuration Files (application.yml, application-dropbox.yml, application-cloud.yml)"]:::config

    %% Frontend to Backend: HTTP Requests
    Browser -->|"HTTP_Request"| HomeCtrl
    Browser -->|"HTTP_Request"| ImageCtrl
    Browser -->|"HTTP_Request"| ScriptCtrl

    %% Controller to Service interactions
    ScriptCtrl -->|"ExecuteScript"| ScriptExec
    ScriptCtrl -->|"GenerateFile"| ScriptFileGen

    %% Service interactions with Security components
    ScriptExec -->|"SecurityCheck"| SecurityMngr
    ScriptExec -->|"LoadClasses"| SecurityCL
    SecurityMngr -->|"Throws"| SSE

    %% Service interactions with File Storage abstraction
    ScriptFileGen -->|"UseLocal"| FS_Local
    ScriptFileGen -->|"UseDropbox"| FS_Dropbox

    %% Configuration influences the Backend
    Config -->|"Configures"| App

    %% Click Events
    click PublicAssets "https://github.com/joxebus/micronautgroovywebconsole/tree/main/src/main/resources/public"
    click ViewTemplates "https://github.com/joxebus/micronautgroovywebconsole/tree/main/src/main/resources/views"
    click App "https://github.com/joxebus/micronautgroovywebconsole/blob/main/src/main/groovy/io/github/joxebus/groovywebconsole/Application.groovy"
    click HomeCtrl "https://github.com/joxebus/micronautgroovywebconsole/blob/main/src/main/groovy/io/github/joxebus/groovywebconsole/controller/HomeController.groovy"
    click ImageCtrl "https://github.com/joxebus/micronautgroovywebconsole/blob/main/src/main/groovy/io/github/joxebus/groovywebconsole/controller/ImageController.groovy"
    click ScriptCtrl "https://github.com/joxebus/micronautgroovywebconsole/blob/main/src/main/groovy/io/github/joxebus/groovywebconsole/controller/ScriptController.groovy"
    click ScriptExec "https://github.com/joxebus/micronautgroovywebconsole/blob/main/src/main/groovy/io/github/joxebus/groovywebconsole/service/ScriptExecutorService.groovy"
    click ScriptFileGen "https://github.com/joxebus/micronautgroovywebconsole/blob/main/src/main/groovy/io/github/joxebus/groovywebconsole/service/ScriptFileGeneratorService.groovy"
    click FS_Local "https://github.com/joxebus/micronautgroovywebconsole/blob/main/src/main/groovy/io/github/joxebus/groovywebconsole/service/common/impl/FileServiceLocal.groovy"
    click FS_Dropbox "https://github.com/joxebus/micronautgroovywebconsole/blob/main/src/main/groovy/io/github/joxebus/groovywebconsole/service/common/impl/FileServiceDropbox.groovy"
    click SecurityMngr "https://github.com/joxebus/micronautgroovywebconsole/blob/main/src/main/groovy/io/github/joxebus/groovywebconsole/security/ScriptSecurityManager.groovy"
    click SecurityCL "https://github.com/joxebus/micronautgroovywebconsole/blob/main/src/main/groovy/io/github/joxebus/groovywebconsole/security/ScriptSecurityClassLoader.groovy"
    click SSE "https://github.com/joxebus/micronautgroovywebconsole/blob/main/src/main/groovy/io/github/joxebus/groovywebconsole/exception/ScriptSecurityException.groovy"
    click Config "https://github.com/joxebus/micronautgroovywebconsole/blob/main/src/main/resources/application.yml"

    %% Styles
    classDef frontend fill:#87CEEB,stroke:#333,stroke-width:2px;
    classDef backend fill:#E0E0E0,stroke:#333,stroke-width:2px;
    classDef controller fill:#FFDAB9,stroke:#333,stroke-width:2px;
    classDef service fill:#98FB98,stroke:#333,stroke-width:2px;
    classDef storage fill:#DDA0DD,stroke:#333,stroke-width:2px;
    classDef security fill:#FFA07A,stroke:#333,stroke-width:2px;
    classDef config fill:#F0E68C,stroke:#333,stroke-width:2px;
    classDef exception fill:#FF6347,stroke:#333,stroke-width:2px;
```
