Format versions: 2.0 (current, encrypted), 1.0.1 (legacy, plain ZIP) Status: Stable License: This specification is released under CC-BY-SA 4.0. The reference implementation in DIRD+ is licensed under AGPL-3.0.
This document describes the .dird file format used by DIRD+ to export and import patient and session data. The format is open and non-proprietary: any developer or tool can read, write, or transform .dird files using standard ZIP, JSON, AES-256-GCM and Argon2id tooling.
A .dird file is one of:
- v2.0 (current): An encrypted container wrapping a ZIP payload. The container starts with the magic bytes
DIRDand uses AES-256-GCM with an Argon2id-derived key. See §1.1. - v1.0.1 (legacy): A plain ZIP archive. Detected by the absence of the
DIRDmagic. Supported for import only, for migration from pre-v2.0 installations.
Once decrypted (v2.0) or opened directly (v1.0.1), the inner ZIP contains JSON metadata, image blobs, and PDF reports for one or more patients or sessions.
The file extension is .dird. For v2.0 the MIME type is application/octet-stream; for v1.0.1 it is application/zip.
Binary layout (little-endian unless noted):
| Offset | Size | Field | Notes |
|---|---|---|---|
| 0 | 4 | magic |
ASCII "DIRD" (0x44 0x49 0x52 0x44) |
| 4 | 2 | version |
2 for v2.0 |
| 6 | 2 | flags |
Reserved, MUST be 0 |
| 8 | 1 | kdf_algo |
1 = Argon2id |
| 9 | 4 | kdf_m_kib |
Argon2id memory cost in KiB (default 65536 = 64 MiB) |
| 13 | 4 | kdf_t |
Argon2id time cost (default 3) |
| 17 | 1 | kdf_p |
Argon2id parallelism (default 4) |
| 18 | 16 | salt |
Argon2id salt |
| 34 | 12 | wrapped_dek_nonce |
AES-256-GCM nonce for the wrapped DEK |
| 46 | 48 | wrapped_dek |
32-byte DEK encrypted with KEK + 16-byte GCM tag |
| 94 | 12 | content_nonce |
AES-256-GCM nonce for the inner ZIP |
| 106 | … | ciphertext |
Inner ZIP encrypted with DEK, 16-byte GCM tag appended |
Algorithms:
- KDF: Argon2id (RFC 9106). The user-supplied passphrase +
saltderive a 32-byte KEK usingkdf_m_kib/kdf_t/kdf_p. DIRD+ writes OWASP-2025 parameters (m=64 MiB,t=3,p=4). - AEAD: AES-256-GCM with 96-bit nonces and 128-bit tags.
- Associated data:
- DEK wrap: ASCII
"DIRD-DEK-v2". - Content: ASCII
"DIRD-v2".
- DEK wrap: ASCII
Decryption flow:
- Parse header; verify
magic == "DIRD"andversion == 2. - Derive
KEK = Argon2id(passphrase, salt, params from header). DEK = AES-256-GCM_decrypt(KEK, wrapped_dek_nonce, wrapped_dek, aad="DIRD-DEK-v2").inner_zip = AES-256-GCM_decrypt(DEK, content_nonce, ciphertext, aad="DIRD-v2").- Proceed with the v1.0.1 ZIP-level layout described below.
If any AEAD step fails, the container is rejected (incorrect passphrase, tampered bytes, or wrong version). DIRD+ does not implement passphrase recovery — losing the passphrase makes the file permanently unrecoverable.
The inner ZIP payload follows the layout described in the rest of this document.
.dird files come in three flavours, distinguished by the export_type field in metadata.json:
export_type |
Contents |
|---|---|
full |
All patients and all their sessions. |
patient |
One patient and all their sessions. |
session |
One single session. |
The directory structure differs slightly between patient/full exports and session exports.
example.dird/
├── metadata.json
└── sessions/
├── session_001/
│ ├── images/
│ │ ├── img_001.jpg
│ │ ├── img_002.png
│ │ └── ...
│ ├── images_metadata.json
│ ├── detections.json
│ ├── segmentations.json
│ ├── measurements.json
│ ├── classifications.json
│ └── reports/
│ ├── report_screening.pdf
│ └── report_followup.pdf
├── session_002/
│ └── ...
└── ...
For single-session exports, the contents of the session folder are placed at the root of the archive:
example.dird/
├── metadata.json
├── images/
│ └── ...
├── images_metadata.json
├── detections.json
├── segmentations.json
├── measurements.json
├── classifications.json
└── reports/
└── ...
JSON document with the export header and patient information.
{
"export_version": "1.0.1",
"exported_at": "2026-05-20T14:32:00Z",
"export_type": "full | patient | session",
"patient": {
"id": "uuid-or-internal-id",
"name": "string | null",
"national_id": "string | null",
"date_of_birth": "YYYY-MM-DD | null",
"gender": "M | F | X | null",
"contact": {
"phone": "string | null",
"email": "string | null"
},
"clinical_history": "string | null"
},
"sessions": [
{
"id": "session_001",
"session_date": "ISO-8601",
"clinician_id": "string",
"notes": "string | null"
}
]
}Fields marked | null are optional. DIRD+ writes them as null when absent; tools reading the format must accept either null or missing keys.
Notes:
exported_atandsession_datefollow ISO 8601 with timezone (RFC 3339 profile recommended).idvalues are internal identifiers; they are unique within the file but not globally unique unless a UUID is used.
A folder containing the raw retinal image files (JPEG or PNG). File names are referenced from images_metadata.json.
- Recommended format: JPEG for fundus photographs, PNG for any post-processed image where lossless compression is desired.
- Filenames should be ASCII-safe and unique within the session.
Metadata for each image in images/.
{
"version": "1.0.1",
"images": [
{
"id": "img_001",
"filename": "img_001.jpg",
"eyeType": "OD | OS | unknown",
"capture_date": "ISO-8601 | null",
"width": 1024,
"height": 1024,
"device": "string | null",
"notes": "string | null"
}
]
}eyeType:OD(oculus dexter / right),OS(oculus sinister / left), orunknown.
Bounding box detections produced by the AI model, with foreign key references to images.
{
"version": "1.0.1",
"model": {
"name": "DIRDv2r0",
"version": "2.0.0",
"doi": "10.5281/zenodo.19685466"
},
"detections": [
{
"id": "det_001",
"imageId": "img_001",
"class": "hemorrhage | hard_exudate | cotton_wool_spot | microhemorrhages | optic_disc | fovea | ...",
"confidence": 0.87,
"bbox": {
"x": 245.5,
"y": 312.8,
"width": 18.3,
"height": 16.0,
"coord_system": "pixel"
},
"validated_by_clinician": true,
"clinician_note": "string | null"
}
]
}- Bounding box coordinates are in pixels of the original image, with the origin at the top-left corner (standard image coordinate system).
confidenceis the raw model score, in the range [0, 1].validated_by_clinicianindicates whether a qualified clinician has reviewed this specific detection.
Pixel-level segmentation masks. Available when the model produces segmentation output (planned for v3+; in v2.0 this file may be present but empty or absent).
{
"version": "1.0.1",
"segmentations": [
{
"id": "seg_001",
"imageId": "img_001",
"class": "vessel | hemorrhage | ...",
"mask_filename": "masks/seg_001.png",
"encoding": "binary_png | rle | polygon"
}
]
}Mask files (when encoding is binary_png) live in a masks/ folder alongside images/.
Derived measurements computed from the images or detections (vessel calibers, lesion counts, area fractions, etc.).
{
"version": "1.0.1",
"measurements": [
{
"id": "meas_001",
"imageId": "img_001",
"metric": "lesion_count | vessel_caliber | ...",
"value": 12,
"unit": "count | mm | um | ratio | ...",
"method": "string"
}
]
}The per-image diabetic-retinopathy classification — the clinical conclusion (severity,
applied guideline, treatments, urgency, and the audit flag manuallyModified). Present when
the image was classified. Omitting this file loses the diagnosis on re-import.
{
"version": "1.0.1",
"classifications": [
{
"id": "cls_001",
"imageId": "img_001",
"eyeType": "OD | OI | unknown",
"severity": "string (guideline-specific grade)",
"confidence": "low | moderate | high",
"guideline": "icdr-2024 | minsal-2017 | ...",
"treatments": "string",
"followupDays": 180,
"urgency": "routine | accelerated | urgent",
"manuallyModified": false
}
]
}Clinical PDF reports generated by the application. File naming convention:
report_<type>.pdf
where <type> is one of screening, followup, referral, or a custom string.
Reports are standard PDF/A-compatible documents that can be opened by any PDF reader.
For implementers extending DIRD+ or building compatible tools, this is the mapping between .dird file contents and the internal SQLCipher schema used by the reference implementation (DIRD+ v2.0+; pre-v2.0 installations used a Dexie/IndexedDB schema, migrated automatically on upgrade):
File in .dird |
Database table | Notes |
|---|---|---|
metadata.patient |
patients |
One record per file (or many in full exports) |
metadata.sessions[] |
sessions |
Foreign key to patient |
images/* + images_metadata.json |
images (blob + metadata) |
Images stored as blobs |
detections.json |
detections |
Foreign key: imageId |
segmentations.json |
segmentations |
Foreign key: imageId |
measurements.json |
measurements |
Foreign key: imageId |
classifications.json |
imageClassifications |
Foreign key: imageId — the DR diagnosis |
reports/*.pdf |
reports |
Foreign key: sessionId |
Reference implementation:
- Exporter:
src/lib/export/dird-exporter.ts(functionsexportPatientat line 14,exportSessionat line 108). - Importer:
src/lib/export/dird-importer.ts. - Packaging: JSZip.
From DIRD+ v2.0 onward, .dird files are encrypted at rest using AES-256-GCM in an envelope-encryption scheme (KEK/DEK), with the KEK derived from a user-provided password via Argon2id. The exact binary layout, field sizes, and decryption flow are specified in §1.1 — this section does not restate them to avoid drift between the two.
Unencrypted (legacy v1.0.1) .dird files do not have the DIRD magic; they begin with the standard ZIP PK\x03\x04 signature. Tools must check the first 4 bytes to determine whether decryption is required.
Reference implementation of the container format: src/lib/export/dird-container.ts (binary layout documented in its header comment, kept in sync with src-tauri/src/crypto.rs).
Any standard tool can read an unencrypted .dird file:
# Inspect contents
unzip -l example.dird
# Extract everything
unzip example.dird -d extracted/
# Read metadata
unzip -p example.dird metadata.json | jq .Python example:
import zipfile
import json
with zipfile.ZipFile("example.dird") as z:
with z.open("metadata.json") as f:
meta = json.load(f)
print(meta["export_version"], meta["export_type"])JavaScript example (Node.js with JSZip):
import JSZip from "jszip";
import { readFileSync } from "fs";
const zip = await JSZip.loadAsync(readFileSync("example.dird"));
const meta = JSON.parse(await zip.file("metadata.json").async("string"));
console.log(meta.export_version, meta.export_type);The format is versioned at two levels:
- Container version: in the binary header (
versionfield).2for v2.0 encrypted containers; absent for v1.0.1 plain ZIPs (detected by the missingDIRDmagic). - Inner payload version: in
metadata.json(export_versionfield). Current is 2.0.0 (paired with container v2.0); legacy was 1.0.1 (plain ZIP).
We follow Semantic Versioning for the format:
- MAJOR changes (e.g., 1.x → 2.x): incompatible schema changes. Old files cannot be read by new code without a converter.
- MINOR changes (e.g., 1.0 → 1.1): backwards-compatible additions. Old files remain readable; new files use new optional fields.
- PATCH changes (e.g., 1.0.0 → 1.0.1): documentation or clarification only; no schema changes.
DIRD+ supports reading all versions ≥ 1.0.0.
- File size: PDFs and images embedded as blobs cause
.dirdfiles to grow quickly. For full backups of large patient cohorts, expect file sizes in the hundreds of megabytes to gigabytes. - Pre-encryption signing: In version 1.0.1, unencrypted
.dirdfiles include no integrity signature. Tampering is detectable only by comparing hashes. Encryption (v2.0+) provides integrity via GCM authentication tags. - Patient identity uniqueness:
patient.idis unique within the file but not globally unique. When importing multiple.dirdfiles, the importer must reconcile potential collisions. - Sensitive content: Unencrypted
.dirdfiles contain personally identifiable information (PII) and protected health information (PHI). Treat them with the same care as any clinical record. Always use encrypted exports for any transfer outside the controlled clinical environment.
This specification is maintained alongside the DIRD+ source code. Proposed changes are tracked as GitHub Issues with the format-spec label. Substantive proposals should be submitted as Pull Requests against this file.
Backwards compatibility is a core design value: changes that break version 1.x readers will only be accepted in a new major version (2.0).
Format: DIRD+ Patient Case File Format (.dird)
Specification version: 1.0.1
Specification license: CC-BY-SA 4.0
Reference implementation: DIRD+ (AGPL-3.0)
Maintainer: Nicolás Baier Quezada, Universidad Austral de Chile (UACh)