# open-ent-ng/nextcloud architecture

> Architecture diagram of the GitHub repository open-ent-ng/nextcloud, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2025-05-15). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/open-ent-ng/nextcloud
- Repository: https://github.com/open-ent-ng/nextcloud

## Overview

##### Project Type and Purpose
- This is a full-stack microservice providing:
- An AngularJS sniplet plugin for ENT’s workspace module (under `angularjs/`).
- A React/TypeScript “Nextcloud Console” standalone frontend (under `frontend/`, an Nx monorepo).
- A Spring Boot backend service (`backend/`) that mediates between the frontends and an external Nextcloud server (via OCS and WebDAV), plus a PostgreSQL database for triggers.

##### File Structure
- Top-level directories:
- `.github`, `JenkinsFile`, `docker-compose.yml`, CI/CD configs.
- `angularjs/`: Legacy plugin code—SASS, HTML templates, TypeScript services/controllers/tests.
- `backend/`: Maven Spring Boot app—controllers, services, helpers, models, security, SQL scripts, test cases.
- `frontend/`: Modern React/TS/Nx app—components, containers, API services, global providers, styling, Vite config, env templates.
- Notice deployment artifacts:
- Docker Compose files in each folder, `build.sh` scripts, Kubernetes/Nextcloud configs in `backend/deployment/nextcloud`.

##### Pull Key Insights from the README
- Purpose: “Online document space management service for ENT synchronized on different devices using Nextcloud.”
- Two use cases:
a. Embedding Nextcloud-powered file management in the ENT workspace via sniplets.
b. Serving Nextcloud desktop client configuration (Console) protected by SSO/workflow.
- External dependencies: Nextcloud OCS API, WebDAV API, PostgreSQL DB, SAML plugin on Nextcloud server.

##### Main Components & Their Interactions
A. Frontends
1. ENT Workspace (hosted elsewhere)
- Loads AngularJS sniplet from `angularjs/` via `<sniplet template="...">`.
- Communicates over HTTP/JSON to the Backend’s REST controllers (`/nextcloud/...`).
2. Nextcloud Console (React app in `frontend/`)
- Served as a standalone SPA.
- Calls backend endpoint `/nextcloud/desktop/config` using client-id credentials for SSO.
B. Backend Service (Spring Boot in `backend/`)
- Exposes REST controllers: DocumentsController, NextcloudController, UserController, NextcloudDesktopController.
- Implements MVC, DI, ServiceFactory pattern.
- Connects to:
- External Nextcloud server over OCS API and WebDAV (configurable URLs).
- PostgreSQL database for persisting/trigging SAML user replication (SQL triggers in `sql/`).
C. External Systems
- Nextcloud Server (OCS + WebDAV)
- PostgreSQL DB (schema migrations + trigger functions)
- SAML/SSO provider plugin for Nextcloud
D. CI/CD & Deployment
- Jenkins pipeline & GitHub Actions (`.github/workflows/dev-check-repository.yml`).
- Docker Compose for local/dev in each module.
- `backend/deployment/nextcloud/conf.json.template` for production.

##### Architectural Patterns & Design Principles
- Modular separation: two distinct frontends sharing one backend service.
- Backend uses layered architecture: Controller → Service → Helper → External API.
- AngularJS plugin follows MVC in TypeScript + templates + SASS.
- React frontend follows component/container pattern + global context/provider + RTK Query (emptySplitApi).
- Use of configuration-as-code (`.env`, `${...}` placeholders) and feature flags (`enable-nextcloud`).
- Test coverage: unit tests in both frontends and backend.

##### Detail Is Key
- In the UI, differentiate between the AngularJS components (sniplets, templates, services) and React sub-modules (API service, stores, components).
- Feature flag flows (e.g., “enable-nextcloud” in ent-core.json).

## Diagram (Mermaid)

