How tomlobato/riff works
• API Gateway / Request Routing: Represent the Roda application (sample_app/app.rb and its route definitions). This component directs incoming HTTP requests to the corresponding routes (e.g., session handling and actions).
• Riff Core Engine: This is encapsulated in the lib/riff directory and includes:
• Action Handlers: Modules under lib/riff/actions (with sub-files for create, delete, update, show, etc.) which manage the core CRUD and custom actions.
• Authentication & Authorization: Components under lib/riff/auth and lib/riff/authorize that contain different auth methods (default, request, signin) and token management (e.g., token creation, validation, and update).
• Request Processing Pipeline: Under lib/riff/request there are modules and classes that build the request chain, context, validation, response composition, and error handling (including chain, context, and validate components).
• Session Management: Represented under lib/riff/session handling open, close, and refresh operations.
• Utility, Configuration, and Constants: Modules such as lib/riff/conf, lib/riff/constants, and lib/riff/settings offer configuration management and shared utility methods.
• Additional Components:
• Swagger Documentation: Under lib/riff/swagger, which shows that the gem supports (or aims to support) API documentation.
• External Dependencies: Libraries such as Roda, Sequel, ActiveSupport, and dry-validation play a significant role in the functionality.
• Sample App Components: In sample_app/, include:
• API resources and routes – Organized in app/api, which include resources for company, post, user, etc.
• Models – Represented in sample_app/app/models.
• Bootstrapping and Environment – Present in sample_app/system (boot files for database, logging, redis, etc.) and configuration files.
• Testing – Presence of a well-defined test suite in spec/ and sample_app/spec to ensure full coverage.
Relationships and Interactions
• Data Flow: Start with HTTP requests entering via the Roda routing layer (r.post, r.on in app.rb), then transferring control to the Riff methods (handle_session, handle_action).
• Request Handling Pipeline: The request is passed on to the modules that:
• Validate and process parameters.
• Handle authorization and authentication (verifying tokens or credentials).
• Direct valid requests to appropriate action handlers (CRUD operations).
• Handle responses by building response bodies and managing errors.
• External Tools: Include external libraries (Roda, Sequel, dry-validation, Oj) as part of the environment that supports and integrates with the core functionalities.
Architectural Patterns/Design Principles
• Layered Architecture: Demonstrate separation of concerns (routing, processing, validation, authentication, and data access).
• Modular Design: Show how functionalities are grouped in logical directories (e.g., actions, auth, request, session) making the gem extensible and maintainable.
• Extensibility Points: Mark the areas where developers can override default behaviors (custom actions under Actions::<MODEL> and custom validations).
Detailed Steps for the Principal Software Engineer
• Create individual blocks for the following:
• API Gateway (Roda routes) that distributes requests.
• Riff Core Engine with sub-blocks: Action Handlers, Authentication & Authorization, Request Processing Pipeline, Session Handling, and Configuration.
• Sample App Implementation which demonstrates how Riff is integrated.
• Under “External Dependencies and Libraries”, list Roda, Sequel, ActiveSupport, dry-validation, Oj.
• Inbound request flow: User → API Gateway → Riff Core Engine → Database/Models → Response.
• Where customization occurs (e.g., custom actions under Actions::<MODEL>).