# andrewsheelan/windsurfing architecture

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

- Interactive diagram: https://gitdiagram.com/andrewsheelan/windsurfing
- Repository: https://github.com/andrewsheelan/windsurfing

## Overview

##### Main Components
- Frontend Client:
- Web browser interfaces showing responsive views.
- Interaction layers powered by Tailwind CSS, Stimulus, Turbo, and JavaScript modules that drive interactive behavior (e.g., chat window, product browsing, and cart updates).

- Rails Web Application:
- Controllers: Represent endpoints handling product management (ProductsController), shopping cart operations (CartsController and CartItemsController), orders (OrdersController), and real-time messaging (MessagesController, ChatChannel).
- Views: Mark the presentation layer that renders pages based on ERB templates (e.g., layouts, product views, cart views, chat partials).
- Channels: Highlight Action Cable components for real-time features, including ChatChannel and connection handling in ApplicationCable.
- Jobs & Background Processing: Include jobs (ProcessWithProgressJob) that manage asynchronous actions.

- Database and Storage:
- PostgreSQL (or SQLite as mentioned in the README for development).
- Active Storage for image uploads.
- Redis for Action Cable that supports real-time messaging.

- External Services and Integration Points:
- Devise for authentication, indicating secure user registration and role-based access.
- External APIs or services such as the Ollama service (found in app/services/ollama_service.rb) should be noted.
- CI/CD Integration: Although not the focus of the core architecture, the CI pipeline ensures code quality (RuboCop, tests, Dockerfile setup). You might annotate these components as part of the deployment/support infrastructure.

- Infrastructure & DevOps:
- Dockerfiles (multiple variants), docker-compose, and deployment configuration files (e.g., Procfile.dev, config/deploy.yml) should be captured as deployment artifacts.
- Dedicated directories for GitHub workflows and hooks that automate build, test, and deployment processes.

##### Relationships and Data Flows
- User Flow:
- Clients (web browsers) interact with the Rails application through HTTP requests that are routed to the appropriate controllers.
- Data Persistence:
- Attachments from models to Active Storage.
- Real-time Features:
- Background Processes:
- Asynchronous job queues that process long-running tasks (for example, order confirmations or stock validations).

##### Architectural Patterns and Principles
- MVC Pattern: Clearly segment the application into Model, View, and Controller components.
- Componentization: Break out distinct functions (product management, cart management, orders, chat) as separable modules within the architecture.
- Integration via Services: Represent the app/services directory (e.g., OllamaService) as integration points for external interactions.
- Real-Time Processing: Emphasize the use of Action Cable (channels and connection components) in the system to handle live communication.
- Modular and Layered Approach: Separate concerns such as business logic (models/services), presentation (views), and user interaction (controllers and channels).
- Deployment & DevOps: Optionally include Docker/CI/CD elements to indicate how the code is deployed and scaled.

## Diagram (Mermaid)

