# hatttri/stock_app architecture

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

- Interactive diagram: https://gitdiagram.com/hatttri/stock_app
- Repository: https://github.com/hatttri/stock_app

## Overview

##### Main Components
- Web Client: Represent the web browser or client-side interface (HTML/JavaScript/CSS) that interacts with the Rails application. Since assets are managed under app/assets and app/javascript, show a clear “Browser” component.
- Rails Application Server: This is the core of your application. Split this into subcomponents such as:
- Controllers (defined in app/controllers): Handle HTTP requests, manage sessions (sessions_controller.rb), portfolios (portfolios_controller.rb), stocks (stocks_controller.rb), and users (users_controller.rb).
- Models (found in app/models): Represent the application’s business logic (User, Stock, Portfolio, Wallet, Alert). These interact with the database.
- Views (located in app/views): Present data to the user using Slim templates.
- Channels (found in app/channels): Indicate use of Rails Action Cable for real-time features (like live updates) if needed.
- Jobs/Mailers: For background processing and mailing (user_mailer, application_job), which might cover delayed operations such as notifications.
- Database: Represent the relational database (most likely PostgreSQL in a Heroku deployment) that stores user data, stock information, portfolios, alerts, etc.
- External Services:
- Twitter Search API: Used for fetching market data or sentiments.
- SendGrid: For emailing, such as user activation emails or alerts.
- Deployment Environment: Heroku for hosting the application.
- Testing Environment: RSpec, which is configured for unit, model, and system tests.

- Directional flows:
- Browser requests → Rails server (via controllers).
- Controllers interact with Models for data.
- Models read/write from/to the Database.
- Rails jobs/mailer components interact with External Services (SendGrid for emails).

##### Architectural Patterns & Design Principles
- MVC (Model-View-Controller): This pattern is central to the project, with a clear separation of concerns between controllers (request handling), models (business logic & data), and views (presentation).
- RESTful Routing: As implied by the controllers and routes configuration, data flows are organized following REST principles.
- Background Processing: Inclusion of jobs and mailers signifies asynchronous processing handling actions such as portfolio updates or sending activation emails.
- External Integrations: Make sure to show the integration with third-party services (Twitter and SendGrid).

## Diagram (Mermaid)

```mermaid
flowchart TD

    %% Presentation Layer
    subgraph "Presentation Layer"
        A["Web Client (Browser)"]:::client
    end

    %% Application Layer
    subgraph "Application Layer"
        B["Rails Controllers: Sessions, Users, Stocks, Portfolios, AccountActivations, Alerts"]:::controller
        C["Rails Models: User, Stock, Portfolio, Wallet, Alert, Tweet"]:::model
        D["Rails Views (Slim templates)"]:::view
        E["Action Cable Channels"]:::channel
        F["Background Jobs & Mailers"]:::job
    end

    %% Data & Testing Layer
    subgraph "Data & Testing Layer"
        G["Database (PostgreSQL)"]:::database
        H["Testing Environment (RSpec)"]:::test
    end

    %% External Services
    subgraph "External Services"
        I["Twitter Search API"]:::external
        J["SendGrid"]:::external
    end

    %% Deployment Environment
    K["Deployment: Heroku"]:::external

    %% Flow Connections
    A -->|"HTTP_Request"| B
    B -->|"process"| C
    C -->|"CRUD"| G
    B -->|"render"| D
    D -->|"response"| A
    A -->|"subscribe"| E
    E -->|"push_updates"| A
    B -->|"background_tasks"| F
    F -->|"notify"| J
    B -->|"twitter_api"| I
    I -->|"data"| B
    K -->|"hosts"| B

    %% Styles
    classDef client fill:#AED6F1,stroke:#2E86C1,stroke-width:2px;
    classDef controller fill:#A9DFBF,stroke:#27AE60,stroke-width:2px;
    classDef model fill:#F9E79F,stroke:#F1C40F,stroke-width:2px;
    classDef view fill:#F5B7B1,stroke:#E74C3C,stroke-width:2px;
    classDef channel fill:#D2B4DE,stroke:#8E44AD,stroke-width:2px;
    classDef job fill:#FAD7A0,stroke:#D35400,stroke-width:2px;
    classDef database fill:#D5F5E3,stroke:#28B463,stroke-width:2px;
    classDef external fill:#E8DAEF,stroke:#8E44AD,stroke-width:2px;
    classDef test fill:#D6EAF8,stroke:#3498DB,stroke-width:2px;

    %% Click Events
    click A "https://github.com/hatttri/stock_app/tree/master/app/assets"
    click B "https://github.com/hatttri/stock_app/tree/master/app/controllers"
    click C "https://github.com/hatttri/stock_app/tree/master/app/models"
    click D "https://github.com/hatttri/stock_app/tree/master/app/views"
    click E "https://github.com/hatttri/stock_app/tree/master/app/channels"
    click F "https://github.com/hatttri/stock_app/tree/master/app/jobs"
    click G "https://github.com/hatttri/stock_app/tree/master/db"
    click H "https://github.com/hatttri/stock_app/tree/master/spec"
```
