# aces/loris architecture

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

- Interactive diagram: https://gitdiagram.com/aces/loris
- Repository: https://github.com/aces/loris

## Overview

1. LORIS is a self-hosted PHP web platform for longitudinal research data management, centered on a MySQL database and a large module/plugin architecture. It serves clinical, behavioural, imaging, genetic, and electrophysiology workflows from the same codebase.

2. The runtime entry points live under `htdocs/`. Requests begin in front-controller PHP files such as `index.php`, `router.php`, `survey.php`, and module-specific AJAX endpoints. Static assets, legacy JS/CSS, and some direct-download handlers are also served from this web root.

3. The core application framework is in `src/`. This layer provides the common request/response stack: routing, middleware, HTTP abstractions, authentication, MFA, CSP/compression/ETag handling, language selection, page decoration, and error handling. It is the main boundary between the web server and feature modules.

4. Application features are primarily packaged as modules under `modules/`. Each module has its own PHP, JSX/TSX front end, templates, localization files, help docs, tests, and sometimes AJAX handlers or REST endpoints. This is a modular monolith rather than a microservice system.

5. The frontend is mixed-generation: older pages use Smarty templates and jQuery-era assets, while newer module UIs use React/TypeScript in `jsx/`. Shared UI primitives live in the repo root `jsx/` and API/client helpers in `jslib/`. Webpack/Babel/TS tooling builds these assets.

6. Data access is database-first. The application model is encoded in the `SQL/` directory, with release upgrade scripts, cleanup patches, and archived migrations, plus `raisinbread/RB_files` which mirrors the schema as table-definition SQL. Most module behavior ultimately reads/writes these relational tables.

7. Core domain boundaries are visible in the modules:
   - study structure and identity: `candidate_*`, `configuration`, `create_timepoint`, `timepoint_list`, `project/site/cohort` logic
   - data capture: `instruments`, `instrument_builder`, `instrument_manager`, `media`, `publication`, `document_repository`
   - quality and review: `imaging_qc`, `imaging_browser`, `mri_violations`, `conflict_resolver`, `issue_tracker`
   - specialized domains: `electrophysiology_*`, `genomic_browser`, `biobank`, `data_release`, `dqt`, `redcap`, `oidc`
   - admin/security: `login`, `user_accounts`, `my_preferences`, `module_manager`, `policy_tracker`

8. The API surface is split into dedicated back-end packages such as `modules/api` and `modules/dataquery`, plus shared HTTP/query infrastructure in `src/Http` and `src/Data/Query`. These modules expose structured endpoints and schemas for programmatic access and internal UI data fetching.

9. File handling is a major architectural concern. Imaging, media, electrophysiology, publication uploads, and data-release files are uploaded through module-specific handlers, then tracked in database tables and sometimes transformed into downstream formats or indexed metadata. Several utility classes in `php/libraries/` and `src/Data/Models` support these flows.

10. Authentication and authorization are cross-cutting and data-driven. Permissions, menu visibility, site/project scoping, MFA, and OIDC are enforced through core middleware plus database-backed permission tables. Modules typically declare their own permissions and menu items, which the core menu/router layer resolves at runtime.

11. Background and operational workflows live in `tools/` and `Procfile`/Docker assets. This includes importers, exporters, data-integrity repair scripts, SQL generation, notification and digest jobs, module management, and deployment helpers. These scripts are part of the system architecture because many data flows are batch-oriented rather than interactive.

12. Testing and environment definition are first-class. The repo includes PHPUnit/unit/integration tests under `test/` and per-module test plans, Docker test images, shell runners, and CI workflows in `.github/workflows`. Documentation under `docs/` and `readthedocs/` describes installation, schema conventions, module development, and operational setup.

13. Overall, the architectural diagram should show: browser/UI clients hitting PHP entry points; core `src/` middleware/router/auth layers; feature modules with their own UI and endpoint logic; shared MySQL schema/migrations; and supporting background scripts, tests, and documentation around the edges.

