How team-youtrust/sample-webapp works
The project is a Rails sample application for YOUTRUST’s career-focused social networking service. It is organized following a clear domain separation where each layer has a precise responsibility, and it makes extensive use of the Command, UseCase, and Query patterns for clarity and modularity. The application exposes primarily API endpoints, with controllers acting as a thin layer that delegates to application logic (UseCases) and read functionalities (Queries), while writes are handled via Commands. Additionally, the notification system is managed through a dedicated NotificationJob and Notification classes.
Main Components
• Web/API Layer – Represented by the “Controller” layer (app/controllers) that handles incoming HTTP requests, decrypts/encrypts IDs, and calls higher-level services.
• Application/Business Logic Layer – This contains:
• UseCases (app/use_cases) for coordinating operations (invoked from controllers).
• Commands (app/commands) that execute specific update operations on models.
• Queries (app/queries) that encapsulate fetching and filtering resources.
• Domain Layer – Including Models (app/models) defining business objects (User, FriendRequest, Notification, etc.) and domain-specific behaviors.
• Notification / Background Processing – NotificationJob (app/jobs) and Notification classes (app/models/notification) which encapsulate asynchronous notification dispatching and business rules for various notification types.
• Assets and Frontend – Though primarily an API service, the project includes assets (app/assets, app/javascript) and public static files.
• Infrastructure & Operations – Docker configurations (docker-compose.yml and files under the .docker directory), environment and config files (config/*), and testing directories (spec/) that ensure deployment and CI/CD aspects are visible.
Relationships and Interactions
• The API layer (Controllers) receives HTTP requests and forwards them to appropriate UseCases.
• Each UseCase coordinates business logic by calling the relevant Command for write operations or Query for read operations.
• Commands operate on Models and encapsulate domain updates while also triggering NotificationJobs to handle asynchronous notification logic.
• Queries fetch filtered and sorted IDs in line with the scalable listing approach, then use those IDs to load the full resource details.
• The Notification system works asynchronously, where NotificationJob invokes Notification classes which then perform operations like sending emails or push notifications.
• Integration with Docker for both local development and production-like environments should be noted.
Architectural Patterns / Design Principles
• Layered Architecture – Separation between controllers (HTTP interface), use cases (application services), and domain (models and business logic).
• Command Pattern – Commands encapsulate operation-specific logic and validations.
• Query Object Pattern – Queries centralize complex retrieval/filtering logic.
• Asynchronous Processing – Use of background jobs (NotificationJob) to decouple time-intensive or external processing.
• API design for listing resources using two-step (IDs first, then resource details) technique.
Relevant Technologies / Frameworks
• Ruby on Rails is the primary framework.
• Docker & docker-compose for containerized development and deployment.
• RSpec for testing (as shown in the “spec” directory).
• Webpack, Babel, and PostCSS in the JavaScript/asset pipeline.
• ActiveJob for background processing.