# smi/smiservices architecture

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

- Interactive diagram: https://gitdiagram.com/smi/smiservices
- Repository: https://github.com/smi/smiservices

## Overview

##### Main Components
- SmiServices Suite – Representing the core microservices that handle tasks such as:
– DICOM processing applications (DicomDirectoryProcessor, DicomLoader, DynamicRulesTester, ExtractImages, Setup, TriggerUpdates)
– A wide set of microservices under src/SmiServices/Microservices:
– CohortExtractor, CohortPackager, DicomAnonymiser, DicomRelationalMapper, DicomReprocessor, DicomTagReader, FileCopier, IdentifierMapper, IsIdentifiable, MongoDBPopulator, UpdateValues, etc.
- CTPAnonymiser – A Java service dedicated to de-identification, with its own build scripts and library dependencies (note the use of Maven and JDK).
- Databases – Include components for MongoDB and SQL (or relational databases) as the target storage for extracted metadata.
- Supporting Utilities and Configurations – Indicate that various configuration files (in data/microserviceConfigs, data/rabbitmqConfigs, and util/docker-compose setups) offer deployment and runtime settings.
- Build and Deployment Scripts – Highlight the binary folders (bin/smi, bin/ctp) and the build infrastructure (e.g., .NET build scripts, Maven scripts, pre-commit hooks, and docker-compose files) that underpin development and deployment.

##### Relationships and Interactions
- Outbound/inbound communication lines between the SmiServices microservices and RabbitMQ. For example, some microservices are "consumers" (like queue consumers handling extraction requests), while others are "producers" (sending messages or control commands).
- How SmiServices integrate with databases; many microservices have components that either load data into MongoDB/SQL or extract data from them.
- Configuration and deployment layer (docker-compose, configuration files in data and utils) with the infrastructure components to show that the environment is supported by external scripts and settings.

##### Architectural Patterns and Design Principles
- The architecture leverages a microservices pattern with clearly defined service boundaries (each microservice is in its own module under “src/SmiServices/Microservices”).
- Communication is event-driven via RabbitMQ, which suggests asynchronous processing and decoupling.
- There is a separation of concerns between metadata extraction, de-identification processing, and data persistence.
- Shared libraries (e.g., common message definitions and utility code under src/common and src/SmiServices/Common) support consistency and reduce duplication across services.

## Diagram (Mermaid)

```mermaid
flowchart TD
    %% Deployment & Configurations Layer
    subgraph "Deployment & Configurations"
        Configs["Utilities & Configurations"]:::config
        BuildSMI["SMI Build Tools"]:::build
        BuildCTP["CTP Build Tools"]:::build
    end

    %% SmiServices Suite Layer
    subgraph "SmiServices Suite"
        subgraph "Applications"
            DicomDir["DicomDirectoryProcessor"]:::csharp
            DicomLoader["DicomLoader"]:::csharp
            DynamicRules["DynamicRulesTester"]:::csharp
            ExtractImages["ExtractImages"]:::csharp
            Setup["Setup"]:::csharp
            TriggerUpdates["TriggerUpdates"]:::csharp
        end
        subgraph "Microservices"
            CohortExtractor["CohortExtractor"]:::csharp
            CohortPackager["CohortPackager"]:::csharp
            DicomAnonymiserService["DicomAnonymiser"]:::csharp
            DicomRelationalMapper["DicomRelationalMapper"]:::csharp
            DicomReprocessor["DicomReprocessor"]:::csharp
            DicomTagReader["DicomTagReader"]:::csharp
            FileCopier["FileCopier"]:::csharp
            IdentifierMapper["IdentifierMapper"]:::csharp
            IsIdentifiable["IsIdentifiable"]:::csharp
            MongoDBPopulator["MongoDBPopulator"]:::csharp
            UpdateValues["UpdateValues"]:::csharp
        end
    end

    %% CTPAnonymiser Service Layer
    CTP["CTPAnonymiser"]:::java

    %% Messaging Layer
    RabbitMQ["RabbitMQ Message Broker"]:::messaging

    %% Database Layer
    subgraph "Database Layer"
        MongoDB["MongoDB"]:::database
        SQLDB["SQL Database"]:::database
    end

    %% Connections from Deployment & Configurations to Services
    Configs -->|"config_support"| DicomLoader
    Configs -->|"config_support"| CTP
    BuildSMI -->|"build_trigger"| DicomLoader
    BuildCTP -->|"build_trigger"| CTP

    %% Connections from SmiServices Suite and CTP to Messaging Layer
    DicomDir -->|"publish"| RabbitMQ
    CohortExtractor -->|"consume_publish"| RabbitMQ
    CTP -->|"consume_publish"| RabbitMQ

    %% Direct invocation between SmiServices and CTPAnonymiser service
    DicomAnonymiserService -->|"invoke_de-identification"| CTP
    CTP -->|"return_results"| DicomAnonymiserService

    %% Connections from SmiServices Microservices to Databases
    MongoDBPopulator -->|"data_IO"| MongoDB
    DicomRelationalMapper -->|"data_IO"| SQLDB

    %% Click Events
    click DicomDir "https://github.com/smi/smiservices/tree/main/src/SmiServices/Applications"
    click CohortExtractor "https://github.com/smi/smiservices/tree/main/src/SmiServices/Microservices"
    click CTP "https://github.com/smi/smiservices/blob/main/src/microservices/com.smi.microservices.ctpanonymiser"
    click RabbitMQ "https://github.com/smi/smiservices/tree/main/src/SmiServices/Common/Messaging"
    click MongoDB "https://github.com/smi/smiservices/tree/main/src/SmiServices/Common/MongoDB"
    click SQLDB "https://github.com/smi/smiservices/blob/main/docs/schema.sql"
    click Configs "https://github.com/smi/smiservices/tree/main/data/microserviceConfigs"
    click BuildSMI "https://github.com/smi/smiservices/tree/main/bin/smi"
    click BuildCTP "https://github.com/smi/smiservices/tree/main/bin/ctp"

    %% Styles
    classDef csharp fill:#D5E8D4,stroke:#82B366,stroke-width:2px;
    classDef java fill:#E1D5E7,stroke:#9673A6,stroke-width:2px;
    classDef messaging fill:#FFE6CC,stroke:#FF9900,stroke-width:2px;
    classDef database fill:#CCEDFF,stroke:#3399FF,stroke-width:2px;
    classDef config fill:#FFF2CC,stroke:#D6B656,stroke-width:2px;
    classDef build fill:#F8CECC,stroke:#B85450,stroke-width:2px;
```