```mermaid
flowchart TB
    %% Frontend Layer
    subgraph "Frontends"
        direction TB
        AngularJS["AngularJS Sniplet Plugin"]:::frontend
        ReactConsole["React Nextcloud Console SPA"]:::frontend
    end

    %% Backend Layer
    subgraph "Backend Service (Spring Boot)"
        direction TB
        subgraph "Controllers"
            direction TB
            DocumentsController["DocumentsController"]:::backend
            NextcloudController["NextcloudController"]:::backend
            NextcloudDesktopController["NextcloudDesktopController"]:::backend
            UserController["UserController"]:::backend
        end
        subgraph "Service Layer"
            direction TB
            ServiceFactory["ServiceFactory"]:::backend
        end
        subgraph "Helpers"
            direction TB
            Helper["Helpers"]:::backend
        end
        subgraph "Domain Models"
            direction TB
            Models["Domain Models"]:::backend
        end
        subgraph "Security"
            direction TB
            Security["Security Filters & Annotations"]:::backend
        end
        subgraph "Configuration"
            direction TB
            NextcloudConfig["NextcloudConfig"]:::backend
            DeploymentConf["conf.json.template"]:::cicd
        end
        subgraph "SQL Scripts"
            direction TB
            SQLScripts["SQL Scripts (Triggers & Schema)"]:::external
        end
    end

    %% External Systems
    subgraph "External Systems"
        direction TB
        NextcloudServer["Nextcloud Server (OCS & WebDAV)"]:::external
        PostgresDB["PostgreSQL DB with Triggers"]:::external
    end

    %% CI/CD & Deployment
    subgraph "CI/CD & Deployment"
        direction TB
        GitHubActions["GitHub Actions"]:::cicd
        Jenkins["Jenkins Pipeline"]:::cicd
        RootCompose["Root Docker Compose"]:::cicd
        AngularBuild["angularjs/build.sh"]:::cicd
        BackendBuild["backend/build.sh"]:::cicd
        FrontendBuild["frontend/build.sh"]:::cicd
    end

    %% Connections
    AngularJS -->|"REST /nextcloud/... (HTTP/JSON)"| DocumentsController
    ReactConsole -->|"REST /nextcloud/desktop/config"| NextcloudDesktopController
    DocumentsController -->|"uses"| ServiceFactory
    NextcloudController -->|"uses"| ServiceFactory
    NextcloudDesktopController -->|"uses"| ServiceFactory
    UserController -->|"uses"| ServiceFactory
    ServiceFactory -->|"delegates to"| Helper
    Helper -->|"calls OCS/WebDAV"| NextcloudServer
    ServiceFactory -->|"manages"| Models
    DocumentsController -->|"checks auth"| Security
    NextcloudDesktopController -->|"retrieves SQL triggers"| SQLScripts
    DocumentsController -->|"reads/writes"| PostgresDB
    SQLScripts -->|"defines triggers on"| PostgresDB
    ServiceFactory -->|"loads config"| NextcloudConfig

    GitHubActions -->|"CI build/deploy"| AngularJS
    GitHubActions -->|"CI build/deploy"| ReactConsole
    Jenkins -->|"CD deploy"| AngularJS
    Jenkins -->|"CD deploy"| ReactConsole
    Jenkins -->|"CD deploy"| backend
    RootCompose -->|"local/dev compose"| AngularJS
    RootCompose -->|"local/dev compose"| ReactConsole
    RootCompose -->|"local/dev compose"| backend
    AngularBuild -->|build script| AngularJS
    BackendBuild -->|build script| backend
    FrontendBuild -->|build script| ReactConsole

    %% Click Events
    click AngularJS "https://github.com/open-ent-ng/nextcloud/tree/dev/angularjs/"
    click ReactConsole "https://github.com/open-ent-ng/nextcloud/blob/dev/frontend/src/main.tsx"
    click DocumentsController "https://github.com/open-ent-ng/nextcloud/blob/dev/backend/src/main/java/fr/openent/nextcloud/controller/DocumentsController.java"
    click NextcloudController "https://github.com/open-ent-ng/nextcloud/blob/dev/backend/src/main/java/fr/openent/nextcloud/controller/NextcloudController.java"
    click NextcloudDesktopController "https://github.com/open-ent-ng/nextcloud/blob/dev/backend/src/main/java/fr/openent/nextcloud/controller/NextcloudDesktopController.java"
    click UserController "https://github.com/open-ent-ng/nextcloud/blob/dev/backend/src/main/java/fr/openent/nextcloud/controller/UserController.java"
    click NextcloudConfig "https://github.com/open-ent-ng/nextcloud/blob/dev/backend/src/main/java/fr/openent/nextcloud/config/NextcloudConfig.java"
    click ServiceFactory "https://github.com/open-ent-ng/nextcloud/blob/dev/backend/src/main/java/fr/openent/nextcloud/service/ServiceFactory.java"
    click Helper "https://github.com/open-ent-ng/nextcloud/tree/dev/backend/src/main/java/fr/openent/nextcloud/helper/"
    click Models "https://github.com/open-ent-ng/nextcloud/tree/dev/backend/src/main/java/fr/openent/nextcloud/model/"
    click Security "https://github.com/open-ent-ng/nextcloud/tree/dev/backend/src/main/java/fr/openent/nextcloud/security/"
    click SQLScripts "https://github.com/open-ent-ng/nextcloud/blob/dev/backend/src/main/resources/sql/001-init-nextcloud.sql"
    click DeploymentConf "https://github.com/open-ent-ng/nextcloud/blob/dev/backend/deployment/nextcloud/conf.json.template"
    click GitHubActions "https://github.com/open-ent-ng/nextcloud/blob/dev/.github/workflows/dev-check-repository.yml"
    click Jenkins "https://github.com/open-ent-ng/nextcloud/tree/dev/JenkinsFile"
    click RootCompose "https://github.com/open-ent-ng/nextcloud/blob/dev/docker-compose.yml"
    click AngularBuild "https://github.com/open-ent-ng/nextcloud/blob/dev/angularjs/build.sh"
    click BackendBuild "https://github.com/open-ent-ng/nextcloud/blob/dev/backend/build.sh"
    click FrontendBuild "https://github.com/open-ent-ng/nextcloud/blob/dev/frontend/build.sh"

    %% Styles
    classDef frontend fill:#ddeeff,stroke:#333,stroke-width:1px
    classDef backend fill:#ddffdd,stroke:#333,stroke-width:1px
    classDef external fill:#eeeeee,stroke:#333,stroke-width:1px
    classDef cicd fill:#ffe0b2,stroke:#333,stroke-width:1px
```
