# s314/news-service architecture

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

- Interactive diagram: https://gitdiagram.com/s314/news-service
- Repository: https://github.com/s314/news-service

## Overview

##### Project type and purpose
- This is a full-stack web application built with Ruby on Rails that provides a news classifier interface.
- It includes a separate Julia “Bukdu” microservice that performs Bayesian classification on news content.

##### File structure
- Top-level “app/” directory follows Rails’ MVC pattern:
- app/controllers – Rails controllers handling HTTP requests
- app/models – ActiveRecord models for Users, Sources, Entries
- app/views & app/assets – HTML templates, CSS/SCSS, CoffeeScript
- app/channels – WebSocket channels (ActionCable)
- config/ – Rails routing, environment configs, cable.yml
- db/ – Migrations, schema, seeds
- “Bukdu/” directory contains Julia code:
- bukdu_server.jl – entry point for a classifier microservice
- bayes.jl, db_learning.jl – classification logic
- corpus/ – sample text files organized by category
- Rakefile, Gemfile, package.json, bin/rails, bin/yarn indicate standard Rails build and asset pipeline.

##### README for additional insights
- The README instructs launching the Julia classifier service first, then starting the Rails server.
- Rails interacts with the Julia service over HTTP (or TCP) to classify incoming news items.

##### Main components and their interactions
a. Components:
1) Browser / Client UI
2) Rails Web Server
– Controllers, Views, Assets, ActionCable
3) PostgreSQL (or configured SQL) Database
4) Julia “Bukdu” Classifier Service
5) (Optional) Redis for ActionCable / background jobs
b. Relationships & data flow:
- User → Rails (HTTP GET/POST)
- Rails Controllers → Models → Database (SQL)
- Rails Classifier endpoint → Julia Service (HTTP/TCP request)
- Julia Service loads corpus, computes category, returns JSON
- Rails renders classification result back to user
- Background jobs (app/jobs) or ActionCable push notifications flow through Redis or the Rails process.
c. Architectural patterns:
– MVC for Rails application
– Microservice pattern for offloading classification to Julia
– REST or lightweight RPC between Rails and Julia
– Asset pipeline for JS/CSS, optional WebSockets for live updates
d. Key technologies:
- Ruby on Rails (MVC, ActiveRecord, ActionCable)
- PostgreSQL (config/database.yml)
- Julia (HTTP.jl or Sockets.jl in bukdu_server.jl)
- SCSS, CoffeeScript, Yarn/Webpacker for front-end assets
- Puma web server, Rake tasks
- Gemfile-managed Ruby gems

##### Diagramming conventions
- UI / Browser – Blue
- Rails Web/App – Green
- Database – Orange
- Julia Service – Purple
- Cache / Message Broker – Yellow

## Diagram (Mermaid)

```mermaid
flowchart TB
    %% UI Layer
    subgraph "Browser / Client UI" 
        direction TB
        ViewsUI["Views"]:::ui
        JSUI["JavaScript Assets"]:::ui
        CSSUI["Stylesheets"]:::ui
    end

    %% Rails Server
    subgraph "Rails Web Server" 
        direction TB

        subgraph "Web Layer"
            direction TB
            Routing["Routing"]:::rails
            Controllers["Controllers"]:::rails
            ViewsWeb["Rails Views"]:::rails
            AssetsSub["Assets"]:::rails
            subgraph "Assets"
                direction TB
                JSRails["JS"]:::rails
                CSSRails["CSS"]:::rails
                Images["Images"]:::rails
            end
        end

        subgraph "App Layer"
            direction TB
            Models["Models"]:::rails
            Jobs["Background Jobs"]:::rails
            Mailers["Mailers"]:::rails
            subgraph "Configuration"
                direction TB
                DBConfig["DB Config & Migrations"]:::rails
                CableConfig["ActionCable Config"]:::rails
                OtherConfig["Other Config & Initializers"]:::rails
            end
        end
    end

    %% Datastores and Brokers
    subgraph "Datastores / Brokers"
        direction TB
        DB["PostgreSQL Database"]:::db
        Redis["Redis (Cache/Broker)"]:::cache
    end

    %% Julia Service
    subgraph "Julia “Bukdu” Classifier Service" 
        direction TB
        Server["bukdu_server.jl"]:::julia
        Bayes["bayes.jl"]:::julia
        DBLearn["db_learning.jl"]:::julia
        Corpus["corpus/"]:::julia
    end

    %% Connections
    ViewsUI -->|"GET /classify"| Routing
    JSUI --> Routing
    CSSUI --> Routing

    Routing -->|"routes requests"| Controllers
    Controllers -->|"render views"| ViewsWeb
    ViewsWeb -->|"HTML/CSS/JS"| ViewsUI

    Controllers -->|"calls Classification API (HTTP)"| Server
    Server -->|"JSON Response"| Controllers

    Controllers -->|"ActiveRecord SQL"| Models
    Models -->|"reads/writes"| DB

    Controllers -->|"enqueue jobs"| Jobs
    Jobs -.->|"async"| Redis
    Redis -.->|"push updates"| ViewsUI

    Controllers -->|"websocket"| CableConfig
    CableConfig -.->|"pub/sub"| Redis
    Redis -.->|"push updates"| ViewsUI

    %% Julia internals (no external arrows)
    Server --> Bayes
    Server --> DBLearn
    Server --> Corpus

    %% Click Events
    click ViewsUI "https://github.com/s314/news-service/tree/master/app/views/"
    click JSUI "https://github.com/s314/news-service/tree/master/app/assets/javascripts/"
    click CSSUI "https://github.com/s314/news-service/tree/master/app/assets/stylesheets/"
    click Routing "https://github.com/s314/news-service/blob/master/config/routes.rb"
    click Controllers "https://github.com/s314/news-service/tree/master/app/controllers/"
    click ViewsWeb "https://github.com/s314/news-service/tree/master/app/views/"
    click JSRails "https://github.com/s314/news-service/tree/master/app/assets/javascripts/"
    click CSSRails "https://github.com/s314/news-service/tree/master/app/assets/stylesheets/"
    click Images "https://github.com/s314/news-service/tree/master/app/assets/images/"
    click Models "https://github.com/s314/news-service/tree/master/app/models/"
    click Jobs "https://github.com/s314/news-service/blob/master/app/jobs/application_job.rb"
    click Mailers "https://github.com/s314/news-service/blob/master/app/mailers/application_mailer.rb"
    click DBConfig "https://github.com/s314/news-service/blob/master/config/database.yml"
    click CableConfig "https://github.com/s314/news-service/blob/master/config/cable.yml"
    click OtherConfig "https://github.com/s314/news-service/blob/master/config/application.rb"
    click Server "https://github.com/s314/news-service/blob/master/Bukdu/bukdu_server.jl"
    click Bayes "https://github.com/s314/news-service/blob/master/Bukdu/bayes.jl"
    click DBLearn "https://github.com/s314/news-service/blob/master/Bukdu/db_learning.jl"
    click Corpus "https://github.com/s314/news-service/tree/master/Bukdu/corpus/"

    %% Styles
    classDef ui fill:#D0E7FF,stroke:#333,stroke-width:1px
    classDef rails fill:#D0F0D0,stroke:#333,stroke-width:1px
    classDef db fill:#FFE5B4,stroke:#333,stroke-width:1px
    classDef cache fill:#FFFACD,stroke:#333,stroke-width:1px
    classDef julia fill:#E0D2F7,stroke:#333,stroke-width:1px
```
