# more-platform/more-studymanager-backend architecture

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

- Interactive diagram: https://gitdiagram.com/more-platform/more-studymanager-backend
- Repository: https://github.com/more-platform/more-studymanager-backend

## Overview

##### Main Components to Identify
- API / Controller Layer: Represent all the controllers (e.g., LoginController, various V1 API controllers) in the “studymanager” module. These endpoints are what front-end clients or other services will interact with.
- Service Layer: Include the diverse services (ActionService, ParticipantService, StudyService, SchedulingService, etc.) that contain business logic.
- Repository / Persistence Layer: Note the repositories handling data access, with support from database migration scripts located in the resources folder.
- Domain / Core Module: Highlight the “studymanager-core” module. This module encapsulates the core domain entities (such as Study, Participant, Action, Observation, Notification, etc.) and factories/SDK components.
- Intervention & Observation Modules: Separate out the “studymanager-intervention” and “studymanager-observation” modules, which extend the core with domain-specific functionalities for interventions (for example, push notifications and scheduled triggers) and observations (supporting various observation types, including those relating to LimeSurvey or mobile data).
- External Integrations: Identify external systems that this backend interfaces with:
– OAuth2 Authorization Server / Keycloak (as indicated in both the README and configuration classes)
– Elastic Search (configured via ElasticConfiguration and related service classes)
– Firebase Messaging (as seen in FirebaseConfiguration and corresponding service)
– Possibly other external data sources/APIs exposed through the SDK.
- Development & Deployment Services: Include Docker Compose as a container orchestration unit (with services such as the database, auth server, etc.) signified by the docker-compose.yaml file.

##### Relationships and Interactions
- Scheduled tasks (using cron or interval schedules) should be shown triggering jobs (e.g., trigger observations or interventions) within the system.

##### Architectural Patterns and Technologies
- The application follows a layered architecture (Controller → Service → Repository/Domain Model) with a clear separation of concerns.
- It is built using Spring (or a similar dependency injection framework) evidenced by configuration classes for security and web components.
- The Maven multi-module structure reinforces separation of concerns; each module (core, intervention, observation) encapsulates specific areas of responsibility.
- Integration with external systems via dedicated configuration and SDK classes is a key design principle.

## Diagram (Mermaid)

```mermaid
flowchart TD
    %% External Clients
    client["API Clients"]:::external

    %% API Layer
    subgraph "API Layer"
        C["StudyManager API Controllers"]:::api
    end

    %% Service Layer
    subgraph "Service Layer"
        S["Service Layer"]:::service
    end

    %% Persistence Layer
    subgraph "Persistence Layer"
        R1["Repository"]:::persistence
        R2["DB Migration Scripts"]:::persistence
        DB["Database"]:::persistence
    end

    %% Domain Modules
    subgraph "Domain Modules"
        DC["StudyManager Core"]:::domain
        I["Intervention Module"]:::domain
        O["Observation Module"]:::domain
    end

    %% External Integrations
    subgraph "External Integrations"
        EK["OAuth2/Keycloak Integration"]:::external
        EE["Elastic Search Integration"]:::external
        EF["Firebase Messaging Integration"]:::external
    end

    %% Scheduling & Jobs
    subgraph "Scheduling"
        SJ["Trigger Jobs"]:::scheduling
        SS["Schedule Config"]:::scheduling
    end

    %% Deployment / Orchestration
    subgraph "Deployment / Orchestration"
        D["Docker Compose"]:::deployment
    end

    %% Connections
    client -->|"sendsRequest"| C
    C -->|"calls"| S
    S -->|"accesses"| R1
    R1 -->|"reads/writes"| DB
    S -->|"uses"| R2
    S -->|"invokes"| I
    S -->|"invokes"| O
    S -->|"integrates"| EK
    S -->|"integrates"| EE
    S -->|"integrates"| EF
    S -->|"uses"| DC
    I -->|"depends_on"| DC
    O -->|"depends_on"| DC
    SJ -->|"triggers"| S
    SS -->|"configures"| S
    D -->|"manages"| DB
    D -->|"orchestrates"| EK

    %% Click Events
    click C "https://github.com/more-platform/more-studymanager-backend/tree/main/studymanager/src/main/java/io/redlink/more/studymanager/controller"
    click S "https://github.com/more-platform/more-studymanager-backend/tree/main/studymanager/src/main/java/io/redlink/more/studymanager/service"
    click R1 "https://github.com/more-platform/more-studymanager-backend/tree/main/studymanager/src/main/java/io/redlink/more/studymanager/repository"
    click R2 "https://github.com/more-platform/more-studymanager-backend/tree/main/studymanager/src/main/resources/db/migration"
    click DC "https://github.com/more-platform/more-studymanager-backend/tree/main/studymanager-core/src/main/java/io/redlink/more/studymanager/core"
    click I "https://github.com/more-platform/more-studymanager-backend/tree/main/studymanager-intervention"
    click O "https://github.com/more-platform/more-studymanager-backend/tree/main/studymanager-observation/src/main/java/io/redlink/more/studymanager/component/observation"
    click EK "https://github.com/more-platform/more-studymanager-backend/tree/main/studymanager/src/main/java/io/redlink/more/studymanager/service/OAuth2AuthenticationService"
    click EE "https://github.com/more-platform/more-studymanager-backend/tree/main/studymanager/src/main/java/io/redlink/more/studymanager/configuration/ElasticConfiguration"
    click EF "https://github.com/more-platform/more-studymanager-backend/tree/main/studymanager/src/main/java/io/redlink/more/studymanager/configuration/FirebaseConfiguration"
    click SJ "https://github.com/more-platform/more-studymanager-backend/tree/main/studymanager/src/main/java/io/redlink/more/studymanager/scheduling"
    click SS "https://github.com/more-platform/more-studymanager-backend/tree/main/studymanager-core/src/main/java/io/redlink/more/studymanager/core/sdk/schedule"
    click D "https://github.com/more-platform/more-studymanager-backend/blob/main/docker-compose.yaml"

    %% Styles
    classDef api fill:#cce5ff,stroke:#004085,stroke-width:2px;
    classDef service fill:#d4edda,stroke:#155724,stroke-width:2px;
    classDef persistence fill:#fff3cd,stroke:#856404,stroke-width:2px;
    classDef domain fill:#f8d7da,stroke:#721c24,stroke-width:2px;
    classDef external fill:#e2e3e5,stroke:#6c757d,stroke-width:2px;
    classDef scheduling fill:#d1ecf1,stroke:#0c5460,stroke-width:2px;
    classDef deployment fill:#e9ecef,stroke:#636363,stroke-width:2px;
```
