# team-youtrust/sample-webapp architecture

> Architecture diagram of the GitHub repository team-youtrust/sample-webapp, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2025-03-29). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/team-youtrust/sample-webapp
- Repository: https://github.com/team-youtrust/sample-webapp

## Overview

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.

## Diagram (Mermaid)

```mermaid
flowchart TD
    %% Web/API Layer
    subgraph "Web/API Layer"
        CONTROLLERS["Controllers (app/controllers)"]
    end

    %% Application/Business Logic Layer
    subgraph "Application/Business Logic"
        USECASES["UseCases (app/use_cases)"]
        COMMANDS["Commands (app/commands)"]
        QUERIES["Queries (app/queries)"]
    end

    %% Domain Layer
    subgraph "Domain Layer"
        MODELS["Models (app/models)"]
    end

    %% Notification System
    subgraph "Notification System"
        NOTIF_JOB["NotificationJob (app/jobs/notification_job.rb)"]
        NOTIF_HANDLERS["Notification Handlers (app/models/notification)"]
    end

    %% Assets & Frontend
    subgraph "Assets & Frontend"
        ASSETS["Assets (app/assets)"]
        JAVASCRIPT["JavaScript (app/javascript)"]
    end

    %% Infrastructure & Operations
    subgraph "Infrastructure & Operations"
        DOCKER_COMPOSE["Docker Compose (docker-compose.yml)"]
        DOCKER_DIR["Docker Directory (.docker/)"]
        CONFIG["Configuration (config)"]
        TESTING["Testing (spec)"]
    end

    %% Main Flow Connections
    CONTROLLERS -->|"calls"| USECASES
    USECASES -->|"invokes"| COMMANDS
    USECASES -->|"queries"| QUERIES
    COMMANDS -->|"updates"| MODELS
    QUERIES -->|"fetches"| MODELS
    USECASES -->|"triggers"| NOTIF_JOB
    NOTIF_JOB -->|"executes"| NOTIF_HANDLERS

    %% Click Events
    click CONTROLLERS "https://github.com/team-youtrust/sample-webapp/tree/main/app/controllers/api/"
    click USECASES "https://github.com/team-youtrust/sample-webapp/tree/main/app/use_cases/"
    click COMMANDS "https://github.com/team-youtrust/sample-webapp/tree/main/app/commands/"
    click QUERIES "https://github.com/team-youtrust/sample-webapp/blob/main/app/queries/receiving_friend_requests_query.rb"
    click MODELS "https://github.com/team-youtrust/sample-webapp/blob/main/app/models/user.rb"
    click NOTIF_JOB "https://github.com/team-youtrust/sample-webapp/blob/main/app/jobs/notification_job.rb"
    click NOTIF_HANDLERS "https://github.com/team-youtrust/sample-webapp/blob/main/app/models/notification/accept_friend_request.rb"
    click ASSETS "https://github.com/team-youtrust/sample-webapp/tree/main/app/assets/"
    click JAVASCRIPT "https://github.com/team-youtrust/sample-webapp/tree/main/app/javascript/"
    click DOCKER_COMPOSE "https://github.com/team-youtrust/sample-webapp/blob/main/docker-compose.yml"
    click DOCKER_DIR "https://github.com/team-youtrust/sample-webapp/tree/main/.docker/"
    click CONFIG "https://github.com/team-youtrust/sample-webapp/tree/main/config/"
    click TESTING "https://github.com/team-youtrust/sample-webapp/tree/main/spec/"

    %% Styles
    class CONTROLLERS controller;
    class USECASES,COMMANDS,QUERIES usecase;
    class MODELS domain;
    class NOTIF_JOB,NOTIF_HANDLERS async;
    class ASSETS,JAVASCRIPT assets;
    class DOCKER_COMPOSE,DOCKER_DIR,CONFIG,TESTING infra;

    classDef controller fill:#f9d6a5,stroke:#333,stroke-width:2px;
    classDef usecase fill:#b5d9f7,stroke:#333,stroke-width:2px;
    classDef domain fill:#abe9af,stroke:#333,stroke-width:2px;
    classDef async fill:#ffd1dc,stroke:#333,stroke-width:2px;
    classDef assets fill:#d1c4e9,stroke:#333,stroke-width:2px;
    classDef infra fill:#c1d6e2,stroke:#333,stroke-width:2px;
```
