For the complete documentation index, see llms.txt. This page is also available as Markdown.

C4 Diagrams

This page describes SPICE using the C4 model: first the system context (who and what interacts with the platform), then the containers (deployable applications, services and data stores), then the main components inside the key containers. Each diagram is also described in text. For a shorter summary, see the Architecture Overview.

1. System context

Actors and external systems

Actor / system
Interaction with SPICE

Community health worker / frontline health worker

Uses the mobile app to register households and members, screen, assess, prescribe and follow up. Often works offline.

Facility clinician or supervisor

Uses the mobile app and, depending on role, the web applications to review patients and performance.

Administrator

Uses the admin web portal to manage organisations, geography, facilities, users, roles, clinical metadata and workflows.

Programme or facility manager

Uses the reporting web app to view and download reports.

Patient

Receives SMS messages from the platform. Does not use the platform directly.

SMS and email providers

External services the notification service calls to deliver messages.

Other FHIR systems

External health information systems that exchange data with SPICE through the FHIR server's standard REST API.

Analytics consumers

Optional external BI or analytics tools reading the reporting data.

Context diagram

How to read it: people interact with SPICE through its apps. SPICE delegates message delivery to external providers and exposes clinical data to other systems using FHIR.

2. Containers

Container inventory

Client applications

Container
Technology
Responsibility

Mobile app

Native Android (Kotlin)

Offline-first data capture, local encrypted database, background sync, dynamic form rendering.

Admin web portal

React single-page app

Organisation, geography, facility, user and role management; clinical metadata; workflow configuration.

Reporting web app

React single-page app

Report browsing, filtering and download; report-user and site management.

Edge

Container
Responsibility

Reverse proxy / API gateway

Single HTTPS entry point; routes requests by path to the backend services.

Backend services

Container
Responsibility

Authentication service

Validates credentials and issues and validates access tokens.

User service

Users, roles, organisations and user-to-organisation mapping.

Admin service

Geography and facility hierarchy, programmes, clinical workflows, medication and lab-test catalogues, customisation settings, terms and conditions.

SPICE service (clinical workflow service)

Clinical modules: registration, screening, assessment, medical review, prescriptions, lab tests, follow-up, immunisation, treatment plans, patient transfer and more. Applies business rules and stores operational data.

Offline sync service

Receives uploads from the mobile app, processes them asynchronously and assembles the data the app downloads.

Notification service

Delivers SMS and email via external providers; renders email templates; scheduled notification jobs.

FHIR mapper

Converts platform data to FHIR R4 resources and reads FHIR data back; writes to the FHIR server.

FHIR server

HAPI FHIR JPA server, customised with token-based authentication, district-aware partitioning options and database migrations.

CQL service (optional)

Evaluates clinical rules written in Clinical Quality Language.

Facility registry and report service

Facility registry, and the query API behind the reporting web app.

Common library

Shared code (security, DTOs, utilities, inter-service client support) packaged as a library, not a running service.

Data and infrastructure

Container
Responsibility

Platform database (PostgreSQL)

Users, organisations, geography, configuration and operational clinical data.

FHIR database (PostgreSQL)

The FHIR server's store of clinical resources.

Reporting database (PostgreSQL)

Flat reporting schemas populated by the ETL job.

Cache (Redis)

Caching of roles and configuration; shared state such as distributed locks.

Message queue (RabbitMQ)

Asynchronous hand-off of offline sync work.

Object storage

Files such as signatures, consent forms and exports.

Reporting ETL job

Scheduled Python batch job: platform and FHIR databases to reporting database.

Analytics stack (optional)

Orchestration, batch processing, query engine and dashboards for large-scale analytics.

Container diagram

The overview below shows the deployable services and the data stores they own. It leaves out the cache, the object store and most service-to-service calls so that it stays readable; the inventory above lists them. The next two diagrams follow the clinical data flow and the reporting flow.

Clinical data flow

The SPICE service is the hub for clinical writes. The offline sync service decouples the mobile app from the clinical services with a queue.

Reporting flow

Reporting is a one-way flow from the transactional databases to the reporting database, which the report service reads.

How to read them: all client traffic enters through one gateway. The SPICE service hands clinical data to the FHIR mapper, which writes it to the FHIR server. Not every service-to-service call is drawn. Where services use the cache, the object store and the message queue is listed in the inventory above.

3. Components

Mobile app

The app follows an MVVM and repository pattern with dependency injection.

Layer
Responsibility

UI (activities, fragments, view models)

One package per feature area (for example household, member, assessment, follow-up, dashboard). Screens extend shared base classes that handle view lifecycle and screen-level analytics.

Form engine

Renders assessment questionnaires, diagnosis and examination screens from configuration rather than hand-built layouts.

Repositories

One per feature; the boundary between view models and data sources.

Local database

Encrypted on-device relational database holding all working data for offline use.

Network layer

REST client with interceptors for authentication and error handling.

Sync

Background workers that upload pending changes and download updates when connectivity is available.

Analytics library

Separate module with its own local store that logs usage events and uploads them in batches.

Feature toggles

Switches that enable or disable features per build or deployment.

Web portals

Both portals are React single-page applications that call backend REST APIs through the gateway.

Portal
Main areas

Admin web portal

Organisation and geography management (regions, districts and other levels, facilities), users and administrators, locked and deactivated accounts, medication and lab-test catalogues, programmes, workflow configuration, consent and privacy-policy pages, user profile.

Reporting web app

Authentication and role-based navigation, region and site selection, a report list per site, filters (date, gender, diagnosis, referral), Excel download and report-user management.

Typical structure in both: routed page containers, reusable components, a centralised state store, and an API service layer.

Core platform services

Service
Key internal components

Authentication service

Credential check, token issuance and validation endpoints.

User service

User, organisation and role management; account lock and activation handling; database migrations.

Admin service

Controllers and services for countries, regions and other geography levels, branches and facilities, programmes, clinical workflows, medication, lab tests, designations, and workflow, lab-test and region customisation.

SPICE service

Feature modules for registration, screening, assessment, medical review, prescriptions, lab tests, follow-up, immunisation, treatment plans, patient transfer, symptoms, messages, device details and in-app analytics. Includes risk algorithms and clients for the admin, user, notification, offline-sync and FHIR services.

Offline sync service

Upload endpoint, queue producer and consumer, sync log, a scheduler, and clients for the SPICE, admin and CQL services.

Notification service

SMS and email senders behind a provider abstraction, email templates, scheduled jobs guarded by a distributed lock so that only one instance runs each job.

FHIR mapper

Per-resource mapping components (patient, encounter, observation, medication, immunisation and others) and a FHIR client for the FHIR server.

FHIR server

Standard HAPI FHIR JPA server (R4) plus SPICE additions: token-validation interceptor, optional partitioning by organisational unit, and custom database migrations.

Facility registry and report service

Facility and country registry, report definitions and the reporting-analytics query endpoints used by the reporting web app.

All Java services share a common library that provides security configuration, data-transfer objects, utilities and inter-service HTTP client configuration, and use the same layering: controller, service, repository.

Last updated