How masutaka/trial-rails8 works
Project Type and Purpose
• This is a monolithic full-stack web application built with Ruby on Rails 8.
• It provides a blog platform (posts, comments, scheduling), social features (follows, notifications), product management (rich text descriptions, image uploads), real-time chat via WebSocket, and user authentication.
• It uses Hotwire (Turbo Drive, Turbo Frames, Turbo Streams, Stimulus), Active Job with Sidekiq, Active Storage, Action Text, and Action Cable (Solid Cable adapter).
Key Architectural Components
a. Clients
• Web browser (HTML views enhanced with Turbo & Stimulus).
b. Rails Application Server
• HTTP request routing (config/routes.rb) → Controllers → Models → Views.
• MVC pattern: app/controllers, app/models, app/views.
• Turbo Drive for navigation, Turbo Frames/Streams for partial updates, Stimulus controllers for frontend behavior.
c. Database
• MySQL (config/database.yml) storing users, posts, comments, follows, notifications, products.
• Polymorphic associations for notifications, self-referential for follows.
d. Background Jobs
• Active Job configured with Sidekiq (config/sidekiq.yml & initializer).
• Redis as Sidekiq backend.
• Jobs: scheduled post publication, email sending, notifications.
e. WebSockets
• Action Cable (Solid Cable adapter configured in config/cable.yml).
• ChatChannel for real-time messaging.
f. File Storage & Rich Text
• Active Storage for file uploads (product images) using local/disk service (config/storage.yml).
• Action Text for rich-text descriptions.
g. Email
• Action Mailer sending password reset and product in-stock emails.
h. Infrastructure & DevOps
• Docker/Docker Compose for MySQL and Redis containers.
• CI/CD pipelines (GitHub Actions).
• Kamal hooks for deployment.
• Sidekiq Web UI for job monitoring.
i. Caching & Monitoring
• Bullet gem for N+1 detection.
• Rails cache store (config/cache.yml).
Relationships and Data Flows
• Browser → (HTTP/Turbo Drive) → Rails Router → Controller → Model → DB → View → Browser.
• Browser → (Turbo Streams/WebSocket) → Action Cable → ChatChannel → Broadcast → Browser.
• Rails → (Active Job enqueued) → Redis queue → Sidekiq worker → perform job (e.g., publish_post_job) → DB changes or email dispatch.
• Controllers interact with models and enqueue jobs or broadcast streams.
• Active Storage uploads files to storage service; URLs served by Rails.
Architectural Patterns & Principles
• MVC to separate concerns.
• Self-referential association for follow graph.
• Polymorphic association for notification extensibility.
• Event-driven design via background jobs and WebSocket broadcasting.
• Hotwire approach to minimize custom JS and SPA complexity.
• Docker-based local development replicates production dependencies.