NEXA
An offline-first messenger that moves messages phone to phone, with no network at all. Done as a university capstone project. A messaging network with no network.
- Role
- Project lead — DTN and comms layer, three-person team
- Timeline
- 6 weeks, submitted Sept 2025
- Stack
- Kotlin · Nearby Connections · Libsodium · SQLite · ZXing
In motion
The problem
Messaging apps assume a working internet connection and a server in the middle. In parts of South Africa that assumption fails daily — data is metered, coverage drops between townships, and a load-shedding block takes the local tower with it. The phones are there; the network is not.
The centralised model also makes every message somebody else’s to read, store and lose. For a group organising in a place with patchy coverage the useful property is not scale — it is that the system keeps working when the infrastructure does not.
The solution
Nexa removes the server. Phones advertise and discover each other over Google’s Nearby Connections API, exchange public keys through a handshake or a scanned QR code, and encrypt every message end to end with Libsodium. When the recipient is out of range the message is stored and carried by intermediate peers, delay-tolerant-network style using a store-and-forward mechanism, until it reaches a device that can deliver it. Identities, keys and history all live on the device.
- 01Peer discovery in under five seconds over Bluetooth and Wi-Fi Direct, with no pairing step.
- 02End-to-end encryption on every message, with keys generated on-device and never transmitted.
- 03Store-and-forward delivery across up to five hops, so messages reach peers who were never in range.
- 04QR-code pairing for adding a contact whose key you want to verify in person.
- 05Media sharing up to 50MB, chunked into 64KB pieces above 10MB.
Why this stack
Google Nearby Connections API
Handles Bluetooth and Wi-Fi Direct behind one API and negotiates the fastest available transport per connection, which is work I would otherwise have written twice.
RejectedRaw Bluetooth sockets plus Wi-Fi Direct, which meant maintaining two discovery paths and two failure modes for one feature.
Libsodium
Gives one audited primitive per job — key exchange, symmetric sealing, password hashing — with no cipher choices to get wrong.
RejectedBuilding the key exchange on the Java crypto APIs, where the defaults are easy to misread and the mistakes are silent.
SQLite with a repository layer
Hand-written SQL behind DatabaseRepository kept the schema visible and the coroutine boundary in one place, on a dataset that is three tables and never joins deeply.
RejectedRoom, whose annotation processing and migration ceremony cost more than it saved at this size, and which hid queries I was still changing weekly.
EncryptedSharedPreferences
Private keys and per-peer shared secrets needed storage the rest of the app could not read; an in-memory cache in KeyManager keeps the decrypt cost off the message path.
RejectedKeeping keys in the SQLite database alongside message content, which puts the secrets and the thing they protect in one file.
ZXing
QR generation and scanning in one library, so verifying a peer’s identity in person is a camera frame rather than a typed fingerprint.
RejectedManual entry of device identifiers, which is still the fallback when a code will not scan.
- How a request moves through it
- 1The user types a message; EnhancedMsgHandler seals it with the shared key it derived for that peer, so plaintext never leaves the process.
- 2DTNMessageManager wraps the ciphertext in a DTNBundle — bundle id, source, destination, hop count, TTL — and puts it in the pending queue.
- 3NearbyService resolves the destination device id to a live endpoint id and sends the payload if that peer is connected.
- 4If it is not, the bundle stays buffered and is offered to every peer that connects afterwards, each one incrementing the hop count and carrying it further.
- 5On arrival the receiver checks the bundle id against seenBundles, decrypts, writes a MessageEntity to SQLite, and emits it to the UI over a SharedFlow.
Decision log
Hurdles that changed the shape of the system, in the order they were hit.
The network’s idea of identity lasted minutes
Nearby Connections addresses peers by endpoint id, which it regenerates per discovery session. I had built contacts, message routing and the key store against that id, so every reconnection produced a stranger — the same phone, a new identity, and a conversation that could not be matched to its history.
The fix was a handshake that trades a stable, app-generated device id on connect, and two concurrent maps translating between the two. It sounds like plumbing, but it drew the line the rest of the system needed: the comms layer owns ephemeral addressing, and everything above it only ever sees a device id.
One routing strategy could not serve both cases
The first forwarding engine treated every message the same way and flooded it to all peers. For a group message that is the right behaviour. For a one-to-one message it meant handing a copy to a dozen phones to reach one, spending their battery and storage on delivery that one careful hop would have made.
Routing split in two: Spray-and-Wait caps the number of replicas for direct messages, and Epidemic flooding stays for group traffic where delivery probability matters more than cost. Holding both behind one strategy interface is the only reason the DTN logic survived being rewritten as often as it was.
Flooding sent messages back where they came from
Epidemic routing has no memory by default. Peers handed bundles back to the device that had just given them one, the same message arrived three or four times, and a message with no reachable destination circulated until the app was killed.
Three things stopped it: a seenBundles set of processed bundle ids, a TTL, and a hop count checked before every forward. The broader lesson was that in a store-and-forward network the interesting state is not what you are holding, it is what you have already seen.
Large payloads broke a path built for text
Sending a photo over the same code path as a chat line failed in the least useful way — the transfer would begin, stall partway, and leave the receiver holding a partial payload it could neither identify nor discard.
Files now travel as metadata first, then content: anything over 10MB is split into 64KB chunks and reassembled against the header, with a hard 50MB ceiling. Announcing the shape of a transfer before sending it meant the receiver could allocate, track progress, and for the first time fail cleanly.
Group chat was cut with its plumbing already built
Community channels were in scope from the start, and the parts that are hard were finished: epidemic routing for group traffic, the group entity and its membership handling, and the mesh forwarding that makes a channel possible at all.
What ran out, six weeks in, was the time to build the UI and the invite flow. Cutting the feature rather than shipping it half-wired was the right call, and it left the codebase in an odd but honest state — the mechanism is tested and reachable, and the screen that would use it does not exist.
Trade-offs
Sessions do not survive a restart
Chat history reads back from SQLite, but the encrypted session does not: close the app and you re-do the handshake before a live thread will open. Admittedly we had rushed, but it was something I fixed myself. PS: having a dB engineer is WAAAY more important than you'd think
Signed with a debug certificate
MobSF graded the build 46/100 and flagged debuggability, exported components and 14 dangerous permissions. None of it was unfixable, but I got to learn that Android security and general web development security is VERY different
Android only, and deliberately islanded
No iOS, no cloud sync, and no way to reach someone who is not eventually within a few hops of you. Removing the server removed the fallback along with the dependency.
What I took from it
Identity has to belong to the layer that needs it, not to the transport. Every bug in the first three weeks traced back to trusting an address the network considered disposable.
The store-and-forward mechanism to implement delay-tolerant networking turned out be the greatest hint we could've gotten for the whole project.
Messaging applications have a lot more moving parts than I had anticipated. Fair it was my first application ever, but I gained a whole new appreciation for it