How icure/kraken-lite works
Project Type and Purpose
• Kraken Lite is a lightweight, open-source back-end service built with Kotlin and Spring Boot.
• It exposes REST endpoints (v1/v2) for CRUD operations on health-care entities, backed by CouchDB and optional object-storage modules (SAM, Kmehr).
• It ships as a fat JAR (lite-core) and can be run standalone, via Docker, or with Docker Compose (CouchDB, booster, etc.).
File-Structure Analysis
• Top-level:
• compose/… ─ Docker Compose definitions for CouchDB and “cardinal-deployment.”
• booster/ ─ Preloader JAR + Dockerfile to speed up Spring Boot startup
• lite-core/ ─ Core Spring Boot application (Kotlin)
• buildSrc/ ─ Custom Gradle tasks (start/clean CouchDB, Docker utils)
• kraken-common (Git submodule) and gradle wrappers/configs
• Inside lite-core/src/main/kotlin/org/taktik/icure:
• asyncdao/ ─ DAO implementations against CouchDB (async)
• asynclogic/ ─ Business logic layer
• asyncservice/ ─ Service layer that orchestrates DAO + logic
• services/external/rest/lite/v1/v2/controllers ─ HTTP controllers
• config/, security/, cache/, properties/ ─ Spring configuration modules
• entities/, errors/, spring/asynccache/ ─ Domain models, error handlers, caching
README Insights
• Describes runtime properties for:
• CouchDB partitioning, view indexing (background/foreground)
• Authentication endpoints (JWT, HCP-only)
• Optional SAM/Kmehr modules (region flags, Spring profiles)
• External design-docs (signed CouchDB views)
• Plugin loading from external JAR folder
Main Components
a. HTTP API Layer
• Spring Boot embedded Tomcat + controllers (v1/v2).
• Booster preloader (optional entrypoint to accelerate app startup).
b. Service Layer
• asyncservice implementations
• Orchestrates calls to business logic and DAO.
c. Business-Logic Layer
• asynclogic implementations (validation, object-storage adapters).
d. Data-Access Layer
• asyncdao for CouchDB (Dispatcher, DAO interfaces, implementations).
• ObjectStorage DAOs (migration, tasks).
e. CouchDB Cluster
• Single or multi-node CouchDB (with partitions: default, Maurice, etc.)
• External views loader (via Git URLs + signing key).
f. Optional Modules
• SAM module (drug database)
• Kmehr module
• Plugin folder (custom JARs)
g. Infrastructure
• Docker Compose services (CouchDB container, booster container)
• Gradle build tasks
Relationships & Data Flow
• Client → HTTP(S) Load Balancer → (Booster) → Spring Boot Controllers
• Controller → Service → Logic → DAO → CouchDB
• CouchDB ↔ asyncview indexers (background or forced foreground)
• ObjectStorage client ↔ local FS or remote Icure cloud storage
• External View Loader fetches design-docs at startup
• Plugins folder scanned at startup and wired into Spring context
Architectural Patterns & Principles
• Layered architecture (Controller → Service → Logic → DAO)
• Asynchronous/non-blocking I/O for CouchDB calls
• Spring Boot auto-configuration (profiles, property overrides)
• Plugin-based extensibility (SAM, Kmehr, user plugins)
• Git-submodule for common mappers/generators (kraken-common)
Technologies & Frameworks
• Kotlin + Spring Boot (web, security, config)
• CouchDB (NoSQL, partitions, design Docs)
• WebSocket handler (for real-time operations)
• Docker & Docker-Compose (in compose/)
• Gradle Kotlin DSL (buildSrc custom tasks)
• Caffeine cache (async map cache)
• JWT for authentication