Main entry points: [`SQL`](https://github.com/aces/loris/tree/main/SQL) (Schema), [`modules`](https://github.com/aces/loris/tree/main/modules) (Modules), [`src/Data`](https://github.com/aces/loris/tree/main/src/Data) (Data layer), [`src`](https://github.com/aces/loris/tree/main/src) (Core)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_clients["Clients & entry"]
  node_htdocs_entry["htdocs<br/>web entry"]
end

subgraph group_core["Core framework"]
  node_core_root["Core<br/>framework"]
  node_core_http["HTTP stack<br/>request/response"]
  node_core_router["Routing<br/>router"]
  node_core_middleware["Middleware<br/>cross-cutting"]
  node_core_data["Data layer<br/>domain/data"]
  node_core_security["Security<br/>otp/auth"]
  node_ui_shared["Shared UI<br/>react/ui"]
  node_client_lib["Client libs<br/>ts/http"]
end

subgraph group_features["Feature modules"]
  node_modules_core["Modules<br/>modular monolith"]
  node_study_setup["Study setup<br/>study identity"]
  node_capture["Data capture"]
  node_imaging["Imaging"]
  node_electro["Electrophysiology<br/>physio suite"]
  node_genomics["Genomics<br/>genomic browser"]
  node_admin_sec["Admin & access<br/>admin/security"]
  node_query_api["Query & API<br/>api/query"]
  node_quality["Quality & review"]
end

subgraph group_dataops["Data & operations"]
  node_schema[("Schema<br/>mysql/sql")]
  node_raisinbread[("Schema mirror<br/>sql mirror")]
  node_batch_tools["Batch tools<br/>ops/scripts"]
  node_tests["Tests<br/>test suite"]
  node_docs["Docs<br/>documentation"]
end

node_htdocs_entry -->|"boots"| node_core_root
node_core_root -->|"routes"| node_core_router
node_core_root -->|"wraps"| node_core_middleware
node_core_router -->|"loads modules"| node_modules_core
node_core_middleware -->|"wraps"| node_core_http
node_core_router -->|"produces"| node_core_http
node_modules_core -->|"renders"| node_ui_shared
node_modules_core -->|"calls"| node_client_lib
node_modules_core -->|"reads/writes"| node_core_data
node_core_data -->|"maps to"| node_schema
node_schema -->|"mirrors"| node_raisinbread
node_study_setup -->|"defines"| node_schema
node_capture -->|"stores"| node_schema
node_imaging -->|"stores"| node_schema
node_electro -->|"stores"| node_schema
node_genomics -->|"stores"| node_schema
node_admin_sec -->|"enforced by"| node_core_middleware
node_quality -->|"queries"| node_core_data
node_query_api -->|"serves"| node_core_http
node_query_api -->|"executes"| node_core_data
node_batch_tools -->|"maintains"| node_schema
node_batch_tools -->|"imports/exports"| node_core_data
node_tests -.->|"covers"| node_modules_core
node_tests -.->|"covers"| node_core_root
node_docs -.->|"describes"| node_modules_core
node_docs -.->|"documents"| node_schema
node_docs -.->|"documents"| node_batch_tools

click node_htdocs_entry "https://github.com/aces/loris/tree/main/htdocs"
click node_core_root "https://github.com/aces/loris/tree/main/src"
click node_core_http "https://github.com/aces/loris/tree/main/src/Http"
click node_core_router "https://github.com/aces/loris/tree/main/src/Router"
click node_core_middleware "https://github.com/aces/loris/tree/main/src/Middleware"
click node_core_data "https://github.com/aces/loris/tree/main/src/Data"
click node_core_security "https://github.com/aces/loris/tree/main/src/Security"
click node_ui_shared "https://github.com/aces/loris/tree/main/jsx"
click node_client_lib "https://github.com/aces/loris/tree/main/jslib"
click node_modules_core "https://github.com/aces/loris/tree/main/modules"
click node_study_setup "https://github.com/aces/loris/tree/main/modules/configuration"
click node_capture "https://github.com/aces/loris/tree/main/modules/instruments"
click node_imaging "https://github.com/aces/loris/tree/main/modules/imaging_uploader"
click node_electro "https://github.com/aces/loris/tree/main/modules/electrophysiology_uploader"
click node_genomics "https://github.com/aces/loris/tree/main/modules/genomic_browser"
click node_admin_sec "https://github.com/aces/loris/tree/main/modules/login"
click node_query_api "https://github.com/aces/loris/tree/main/modules/api"
click node_quality "https://github.com/aces/loris/tree/main/modules/conflict_resolver"
click node_schema "https://github.com/aces/loris/tree/main/SQL"
click node_raisinbread "https://github.com/aces/loris/tree/main/raisinbread/RB_files"
click node_batch_tools "https://github.com/aces/loris/tree/main/tools"
click node_tests "https://github.com/aces/loris/tree/main/test"
click node_docs "https://github.com/aces/loris/tree/main/docs"

classDef toneNeutral fill:#f8fafc,stroke:#334155,stroke-width:1.5px,color:#0f172a
classDef toneBlue fill:#dbeafe,stroke:#2563eb,stroke-width:1.5px,color:#172554
classDef toneAmber fill:#fef3c7,stroke:#d97706,stroke-width:1.5px,color:#78350f
classDef toneMint fill:#dcfce7,stroke:#16a34a,stroke-width:1.5px,color:#14532d
classDef toneRose fill:#ffe4e6,stroke:#e11d48,stroke-width:1.5px,color:#881337
classDef toneIndigo fill:#e0e7ff,stroke:#4f46e5,stroke-width:1.5px,color:#312e81
classDef toneTeal fill:#ccfbf1,stroke:#0f766e,stroke-width:1.5px,color:#134e4a
class node_htdocs_entry toneBlue
class node_core_root,node_core_http,node_core_router,node_core_middleware,node_core_data,node_core_security,node_ui_shared,node_client_lib toneAmber
class node_modules_core,node_study_setup,node_capture,node_imaging,node_electro,node_genomics,node_admin_sec,node_query_api,node_quality toneMint
class node_schema,node_raisinbread,node_batch_tools,node_tests,node_docs toneRose
```

## Components

### Clients & entry

Browser-facing entry points and web-root assets.

- [htdocs](https://github.com/aces/loris/tree/main/htdocs): web entry · Front controllers, static assets, and direct handlers served from the document root. · `htdocs`

### Core framework

Shared request handling, routing, security, and data primitives.

- [Core](https://github.com/aces/loris/tree/main/src): framework · Shared application framework that connects web entrypoints to modules and data. · `src`
- [HTTP stack](https://github.com/aces/loris/tree/main/src/Http): request/response · HTTP abstractions, response types, endpoints, streams, and file passthrough. · `src/Http`
- [Routing](https://github.com/aces/loris/tree/main/src/Router): router · Base routers and module routing/auth dispatch. · `src/Router`
- [Middleware](https://github.com/aces/loris/tree/main/src/Middleware): cross-cutting · Auth, MFA, CSP, compression, ETag, language, page decoration, and error handling. · `src/Middleware`
- [Data layer](https://github.com/aces/loris/tree/main/src/Data): domain/data · Query, filtering, provisioning, DTOs, and model adapters over relational data. · `src/Data`
- [Security](https://github.com/aces/loris/tree/main/src/Security): otp/auth · Core security primitives including one-time-password support. · `src/Security`
- [Shared UI](https://github.com/aces/loris/tree/main/jsx): react/ui · Common React/TSX components and form primitives reused across modules. · `jsx`
- [Client libs](https://github.com/aces/loris/tree/main/jslib): ts/http · Shared HTTP client and error handling helpers for module UIs. · `jslib`

### Feature modules

Major modular application areas.

- [Modules](https://github.com/aces/loris/tree/main/modules): modular monolith · Module packaging convention for PHP endpoints, JSX UIs, templates, locales, and tests. · `modules`
- [Study setup](https://github.com/aces/loris/tree/main/modules/configuration): study identity · Candidate, project, site, cohort, and timepoint management. · `modules/configuration`
- [Data capture](https://github.com/aces/loris/tree/main/modules/instruments): capture · Instruments, media, publication, and document workflows. · `modules/instruments`
- [Imaging](https://github.com/aces/loris/tree/main/modules/imaging_uploader): imaging suite · Imaging upload, browsing, QC, violations, and archive workflows. · `modules/imaging_uploader`
- [Electrophysiology](https://github.com/aces/loris/tree/main/modules/electrophysiology_uploader): physio suite · Electrophysiology upload and browser with chunked series visualization. · `modules/electrophysiology_uploader`
- [Genomics](https://github.com/aces/loris/tree/main/modules/genomic_browser): genomic browser · Genomic browser and file/sample upload workflows. · `modules/genomic_browser`
- [Admin & access](https://github.com/aces/loris/tree/main/modules/login): admin/security · Login, user accounts, preferences, module management, policy tracking, and OIDC. · `modules/login`
- [Query & API](https://github.com/aces/loris/tree/main/modules/api): api/query · REST/API endpoints and data query builder/execution surface. · `modules/api`
- [Quality & review](https://github.com/aces/loris/tree/main/modules/conflict_resolver): review · Conflict resolution, issue tracking, behavioural QC, and summary dashboards. · `modules/conflict_resolver`

### Data & operations

Database schema, migrations, batch jobs, tests, and docs.

- [Schema](https://github.com/aces/loris/tree/main/SQL): mysql/sql · Database schema, release migrations, cleanup patches, and generated table definitions. · `SQL`
- [Schema mirror](https://github.com/aces/loris/tree/main/raisinbread/RB_files): sql mirror · Table-definition SQL and legacy schema mirror used to validate the database model. · `raisinbread/RB_files`
- [Batch tools](https://github.com/aces/loris/tree/main/tools): ops/scripts · Importers, exporters, repair jobs, module management, and deployment helpers. · `tools`
- [Tests](https://github.com/aces/loris/tree/main/test): test suite · PHPUnit, integration, fixture, and module-specific test plans. · `test`
- [Docs](https://github.com/aces/loris/tree/main/docs): documentation · Installation, coding standards, module development, API, and operational documentation. · `docs`

## Connections

- htdocs → Core: boots · Front controllers enter the shared application framework.
- Core → Routing: routes · Core framework dispatches requests through routing.
- Core → Middleware: wraps · Core framework applies middleware for auth, language, decoration, and errors.
- Routing → Modules: loads modules · Routes into module-specific PHP entry points and file routers.
- Middleware → HTTP stack: wraps · Middleware shapes HTTP requests and responses.
- Routing → HTTP stack: produces · Routing resolves endpoints and HTTP responses.
- Modules → Shared UI: renders · Modules compose shared React components and form primitives.
- Modules → Client libs: calls · Module front ends use shared HTTP/query helpers.
- Modules → Data layer: reads/writes · Modules persist and query domain data through the shared data layer.
- Data layer → Schema: maps to · Data abstractions correspond to the MySQL schema.
- Schema → Schema mirror: mirrors · Generated and archived table definitions track the live schema.
- Study setup → Schema: defines · Study identity and scoping tables anchor the domain model.
- Data capture → Schema: stores · Instruments, media, publication, and documents persist in relational tables.
- Imaging → Schema: stores · Imaging upload, archive, and QC state are database-backed.
- Electrophysiology → Schema: stores · Electrophysiology uploads and annotations are database-backed.
- Genomics → Schema: stores · Genomic files, samples, and analysis metadata persist in tables.
- Admin & access → Middleware: enforced by · Authentication, MFA, permissions, and OIDC are enforced centrally.
- Quality & review → Data layer: queries · Review and conflict workflows consume shared data/query infrastructure.
- Query & API → HTTP stack: serves · API and query endpoints are exposed over HTTP.
- Query & API → Data layer: executes · Structured queries are built and run against shared data models.
- Batch tools → Schema: maintains · Batch jobs and repair scripts manipulate schema and data directly.
- Batch tools → Data layer: imports/exports · Operational scripts reuse core data conventions and extractors.
- Tests → Modules: covers · Tests exercise module behavior and integration paths.
- Tests → Core: covers · Tests validate the core framework behavior.
- Docs → Modules: describes · Documentation explains module conventions and workflows.
- Docs → Schema: documents · Docs capture SQL modeling and deployment conventions.
- Docs → Batch tools: documents · Operational docs cover scripts and maintenance flows.
