Skip to content
cezar.garcia
All projects

Solo academic project · 2026

MedicalField

An offline-first emergency medical record that syncs without duplicating or losing data.

ElectronReactTypeScriptSQLiteJavaSpring BootFastAPIPostgreSQL
196
automated tests, all passing
3
microservices in three languages
6
design patterns applied

Overview

MedicalField is the final project of the Software Architectures course (Univates, 2026/B), which I built on my own, from the back end to the desktop app. It is an emergency medical record for rescue teams, such as ambulance crews, that often work with no internet.

The professional records the patient, the medical record and the care report in an app that works with no connection. When it is back, the data goes up to the server. Records can be browsed in an admin portal, exported as PDF and sent by email.

Architecture

The client app is a desktop app (Electron and React) with a local SQLite database. On the server, three microservices sit behind an Nginx that acts as the single entry point: ms-auth in TypeScript (login, session and audit), ms-clinico in Java with Spring Boot (people, records, care reports and sync) and ms-docs in Python with FastAPI (report PDF and email delivery).

All three use the same PostgreSQL, each with its own schema and its own user. A React admin portal browses care reports, logs and conflicts.

Architecture diagram: desktop app, portal and Postman talk to Nginx, which routes to ms-auth, ms-clinico and ms-docs, all on PostgreSQL
Three microservices in three languages behind a single entry point.

A single write path

The device never depends on the network to work. Online or offline, writing is the same: in a single SQLite transaction, the app writes the record, an item in the send queue (outbox) and a local log. Either everything goes in or nothing does.

The only difference is that, when online, the queue is sent right away. Having two paths, one for online and one for offline, would mean twice as many places for bugs.

An Online/Offline switch on screen works as the master switch: when Offline, the HTTP client refuses any call. The switch is an Observer, and the sync engine fires by itself when it goes back to Online.

Diagram: the professional saves the report, SQLite writes the report and a queue item; offline the item waits, online it is sent, and the server writes it with the same ID
The app always writes to the device first.

Sync and idempotency

The engine sends the queue in the order the items were created, one at a time. The order guarantees the person arrives before the record, and the record before the care report. Then it pulls from the server whatever changed since last time.

Every record has an ID created by the client, and the server recognises what it has already received. If the response is lost on the way, resending is safe: the server answers that it already existed and nothing shows up twice. In the database, the guarantee comes from primary keys and INSERT ... ON CONFLICT DO NOTHING.

  • A temporary error (network, 503, timeout) stops the queue and schedules a retry with growing backoff, from 5 s up to 5 min.
  • A permanent error marks the item and moves on, so one bad item doesn't block the whole queue.
  • If the app closes in the middle of a send, the item goes back to pending on the next start.
  • Every record keeps who created it and who synced it, which can be different professionals.
Sync diagram: the app sends person, record and care report in order, then receives from the server whatever changed
First send the queue in order; then receive what changed.

Conflicts resolved by merging

A clinical record is not edited after it is created. So the only possible conflict is creating the same thing twice, for example the same patient registered in two ambulances with no signal.

The server detects it by CPF and merges: the record that was already there is kept, empty fields are filled in and, when both sides have different values, a strategy decides (Strategy). The default is most recent wins, with the origin timestamp stored per field.

Nothing is lost: the discarded value is recorded and shown on the portal's conflicts page. The discarded ID becomes an alias of the kept ID, so items still in the device queue remain valid.

Diagram: the same patient registered in two ambulances is merged by the server into one record, with the most recent phone number and both care reports
Same CPF, same person: the server merges the two records.

Offline login and audit

Online, access uses a 15-minute RS256 JWT with a 7-day refresh token. Offline, the app checks the password against a local verifier stored at the last online login, valid for 7 days and locked after 5 wrong attempts in a row.

Whoever takes over the shift may never have used that device. So on every sync the app receives the credentials of active professionals and stores the hashes encrypted by the operating system's vault.

Every action produces a log, on the server and on the device, and local logs go up with the sync.

Decisions and tests

Decisions are documented one by one, with the reason and the alternatives that were discarded. The project applies six design patterns where they show up naturally: Repository, Strategy, Observer, Command (each queue item knows how to run itself), Adapter (email delivery) and Builder (PDF assembly).

There are 196 automated tests across the three services, the portal and the app. On every push, GitHub Actions runs each part's tests, brings up the whole system in Docker and builds the Windows installer.

Full stack

Client app
ElectronReactTypeScriptMantineSQLite (node:sqlite)
Admin portal
ReactTypeScriptTailwind CSS v4React Aria
Microservices
ms-auth: Node.js, TypeScript, Fastifyms-clinico: Java, Spring Bootms-docs: Python, FastAPI, WeasyPrint
Data and infrastructure
PostgreSQLNginxDocker ComposeSQLAlchemy CoreAlembic
Security
JWT RS256refresh tokenscryptbcrypt
Testing and delivery
GitHub ActionsPostman / Newmaninstalador Windows (.exe)