99
Matheus Saleh
Project inventory
Case study · Undergraduate research#05

Blood Bank

  • Flutter
  • Dart
  • TypeScript
  • Node.js
  • Fastify
  • Zod
  • SQLite
  • Drizzle
  • Venice AI
  • Docker
  • GitHub Actions

An app for blood donors: educational guide, donation history, the next date you can donate again, plus AI quizzes and a Q&A assistant. It started in 2023 as an undergraduate research project at FEMA and was rebuilt in 2026 as a monorepo with a Flutter app and a custom TypeScript API.

Timeline
2023 → 2026
Origin
Undergraduate research · CEPEIN FEMA
Platforms
Android · iOS · Web
Authors
Matheus Saleh and Gabriel Eduardo de Souza
Home screen with the next eligible donation date, counters and shortcuts

The problem

Blood donation is voluntary and depends on donors knowing whether they can give and when they can come back. The interval rules (60 days for men, 90 for women) and the yearly limit (4 and 3 donations) are not widely known, and wrong information keeps donors away.

The app brings reliable information, checked against Brazil's Ministry of Health, together with personal tracking: every recorded donation updates the estimate of the next date. The calculation is an educational estimate, and the app makes clear that the blood center's screening has the final say.

The 2023 version was part of the research paper “O uso de Dart e Flutter para desenvolvimento de jogos em aplicativos móveis” (in Portuguese), published in the proceedings of FEMA's Scientific Forum.

Screenshots

Screens from the real Web build in API mode, with a fictional donor and real Venice AI answers. The app UI is in Portuguese.

Artificial intelligence(6)

  • Quiz generated by Venice AI
  • Explanation after each answer
  • Quiz result
  • Assistant with suggested questions
  • Conversation that keeps context
  • Daily AI quota used up

Donor tracking(7)

  • Home: days until the next donation and bottom navigation
  • Donation history
  • Recording a donation
  • ABO/Rh red cell compatibility
  • Before, during and after guide
  • Local quiz, works without AI
  • Sign-in against the custom API

Dark theme and wide screens(2)

  • Dark theme
  • Responsive wide layout

Demo data: the donor Lucas Andrade is fictional and lives in a separate database. The capture environment's quota was lowered to 3 requests to show the block; the app default is 20 per day.

Features

What came from the 2023 version and what was built during the 2026 rebuild.

  • 2026

    Next eligible donation date

    Calculated from the minimum interval and the donation limit over 12 months, based on the sex set in the profile.

  • 2026

    AI quizzes

    Five questions per round, with shuffled topics and options and an explanation after each answer. Without AI, the local quiz still works.

  • 2026

    Q&A assistant

    Chat about donating and blood banks that keeps context and suggests follow-up questions. Profile and history are not sent to the provider.

  • 2026

    Daily AI quota per account

    20 requests a day, shared by quiz and chat, reserved atomically in SQLite and reset at midnight Brasília time.

  • 2023 · 2026

    Donation log and history

    Built in 2023; in 2026 it gained editing, delete with “Undo” and date validation.

  • 2023 · 2026

    Guide and educational quiz

    Tips for before, during and after donating, reviewed against the official source, and a quiz with explanations and a progress bar.

  • 2026

    ABO/Rh compatibility

    Full red cell compatibility table, covered by tests.

  • 2023 · 2026

    Accounts and profile

    Login built in 2023; sign-up, password reset and the donor profile (name, sex and blood type) in 2026.

  • 2023 · 2026

    News

    Published by admins, with error states and loading that tolerates missing fields.

  • 2026

    Demo mode

    Runs without a server: session, profile and donations stay in the device's local storage.

Architecture

A monorepo with the app and the API. The app talks to the API over HTTPS with a Bearer token; the AI key never leaves the server.

apps/mobileFlutter · MVVM
  • Screens and view models with ChangeNotifier and provider
  • Pure Dart domain: eligibility and compatibility rules
  • Repositories with two implementations: local (demo) and API
  • Token in secure storage (Keychain / Keystore)
  • go_router with a single guard and StatefulShellRoute to keep all four tabs alive
apps/apiTypeScript · Fastify
  • auth, donor, news and ai modules
  • Zod validates input and output and generates the OpenAPI docs
  • Drizzle ORM on SQLite with versioned SQL migrations
  • Rate limiting, Helmet, scrypt passwords and hashed opaque tokens
  • Venice AI integration and a persisted daily quota

Technical decisions

DecisionWhyTrade-off
Custom API instead of FirebaseFull control of the rules, no dependency on a cloud project, testable locallyRunning a server, database and email
Hashed opaque tokens (not JWT)Instant revocation on logout and password change; a token leaked from the database is uselessOne database query per request
Venice only on the backendThe key never ships in the APK or Web build; validation and limits live on the serverNeeds connectivity, provider credit and handling of bad answers
Daily quota with atomic reservationPrevents going over the limit with concurrent sessions, devices or processesEvery instance must share the same database
YYYY-MM-DD datesDonation rules count days, not instants; avoids time zone bugsOne day of server tolerance for time zones ahead
Read the full README

From 2023 to 2026

Original version · 2023

  • Login with Firebase Authentication
  • News and donations straight from Firestore
  • Guide, 5-question quiz and About screen
  • Firebase called from inside widgets
  • Accounts could only be created in the Firebase console
  • Only Flutter's default test, which failed

Rebuild · 2026

  • Flutter 3.50 with MVVM architecture and go_router
  • Custom Fastify + SQLite API replacing Firebase
  • Sign-up, password reset and revocable sessions
  • AI quiz and assistant with a daily quota per account
  • Content reviewed against the Ministry of Health
  • 145 tests and CI on GitHub Actions

Quality

API tests
71
app tests
74
Node versions in CI (22 and 24)
2

Tests cover isolation between users, session expiry and revocation, rate limiting, password reset, eligibility rules with leap years, the full ABO/Rh table, a mocked Venice integration and the daily quota under cross-process concurrency. CI runs lint, typecheck, tests, build and audit for the API, builds the Docker image, and produces the app's Web build and APK.

Limitations and next steps

  • Password reset still needs an email provider; today the code is printed in the API log.
  • The 2023 data stayed in the original project's Firestore and was not migrated.
  • The iOS build was not produced, since it requires macOS.
  • Next steps: a reminder when the donation date arrives, PostgreSQL in production and a map of blood centers from official data.

Want to see the code?

The repository has the app, the API, the tests and the script that generates these screenshots. Built by Matheus Saleh and Gabriel Eduardo de Souza.

Achievement Unlocked!