Pero Grubač

Incident Alert

Citizens report incidents on a map; moderators approve them first.

ArchitectureReact apps → ASP.NET services ⇄ RabbitMQ + PostgreSQL

read, reportGETGETnew reportapproval,categoriesJWTJWTPublic appReact · citizensMLk-means groups · :5004Statisticsper period · :5006IncidentAlertpublic API · :5000RabbitMQMassTransitManagementmoderation API · :5002PostgreSQLincident_alertPostgreSQLincident_alert_managementModeration appReact · moderators, admins
Two React apps and four ASP.NET Core services. Solid lines are HTTP calls, dashed lines are MassTransit messages through RabbitMQ. The public API and Management each own a PostgreSQL database; ML and Statistics keep no data and read the public API.
Incident Alert: the public map of Bosnia and Herzegovina with incident pins and a place picked for a new report, next to a panel with period and category filters and the latest reported incidents

What it does

Incident Alert lets citizens report what is happening around them, such as a fire, a flood, a traffic problem or a crime, at a place on the map and with photos. Nothing they send goes public straight away. Every report waits in a moderation queue, and only when a moderator approves it does it appear on the public map, count in the statistics and get grouped with similar reports.

Each audience has its own React app. Citizens use the public app without an account: they browse approved incidents by period and category, open a place to see everything reported there, and report something new. Moderators and administrators sign in to the moderation app, where they review the queue on a map, approve, reject or delete reports, manage the categories, and look at statistics, a hot-spot map and groups of similar reports. Both apps are in Serbian and English, with a light and a dark theme.

Architecture

I split the backend into four ASP.NET Core 10 services. The two that keep data each own a PostgreSQL database. They never share tables: everything that crosses a service boundary is a message or an HTTP call.

  • IncidentAlert is the public API. It serves approved incidents and their photos and accepts new reports.
  • IncidentAlert-Management holds the moderation queue, the categories and the accounts, and signs moderators in.
  • IncidentAlert-ML groups published incidents by the similarity of their text, with ML.NET text features and k-means.
  • IncidentAlert-Statistics works out the busiest places and categories per period, the daily trend and the hot spots.

The public API and Management talk through RabbitMQ, using MassTransit. A new report travels from the public API to Management as an event, photos included, and waits there as pending. When a moderator approves it, Management publishes an approval event and removes the report from its queue; the public API then saves the incident, creating the place if it is new. Category changes travel the same way, from Management to the public API. ML and Statistics keep no data of their own: they read published incidents from the public API over HTTP and compute on request.

The moderation app calls Management, ML and Statistics with the same JWT. The public app only talks to the public API.

Decisions and why

  • I made moderation a separate service with its own database. Nothing a citizen sends reaches the public database until a moderator approves it, so the public API never has to filter out unreviewed data.
  • Messages carry the whole report, photos included. That way Management never calls the public API, and an approval is still applied if the public service restarts in between, because RabbitMQ keeps the message.
  • Management owns the categories and pushes every change to the public API as an event, so both sides check reports against the same list.
  • I kept Statistics and ML stateless. They read published incidents and compute on request, so there is no third copy of the data to keep in sync.
  • Places are matched by name. A report for a place that already exists reuses it, so every report for one place shows up together in the apps.
  • I wrote the mappings by hand instead of using AutoMapper. The free AutoMapper versions are affected by a published vulnerability (GHSA-rvv3-g6hj-g44x) and the fixed ones need a commercial licence. Plain extension methods are checked by the compiler and easy to read.

Security

  • Accounts are approved by a person. Registering, or signing in with Google for the first time, only creates an account. An administrator has to give it the moderator role, so a stranger cannot sign up and start publishing.
  • The API never trusts the browser about identity. For Google sign-in it checks the signature, audience and expiry of Google’s ID token itself, and accepts only verified addresses of the student domain.
  • One signing key, three services. Management signs the JWT, and ML and Statistics validate it with the same issuer, audience and key, so the analysis is not public.
  • No secrets in the repository. Passwords and the signing key come from the environment, and the services refuse to start with a missing or short key, or with the development key in Production.
  • Uploaded file names are cut down to their last segment before they touch the disk, so a crafted name cannot write outside the incident’s folder.

Testing and deployment

The backend has 94 automated tests: the services against an in-memory database, and the APIs hosted in memory with a test message bus and a fake Google. They cover the moderation flow (approving publishes and removes the report, nothing skips approval), sign-in and roles, accounts waiting for approval, Google sign-in with forged tokens and foreign addresses, every statistic and the ML grouping. The public app adds 52 tests and the moderation app 56, with Vitest and Testing Library.

Every service has a health endpoint, and the whole backend starts with one Docker Compose command. CI builds and tests the backend, then starts the stack and runs an end-to-end smoke test: it reports an incident, approves it as a moderator, waits for it on the public API, and checks that Statistics refuses a request without a token and answers one with it. On the default branch, the images of the four services and both apps are published to the GitHub Container Registry.

HomepageAboutsectionSystemssectionIndex of projectssectionBrowser appspageContactsectionIncident Alertsystem · case studyeMobilityHubsystem · case studyChat Roomsystem · case studyOnline Library Systemsystem · case studyRepoHealthlive app · case studyOpen RepoHealth app (opens in a new tab)live appGitHub Discord Bottool · case studyBookstore APIweb project · case studyFitForgemobile app · case studyAssetManagermobile app · case studyStore Managementdesktop app · case studyETF Oglasimobile app · case studyDevKitlive app · case studyOpen DevKit app (opens in a new tab)live appDev Timelinelive app · case studyOpen Dev Timeline app (opens in a new tab)live appGitHub Dashboardlive app · case studyOpen GitHub Dashboard app (opens in a new tab)live appStore Chain Managementdesktop app · case studySecure Repositorytool · case studyMinimal Blogweb project · case studyCatan Map Generatorlive app · case studyOpen Catan Map Generator app (opens in a new tab)live appMonte Carlo π · Pythonlive app · case studyOpen Monte Carlo π · Python app (opens in a new tab)live appBrick Breakerlive app · case studyOpen Brick Breaker app (opens in a new tab)live appArcane Keeplive app · case studyOpen Arcane Keep app (opens in a new tab)live appe-Mobility Rentaldesktop app · case studyCountdownlive app · case studyOpen Countdown app (opens in a new tab)live appANOVAdesktop app · case studyEcho Playerdesktop app · case studyMonte Carlo πdesktop app · case studyexcuse.exelive app · case studyOpen excuse.exe app (opens in a new tab)live appYamb Tablelive app · case studyOpen Yamb Table app (opens in a new tab)live appSedmicalive app · case studyOpen Sedmica app (opens in a new tab)live appLora Score Tablelive app · case studyOpen Lora Score Table app (opens in a new tab)live appSnake (Blavor)desktop app · case study
Copy emailpero.grubac00@gmail.com