How rodrighons/notifier works
Project Type & Purpose
• This is a mountable Rails Engine (gem) designed to be plugged into any Rails application.
• Purpose: allow a host app to enqueue and process notifications via configurable channels (e.g. email).
• Key use‐case: host app calls Notifier::BirthNotification.send(:email,…), which creates and processes notifications in the background.
File‐Structure Analysis
Top‐level:
• bin/, config/, lib/, app/, db/: standard Rails engine layout.
• app/controllers/notifier, app/models/notifier, app/services/notifier, app/jobs/notifier, app/mailers/notifier: namespaced MVC + service + job layers.
• lib/notifier/engine.rb: defines the mountable engine.
• test/dummy/: a full Rails app used for development/testing only.
README Insights
• Confirms mountable engine, Rails ≥8, Ruby ≥3.4, PostgreSQL.
• Explains basic API (send notifications, query channels).
• Background jobs (ActiveJob) handle creation and delivery.
• External dependency: mail delivery (SMTP or 3rd-party).
Main Architectural Components
a. Host Rails Application
– Initiates notification requests via engine API.
– Mounts the engine’s routes (config/routes.rb inside engine).
b. Notifier Engine
– Controllers & Views: optional admin UI to manage channels/notifications.
– Models (Notifier::EmailChannel, Notifier::EmailNotification): store configuration & state.
– Services:
• NotificationProcessor (orchestrates channel lookup and enqueueing).
• EmailProcessor (handles delivery logic).
• Domain‐specific services (e.g. BirthNotification).
– Jobs:
• NotificationCreationJob: creates DB records and links to channels.
• NotificationDeliveryJob (if separate) or processed by EmailProcessor via ActiveJob.
– Mailers: Notifier::ApplicationMailer for templating and sending.
– Engine Mount: defined in lib/notifier/engine.rb to isolate namespace and assets.
c. Infrastructure
– Database (PostgreSQL): stores channels, notifications.
– Background Job Queue (e.g. Sidekiq, DelayedJob, or default ActiveJob adapter).
– External Mail Service (SMTP relay, SendGrid, etc.).
d. Development/Test Environment
– test/dummy Rails app: not in production, but useful to show “engine → host app” integration.
1. Host App → calls Notifier API → Rails Engine
2. Engine’s NotificationProcessor enqueues NotificationCreationJob → Job Queue
3. Worker picks up NotificationCreationJob → creates Notifier::EmailNotification record in DB
4. Engine’s EmailProcessor (another job or invoked after creation) → renders email via Notifier::ApplicationMailer → sends to External Mail Service
5. Status updates flow back into DB (e.g. “created”, “sent”, “failed”)
6. Admin UI (optional): browser ↔ Notifier controllers/views for channel & notification management
Architectural Patterns & Principles
• Mountable Engine pattern (isolated namespace, asset pipeline)
• MVC separation for UI management of channels/notifications
• Service objects for business logic (single responsibility)
• Background jobs for decoupling and scalability (ActiveJob)
• Domain layering: Controllers → Services → Jobs → Models → External services
• Configuration by convention: default channel, pluggable channels via AbstractChannel