# complat/chemotion_eln architecture

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

## Overview

##### Project Type and Purpose
- This is a complex, full-stack Rails application that provides an ELN for chemists. Its purpose is to manage chemical experiments, data collection, research plans, reaction/spectra visualization, and file-based collaboration. The README confirms that this is the “Chemotion” ELN, and the file structure reveals that it supports rich functionalities (e.g., chemical reaction processing, integrations with external services such as RDKit, PubChem, and scifinder).

##### File Structure – Major System Components
- Backend (Rails Core)
– Under “app/” you find standard Rails folders such as controllers, models, views, jobs, mailers, policies, and use cases.
– The controllers include RESTful endpoints plus specialized controllers like Api, GraphQL (app/graphql), OAuth integrations, and custom exception handling.
– Models represent the domain (e.g., chemical, reactions, research_plans, wellplates) with rich associations. The presence of concerns indicates use of modular design for shared functionality.
– Service objects (in app/services and app/usecases) encapsulate complex business logic (for example, processing key chemical computations, handling versioning, and integration with external formats).

- API and GraphQL Layers
– The “app/api” folder details a layered API structure with separate endpoints under chemotion and entities. This design supports a REST/JSON API and probably connects with the GraphQL schema (in app/graphql) for flexible data retrieval.
– This layering allows external and internal consumers (e.g., the JavaScript frontend) to interact with the system.

- Frontend and JavaScript Assets
– The project contains an extensive “app/javascript” directory with packs managed by Webpack (and Shakapacker). All your business-specific React components, state stores (mobx and alt), fetchers, models, and utility modules are here.
– This clear separation of client-side code (with folders for components, endpoints, and stores) reinforces the MVC separation with frontend-backend interactions being well defined.

- Background Processing and Job Handling
– The “app/jobs” directory is filled with many asynchronous and scheduled jobs. These handle file transfers (from local or SFTP collections), data exports/imports, notifications, and analysis tasks.
– The existence of configuration files (e.g., delayed_job config, scheduling in config/schedule.rb) indicates a robust background processing and cron job architecture.

- Integration and External Services
- In “lib/chemotion” and related lib folders you see custom libraries for chemical calculations, export (including Excel, SDF, DOCX, PDF generation), and integrations with toolkits such as Open Babel, RDKit, and others.
- There are separate modules for OAuth2 and OmniAuth strategies (for example, in lib/omniauth/strategies/chemotion_orcid.rb), indicating a layered integration with external identity providers.
- Support for external data exchange is also evident in lib/data_cite, lib/import, and lib/export directories.

- Database, Migrations, and Versioning
– The “db/” folder contains not just migrations and schema definitions, but also stored functions (SQL) and triggers, reflecting an advanced data management design.
– Versioning is handled in “app/services/versioning” and there is heavy emphasis on data integrity and audit trails (for example, through logidze integrations).
– The migration history shows careful attention to evolving the database schema to support the domain’s complexity.

- Containerization and Deployment Artifacts
– There are Dockerfiles, docker-compose configurations (.devcontainer, docker-compose.*.yml) and CI/CD pipelines (GitHub/workflows, .gitlab-ci.yml). These files support a containerized, automated deployment process.
– This ensures consistency, reproducibility, and clean development environments.

##### Architectural Patterns and Design Principles to Emphasize
- MVC and Layered Architecture: Clearly demarcate the presentation layer (views and client-side React components), the controller layer (graphQL and RESTful controllers), the business/service layer (use cases, service objects), and the persistence layer (ActiveRecord models backed by complex migrations and stored procedures).
- Micro-Components and Modularization: Highlight the role of “concerns”, “modules”, and helper libraries in keeping the code DRY and modular. Show that reusability is a primary goal.
- Asynchronous Processing: Illustrate how background jobs (distributed via delayed_job and scheduled tasks) interconnect with synchronous user actions.
- API Gateway: Represent the API endpoints (both REST and GraphQL) as boundaries for both internal and external communication.
- External Services & Integrations: Call out connections to chemical informatics libraries (RDKit, Open Babel), external authentication (OAuth2, OmniAuth), data exchange systems (data_cite), and SFTP or mail-based data collection.
- Containerization and CI/CD: Include a component for the development environment and deployment orchestration which leverages Docker, as well as the automated workflow pipelines.

- Essentials: each controller, service, model grouping, job processing mechanism, and integration point.
- Both static architecture (directory organization, component boundaries) and dynamic interactions (request flows, asynchronous communications, external API callbacks).

## Diagram (Mermaid)