```mermaid
flowchart TD
    %% Frontend Client
    subgraph "Frontend Client (Tailwind/Stimulus/Turbo)"
        FB["Web Browser (Client)"]:::frontend
        TWC["Tailwind CSS"]:::frontend
        JSC["JavaScript Controllers"]:::frontend
        CS["Chat Stylesheet"]:::frontend
    end

    %% Rails Web Application
    subgraph "Rails Web Application"
        subgraph "Controllers"
            PC["ProductsController"]:::controller
            CC["CartsController"]:::controller
            CIC["CartItemsController"]:::controller
            OC["OrdersController"]:::controller
            MC["MessagesController"]:::controller
        end
        subgraph "Models"
            P["Product"]:::model
            C["Cart"]:::model
            CI["CartItem"]:::model
            O["Order"]:::model
            OI["OrderItem"]:::model
            M["Message"]:::model
            U["User"]:::model
        end
        subgraph "Views"
            V["ERB Templates (Products,Carts,Orders,Messages,Shared)"]:::view
        end
        subgraph "Real-Time Features"
            CH["ChatChannel"]:::channel
            AC["ApplicationCable"]:::channel
        end
        subgraph "Background Jobs_&_Services"
            BP["ProcessWithProgressJob"]:::job
            OS["Ollama Service"]:::service
            DA["Devise Integration"]:::service
        end
    end

    %% Database and Storage
    subgraph "Database_&_Storage"
        DB["Database (PostgreSQL/SQLite)"]:::database
        AS["Active Storage"]:::storage
    end

    %% Real-Time Infrastructure
    subgraph "Real-Time Infrastructure"
        RD["Redis (Action Cable)"]:::redis
    end

    %% CI/CD & DevOps
    subgraph "CI/CD_&_DevOps"
        CIP["CI Pipeline"]:::ci
        DK["Docker_&_Deployment"]:::ci
        KH["Kamal Hooks"]:::ci
    end

    %% Connections: Client interactions with Rails Application
    FB -->|"HTTP_Request"| PC
    FB -->|"HTTP_Request"| CC
    FB -->|"HTTP_Request"| CIC
    FB -->|"HTTP_Request"| OC
    FB -->|"HTTP_Request"| MC

    %% Controllers render views (example from ProductsController)
    PC -->|"render_view"| V
    V -->|"HTML_Response"| FB

    %% Controllers interact with Models
    PC -->|"CRUD"| P
    CC -->|"CRUD"| C
    CIC -->|"CRUD"| CI
    OC -->|"CRUD"| O
    MC -->|"CRUD"| M

    %% Models persistence to Database
    P -->|"persist"| DB
    C -->|"persist"| DB
    CI -->|"persist"| DB
    O -->|"persist"| DB
    OI -->|"persist"| DB
    M -->|"persist"| DB
    U -->|"persist"| DB

    %% Models using Active Storage (example: Product images)
    P -->|"store_images"| AS

    %% Real-Time flow for Chat
    FB -->|"WebSocket"| CH
    CH -->|"publish_subscribe"| RD
    AC -->|"connection"| RD

    %% Asynchronous Background Job invocation (example from OrdersController)
    OC -->|"async_job"| BP

    %% External Service call from MessagesController
    MC -->|"external_API"| OS

    %% Authentication flow using Devise Integration
    U -->|"auth"| DA

    %% CI/CD & DevOps interactions (deployment pipeline)
    DK -->|"deploys"| DB
    CIP -->|"triggers"| DK
    KH -->|"hooks"| DK

    %% Click Events for Frontend Client
    click TWC "https://github.com/andrewsheelan/windsurfing/blob/main/app/assets/stylesheets/application.tailwind.css"
    click JSC "https://github.com/andrewsheelan/windsurfing/tree/main/app/javascript/controllers"
    click CS "https://github.com/andrewsheelan/windsurfing/blob/main/app/assets/stylesheets/chat.css"

    %% Click Events for Rails Controllers
    click PC "https://github.com/andrewsheelan/windsurfing/blob/main/app/controllers/products_controller.rb"
    click CC "https://github.com/andrewsheelan/windsurfing/blob/main/app/controllers/carts_controller.rb"
    click CIC "https://github.com/andrewsheelan/windsurfing/blob/main/app/controllers/cart_items_controller.rb"
    click OC "https://github.com/andrewsheelan/windsurfing/blob/main/app/controllers/orders_controller.rb"
    click MC "https://github.com/andrewsheelan/windsurfing/blob/main/app/controllers/messages_controller.rb"

    %% Click Events for Rails Models
    click P "https://github.com/andrewsheelan/windsurfing/blob/main/app/models/product.rb"
    click C "https://github.com/andrewsheelan/windsurfing/blob/main/app/models/cart.rb"
    click CI "https://github.com/andrewsheelan/windsurfing/blob/main/app/models/cart_item.rb"
    click O "https://github.com/andrewsheelan/windsurfing/blob/main/app/models/order.rb"
    click OI "https://github.com/andrewsheelan/windsurfing/blob/main/app/models/order_item.rb"
    click M "https://github.com/andrewsheelan/windsurfing/blob/main/app/models/message.rb"
    click U "https://github.com/andrewsheelan/windsurfing/blob/main/app/models/user.rb"

    %% Click Event for Views
    click V "https://github.com/andrewsheelan/windsurfing/tree/main/app/views/products"

    %% Click Events for Real-Time Features
    click CH "https://github.com/andrewsheelan/windsurfing/blob/main/app/channels/chat_channel.rb"
    click AC "https://github.com/andrewsheelan/windsurfing/tree/main/app/channels/application_cable"

    %% Click Events for Background Jobs and Services
    click BP "https://github.com/andrewsheelan/windsurfing/blob/main/app/jobs/process_with_progress_job.rb"
    click OS "https://github.com/andrewsheelan/windsurfing/blob/main/app/services/ollama_service.rb"
    click DA "https://github.com/andrewsheelan/windsurfing/blob/main/config/initializers/devise.rb"

    %% Click Events for Database and Storage
    click DB "https://github.com/andrewsheelan/windsurfing/blob/main/config/database.yml"
    click AS "https://github.com/andrewsheelan/windsurfing/blob/main/config/storage.yml"

    %% Click Events for CI/CD & DevOps
    click CIP "https://github.com/andrewsheelan/windsurfing/blob/main/.github/workflows/ci.yml"
    click DK "https://github.com/andrewsheelan/windsurfing/tree/main/Dockerfile"
    click KH "https://github.com/andrewsheelan/windsurfing/tree/main/.kamal/hooks"

    %% Styles
    classDef frontend fill:#ace7ef,stroke:#045d8c,stroke-width:2px;
    classDef controller fill:#ffb3b3,stroke:#a60000,stroke-width:2px;
    classDef model fill:#c2f0c2,stroke:#007a00,stroke-width:2px;
    classDef view fill:#fff2a8,stroke:#b39b00,stroke-width:2px;
    classDef channel fill:#ffd699,stroke:#e68a00,stroke-width:2px;
    classDef job fill:#e6e6fa,stroke:#4b0082,stroke-width:2px;
    classDef service fill:#fff0b3,stroke:#b38f00,stroke-width:2px;
    classDef database fill:#f4cccc,stroke:#b22222,stroke-width:2px;
    classDef storage fill:#fce5cd,stroke:#d2691e,stroke-width:2px;
    classDef redis fill:#d9ead3,stroke:#008000,stroke-width:2px;
    classDef ci fill:#d0e0e3,stroke:#4682b4,stroke-width:2px;
```
