# guilhermeguerraf/time-to-answer architecture

> Architecture diagram of the GitHub repository guilhermeguerraf/time-to-answer, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2025-05-30). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/guilhermeguerraf/time-to-answer
- Repository: https://github.com/guilhermeguerraf/time-to-answer

## Overview

##### Project type and purpose
- This is a full-stack Ruby on Rails web application (“Time to Answer”), a Q&A site with three user roles—public visitors, registered users, and administrators—and features such as authentication (Devise), search (Searchkick + ElasticSearch), pagination (Kaminari), PDF generation (Prawn), internationalization, and WYSIWYG editing (Trix).

##### File structure
- Top-level Rails structure:
- app/controllers → MVC controllers, split into three namespaces: site (public), users_backoffice, admins_backoffice
- app/models → domain models (Question, Answer, Subject, User/UserProfile/UserStatistic, Admin/AdminStatistic, Favorite, Cep)
- app/views → ERB templates, organized per namespace
- app/assets & lib/assets → front-end assets (CoffeeScript/JS, SCSS/CSS)
- config → Rails configuration, routes, initializers
- db → migrations, schema, seeds
- bin, vendor, public, storage, tmp, test → supporting files
- Architectural patterns: traditional Rails MVC, RESTful controllers, namespaced backoffice areas, asset pipeline, background jobs (app/jobs), ActionCable channels (real-time features), ActiveStorage for file handling.

##### README for additional insights
- Confirms use of SQLite3 (dev/test), ElasticSearch for search, Devise for user and admin authentication, Prawn for PDF export.
- No built-in API layer beyond standard Rails controllers (server-rendered views).

##### Elements
- Clear labels:
- “Browser (Public/User/Admin)”
- “Puma Web Server / Rails App”
- “Controllers (site, users_backoffice, admins_backoffice, ActionCable)”
- “Models / ActiveRecord”
- “Views / ERB + Asset Pipeline”
- “SQLite3 Database”
- “ElasticSearch Cluster”
- “SMTP Mail Server”
- “Storage Service (ActiveStorage)”
- HTTP request/response
- DB queries
- Search queries
- Email deliveries
- WebSocket messages
- Rectangles for application components
- Clouds for external services

##### Final advice
- Be exhaustive: break the Rails app into MVC, background jobs, channels, and asset pipeline.
- Every major integration (ElasticSearch, Mailer, ActiveStorage).
- Don’t overthink: more components (namespaces, gems, services) give a clearer view of responsibilities.

## Diagram (Mermaid)

