How bellps/slonito works
Project Type and Purpose
• This is a full-stack Ruby on Rails 7 application (“Slonito”) that provides a real-time chat interface backed by an external AI service.
• Key features:
• User authentication and management via Devise
• Chat & message persistence (models: Chat, ChatMessage)
• Real-time updates using ActionCable (WebSockets)
• Stimulus/Turbo front-end for dynamic interactions
• Service objects for AI integration (SlonitoApiService) and SQL validation
Top-Level Architecture Overview
[Browser (Client)]
↕ HTTP/Turbo Frames
[Rails Web Server (Puma + Controllers + Views + Stimulus)]
↕ WebSocket (ActionCable)
[Background Workers (ActiveJob) & Services]
↕
[Persistent Storage & External Services]
Main Components
a. Client Layer
• Browser UI with Rails-generated HTML, Turbo Frames, Stimulus controllers (chat_controller.js, message_input_controller.js, etc.), Tailwind CSS.
• Components folder: custom view components for chat UI (chat_button_component, message_component, etc.).
b. Web Server Layer
• Rails MVC:
• Controllers (ChatsController, ChatsMessagesController, MainController)
• Views (.html.erb, .html+turbo_frame.erb)
• Models (User, Chat, ChatMessage)
• Middleware & Rack: config.ru, Puma server.
• Authentication: Devise initializers, controllers, and mailers.
c. Real-Time Layer
• ActionCable channels (app/channels/application_cable/*)
• WebSocket connections for live chat updates.
d. Service & Worker Layer
• Service Objects:
• SlonitoApiService → wraps calls to the external AI provider.
• SqlValidationService → validates user-supplied SQL.
• ActiveJob (app/jobs) for asynchronous tasks (e.g., mailers, long-running API calls).
e. Data Layer
• PostgreSQL (via config/database.yml) for users, chats, messages.
• ActiveStorage (config/storage.yml) for attachments (if used).
• Redis (commonly used for ActionCable pub/sub—mention if configured).
f. External Services
• AI provider (OpenAI or similar) called by SlonitoApiService.
• SMTP/Mail service for Devise mailers.
• Potential caching layer (Redis) if present in production.
Component Interactions & Data Flow
1. User logs in (Devise) → HTTP POST → SessionsController → Database → Devise mailer (if required).
2. User opens chat UI → HTTP GET → Rails renders view with Turbo Frames + Stimulus controllers.
3. User sends a message →
• Frontend Stimulus controller triggers POST to ChatsMessagesController
• Controller persists ChatMessage
• Broadcast via ActionCable to subscribed clients
• Background job invokes SlonitoApiService → external AI call → returns response → persisted as ChatMessage → broadcast back to client
4. SQL code submission (if feature used) → SqlValidationService validates → result returned in real-time.
Architectural Patterns & Design Principles
• MVC (Model-View-Controller) at core.
• Component-based views (Rails ViewComponent pattern).
• Service Objects for external integrations & business logic.
• Hotwire (Turbo + Stimulus) for minimal-JS interactivity.
• Asynchronous processing via ActiveJob.
• Real-time via ActionCable (pub/sub).
Capturing Essential Details
• Don’t omit: authentication flow (Devise), real-time channel, AI service integration, database writes/reads, and background processing.
• Configurable components: Docker container, environment variables (.env.example), credentials (config/credentials.yml.enc).