-
Notifications
You must be signed in to change notification settings - Fork 0
System Architecture
This page provides an overview of the StateForce system's architecture, its main components, and how they interact. The architecture is designed for reliability, scalability, and real-time emergency coordination across distributed agencies.
StateForce is a web-based platform used by government agencies to manage emergency incidents, resources, and operational communication in real time.
- Built as a modular monolith using Ruby on Rails.
- Real-time updates using Hotwire (Turbo + Stimulus).
- Designed for mobile-first field operations and centralized supervision.
- Follows domain-driven design principles for maintainability.
-
Framework: Rails 8 with API and HTML rendering.
-
Key Responsibilities:
- Business logic
- Role-based access control
- Resource allocation
- Incident tracking
- Audit logging
-
Main Services:
-
IncidentManagerβ Handles creation and updates of emergency incidents. -
ResourceDispatcherβ Assigns units based on availability and proximity. -
NotificationServiceβ Sends real-time updates via Turbo or external channels.
-
-
Relational DB with normalized structure.
-
Core entities:
-
users,roles,units,incidents,hospitals,reports,messages
-
For more info visit Database Wiki
- Built with server-rendered views and enhanced with Turbo and Stimulus.
- Responsive design using TailwindCSS utility classes.
- Turbo Streams provide real-time UI updates without needing WebSockets manually.
- Stimulus controllers modularize behavior (filters, modals, maps, etc.).
-
Handles background jobs (email delivery, report generation, geolocation processing).
-
Redis acts as the queue broker.
-
Jobs are retried automatically on failure.
-
Examples:
NotifySupervisorJobGenerateIncidentPDFJobSyncHospitalDataJob
-
Authentication: Devise (email/password), with support for Google OAuth2 via OmniAuth.
-
Authorization:
-
Punditfor policy-based access. - Centralized
Rolemodel defining system access.
-
-
Email confirmation required before accessing protected routes.
-
Session timeout and auto-logout enforced for security.
-
APIs:
- Emergency hospitals dataset via ArcGIS REST API (read-only).
- [Planned] Weather or alert systems via civil protection APIs.
-
OAuth2:
- Google SSO for government accounts.
-
Webhooks:
- Future support for outgoing event hooks to agency dashboards.
sequenceDiagram
participant User
participant UI
participant Rails API
participant DB
participant Sidekiq
User->>UI: Report Incident
UI->>Rails API: POST /incidents
Rails API->>DB: Create record
Rails API->>Sidekiq: Trigger ResourceAssignmentJob
Sidekiq->>DB: Update unit status
Rails API->>UI: Turbo Stream - Update Incident Feed
sequenceDiagram
participant User
participant Devise
participant DB
participant Pundit
User->>Devise: Login (email + password)
Devise->>DB: Authenticate
Devise->>Pundit: Check user role
Pundit->>UI: Allow/deny access
-
App Server: Puma (multi-threaded Rails server)
-
Background Jobs: Sidekiq workers managed via systemd or Procfile
-
Redis: In-memory job queue and pub/sub
-
PostgreSQL: Main relational DB
-
Cloudinary CDN: For assets and pre-rendered documents
-
Environments:
-
productionβ live system -
stagingβ internal QA and tests -
developmentβ local machine with seeded data
-
- HTTPS enforced on all environments.
-
Encrypted credentials using
config/credentials.yml.enc. - Audit Logs for sensitive actions (login, role changes, resource reassignment).
- Rate limiting and CSRF protection enabled.
- Content Security Policy (CSP) headers configured.
Need to propose changes to architecture? Please submit a PR or init a discussion.
We are always looking for feedback and contributions to improve StateForce. Feel free to open issues, suggest edits, or submit pull requests to the repository.
- Repo: StateForce GitHub
- Contact: martinmendozadev@gmail.com
If you encounter issues or need assistance, please reach out via:
- Email: martinmendozadev@gmail.com
- GitHub Issues: Submit an Issue
This documentation and the StateForce platform are licensed under the Apache License 2.0.
Thank you for using StateForce! π¨
Together, we are improving emergency response operations in real-time.
Welcome to the StateForce Wiki! Use this sidebar to navigate through the documentation.
This sidebar provides quick access to all the documentation pages. For detailed information, click on the desired section.