```mermaid
flowchart TD
    %% Clients
    subgraph "Clients" 
        direction TB
        Browser["Browser (Public/User/Admin)"]:::frontend
    end

    %% Web Server and App
    subgraph "Puma Web Server / Rails App" 
        direction TB
        Routes["Routes (config/routes.rb)"]:::backend
        Controllers["Controllers"]:::backend
        Models["Models / ActiveRecord"]:::backend
        Views["Views / ERB + Asset Pipeline"]:::backend
        Jobs["Background Jobs (ActiveJob)"]:::backend
        Channels["ActionCable Channels"]:::backend
        Mailers["Mailers"]:::backend
        StorageCfg["ActiveStorage"]:::backend
    end

    %% Controllers namespace
    subgraph "Controllers" 
        direction TB
        SiteCtrl["Site Controllers"]:::backend
        UsersBackCtrl["Users Backoffice Controllers"]:::backend
        AdminsBackCtrl["Admins Backoffice Controllers"]:::backend
        ActionCableCtrl["ActionCable Connection & Channels"]:::backend
    end

    %% Views namespace
    subgraph "Views" 
        direction TB
        SiteViews["Site Views"]:::backend
        UsersBackViews["Users Backoffice Views"]:::backend
        AdminsBackViews["Admins Backoffice Views"]:::backend
        DeviseUserViews["Devise Views (Users)"]:::backend
        DeviseAdminViews["Devise Views (Admins)"]:::backend
        KaminariViews["Pagination Views (Kaminari)"]:::backend
        PDFViews["PDF Templates (Prawn)"]:::backend
    end

    %% Asset Pipeline
    subgraph "Asset Pipeline" 
        direction TB
        JS["JavaScript (app/assets/javascripts/)"]:::frontend
        CSS["Stylesheets (app/assets/stylesheets/)"]:::frontend
    end

    %% Data Layer
    subgraph "Data Layer"
        direction TB
        DB["SQLite3 Database"]:::data
        ES["ElasticSearch Cluster"]:::data
        Storage["Storage Service (ActiveStorage)"]:::data
    end

    %% External Services
    subgraph "External Services"
        direction TB
        SMTP["SMTP Mail Server"]:::external
        Redis["Redis (caching/pubsub)"]:::external
    end

    %% Connections
    Browser -->|"HTTP/HTTPS"| Routes
    Routes --> Controllers
    Controllers --> Models
    Models --> DB
    Controllers --> Views
    Views --> Browser
    Controllers -->|"search queries"| ES
    Controllers -->|"file uploads/downloads"| Storage
    Controllers --> Jobs
    Jobs --> Mailers
    Mailers --> SMTP
    Browser -->|"WebSocket"| ActionCableCtrl
    ActionCableCtrl --> Controllers
    Controllers --> Redis

    %% Internal dependencies
    Controllers --> Routes
    Views --> AssetPipeline
    AssetPipeline --> Browser

    %% Click Events
    click SiteCtrl "https://github.com/guilhermeguerraf/time-to-answer/tree/main/app/controllers/site/"
    click UsersBackCtrl "https://github.com/guilhermeguerraf/time-to-answer/tree/main/app/controllers/users_backoffice/"
    click AdminsBackCtrl "https://github.com/guilhermeguerraf/time-to-answer/tree/main/app/controllers/admins_backoffice/"
    click ActionCableCtrl "https://github.com/guilhermeguerraf/time-to-answer/tree/main/app/channels/application_cable/"
    click Models "https://github.com/guilhermeguerraf/time-to-answer/tree/main/app/models/"
    click SiteViews "https://github.com/guilhermeguerraf/time-to-answer/tree/main/app/views/site/"
    click UsersBackViews "https://github.com/guilhermeguerraf/time-to-answer/tree/main/app/views/users_backoffice/"
    click AdminsBackViews "https://github.com/guilhermeguerraf/time-to-answer/tree/main/app/views/admins_backoffice/"
    click DeviseUserViews "https://github.com/guilhermeguerraf/time-to-answer/tree/main/app/views/users/"
    click DeviseAdminViews "https://github.com/guilhermeguerraf/time-to-answer/tree/main/app/views/admins/"
    click JS "https://github.com/guilhermeguerraf/time-to-answer/tree/main/app/assets/javascripts/"
    click CSS "https://github.com/guilhermeguerraf/time-to-answer/tree/main/app/assets/stylesheets/"
    click Routes "https://github.com/guilhermeguerraf/time-to-answer/blob/main/config/routes.rb"
    click Jobs "https://github.com/guilhermeguerraf/time-to-answer/blob/main/app/jobs/application_job.rb"
    click Mailers "https://github.com/guilhermeguerraf/time-to-answer/blob/main/app/mailers/application_mailer.rb"
    click PDFViews "https://github.com/guilhermeguerraf/time-to-answer/blob/main/app/views/admins_backoffice/subjects/index.pdf.prawn"
    click StorageCfg "https://github.com/guilhermeguerraf/time-to-answer/blob/main/config/storage.yml"

    %% Styles
    classDef frontend fill:#FFDDAA,stroke:#FFAA44,color:#333
    classDef backend fill:#DDEEFF,stroke:#66Aaff,color:#333
    classDef data fill:#CCFFCC,stroke:#44AA44,color:#333
    classDef external fill:#FFCCCC,stroke:#FF4444,color:#333
```