```mermaid
graph TD
    %% Frontend Layer
    subgraph "Frontend - React/JS"
        FE["React Components"]:::frontend
    end

    %% API and GraphQL Layer
    subgraph "API/GraphQL Layer"
        API["API Endpoints (REST)"]:::api
        GQL["GraphQL Schema"]:::api
    end

    %% Backend (Rails Core)
    subgraph "Backend - Rails Core"
        CTLR["Controllers"]:::backend
        VWS["Views"]:::backend
        SERV["Service Objects"]:::backend
        MDS["Models (Domain Entities)"]:::backend
    end

    %% Asynchronous Processing
    subgraph "Asynchronous Processing"
        BJ["Background Jobs"]:::jobs
    end

    %% External Integrations and Libraries
    subgraph "External Integrations"
        CHEM["Chemical Computation & Integration Services"]:::integration
        EDX["External Data Exchange & Format Conversion"]:::integration
    end

    %% Database and Versioning
    subgraph "Database & Versioning"
        DB["Database Migrations & Schema"]:::database
        VERT["Versioning Services"]:::database
    end

    %% Deployment and Containerization
    subgraph "Deployment"
        DOCK["Docker & Container Configuration"]:::deployment
        CI["CI/CD Pipeline Configurations"]:::deployment
    end

    %% Relationships
    FE -->|"calls"| API
    FE -->|"calls"| GQL

    API -->|"forwards"| CTLR
    GQL -->|"forwards"| CTLR

    CTLR -->|"delegates"| SERV
    CTLR -->|"renders"| VWS

    SERV -->|"handles business logic for"| MDS
    SERV -->|"integrates with"| CHEM
    SERV -->|"handles conversions via"| EDX

    MDS -->|"persists data to"| DB
    MDS -->|"triggers"| BJ

    DB -->|"tracked by"| VERT

    %% Deployment interactions (Container orchestration for main services)
    DOCK -->|"deploys"| FE
    DOCK -->|"deploys"| API
    CI -->|"automates"| FE
    CI -->|"automates"| API

    %% Styling
    classDef backend fill:#AED6F1,stroke:#1F618D,stroke-width:2px;
    classDef api fill:#A9DFBF,stroke:#196F3D,stroke-width:2px;
    classDef frontend fill:#F9E79F,stroke:#B7950B,stroke-width:2px;
    classDef jobs fill:#FAD7A0,stroke:#D35400,stroke-width:2px;
    classDef integration fill:#F5B7B1,stroke:#922B21,stroke-width:2px;
    classDef database fill:#D5F5E3,stroke:#27AE60,stroke-width:2px;
    classDef deployment fill:#EBDEF0,stroke:#8E44AD,stroke-width:2px;

    %% Click Events
    click CTLR "https://github.com/complat/chemotion_eln/tree/main/app/controllers"
    click MDS "https://github.com/complat/chemotion_eln/tree/main/app/models"
    click VWS "https://github.com/complat/chemotion_eln/tree/main/app/views"
    click SERV "https://github.com/complat/chemotion_eln/tree/main/app/services"
    click SERV "https://github.com/complat/chemotion_eln/tree/main/app/usecases"
    click API "https://github.com/complat/chemotion_eln/tree/main/app/api"
    click GQL "https://github.com/complat/chemotion_eln/tree/main/app/graphql"
    click FE "https://github.com/complat/chemotion_eln/tree/main/app/javascript"
    click BJ "https://github.com/complat/chemotion_eln/tree/main/app/jobs"
    click CHEM "https://github.com/complat/chemotion_eln/tree/main/lib/chemotion"
    click EDX "https://github.com/complat/chemotion_eln/tree/main/lib/export"
    click EDX "https://github.com/complat/chemotion_eln/tree/main/lib/import"
    click EDX "https://github.com/complat/chemotion_eln/tree/main/lib/data_cite"
    click DB "https://github.com/complat/chemotion_eln/tree/main/db/migrate"
    click DB "https://github.com/complat/chemotion_eln/blob/main/db/schema.rb"
    click VERT "https://github.com/complat/chemotion_eln/tree/main/app/services/versioning"
    click DOCK "https://github.com/complat/chemotion_eln/blob/main/Dockerfile.chemotion-dev"
    click DOCK "https://github.com/complat/chemotion_eln/blob/main/.devcontainer"
    click DOCK "https://github.com/complat/chemotion_eln/blob/main/docker-compose.dev.yml"
    click CI "https://github.com/complat/chemotion_eln/tree/main/.github/workflows"
    click CI "https://github.com/complat/chemotion_eln/blob/main/.gitlab-ci.yml"
```
