File: ARCHITECTURE.md

package info (click to toggle)
rspamd 3.14.3-1
  • links: PTS, VCS
  • area: main
  • in suites: sid
  • size: 35,064 kB
  • sloc: ansic: 247,728; cpp: 107,741; javascript: 31,385; perl: 3,089; asm: 2,512; pascal: 1,625; python: 1,510; sh: 589; sql: 313; makefile: 195; xml: 74
file content (218 lines) | stat: -rw-r--r-- 7,435 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
# Rspamd WebUI Architecture

## Overview

The Rspamd WebUI is a single-page application (SPA) providing a web interface for monitoring and managing Rspamd. It communicates with Rspamd's Controller API and supports multiple server instances.

**Main capabilities:**
- Real-time statistics and throughput monitoring
- Message processing history inspection
- Message scanning and analysis
- Bayes classifier and Fuzzy storage training
- Symbol and action configuration
- Map editing
- Selector testing
- Multi-server management

## Technology Stack

### Module System
- **RequireJS** - AMD (Asynchronous Module Definition) pattern for modular code organization

### Core Libraries
- **jQuery** - DOM manipulation, event handling, AJAX
- **Bootstrap** - UI framework for responsive layout and components

### Visualization & Data Display
- **D3.js** - Base visualization library
- **D3Evolution** - Time-series line charts (throughput graphs)
- **D3Pie** - Pie charts (action distribution)
- **FooTable** - Responsive data tables with sorting, filtering, and pagination

### Code Editing
- **CodeJar** - Lightweight code editor
- **CodeJar Line Numbers** - Line numbering extension for CodeJar
- **Prism.js** - Syntax highlighting

### Utilities
- **NProgress** - Progress bars for async operations
- **Visibility.js** - Page Visibility API wrapper for timer management
- **Font Awesome** - Icon library
- **jQuery Sticky Tabs** - Persistent tab state via URL hash

### Theme System
Custom implementation supporting light/dark/auto modes with system preference detection.

## Project Structure

```
interface/
├── index.html              # Main HTML file with tab structure
├── css/                    # Stylesheets
│   ├── bootstrap.min.css
│   ├── rspamd.css         # Custom styles
│   └── ...                # Third-party CSS
├── js/
│   ├── main.js            # Entry point & RequireJS configuration
│   ├── app/               # Application modules
│   │   ├── common.js      # Shared utilities and API client
│   │   ├── rspamd.js      # Main application logic, auth, tab management
│   │   ├── stats.js       # Statistics tab (status widgets)
│   │   ├── history.js     # History tab (message log, errors)
│   │   ├── graph.js       # Throughput tab (time-series graphs)
│   │   ├── symbols.js     # Symbols tab (symbol scores editing)
│   │   ├── config.js      # Configuration tab (actions, maps)
│   │   ├── upload.js      # Scan tab (message upload/scanning)
│   │   ├── selectors.js   # Selectors tab (testing selectors)
│   │   ├── libft.js       # FooTable utilities (history table rendering)
│   │   └── footable-fontawesome.js  # FooTable Font Awesome integration
│   └── lib/               # Third-party libraries (minified)
├── img/                   # Images and logos
└── README.md              # Setup instructions
```

## Module System

The WebUI uses **RequireJS** (AMD pattern) for modular code organization.

**Module definition pattern:**
```javascript
define(["dependency1", "dependency2"], (dep1, dep2) => {
    const ui = {};
    ui.publicMethod = function() { /* ... */ };
    return ui;
});
```

**Entry point:** `js/main.js` - configures RequireJS, initializes theme, loads main app module

**Module loading:**
- Main app module (`app/rspamd`) loads on page load
- Tab-specific modules lazy-load when tabs are activated

## Key Components

### Authentication & Connection
`js/app/rspamd.js` - `ui.connect()`

Handles password authentication, stores credentials in `sessionStorage`, detects read-only mode

### Tab Management & Navigation
`js/app/rspamd.js` - `tabClick()`

Manages tab switching, lazy-loads tab-specific modules, handles auto-refresh

### Auto-Refresh System
`js/app/rspamd.js` - `setAutoRefresh()`

Periodically refreshes tab data, pauses when page hidden (via Visibility.js), shows countdown timer

### API Communication
`js/app/common.js` - `ui.query(url, options)`

Sends HTTP requests to Controller API, supports multi-server queries, handles authentication and errors

### Theme System
`js/main.js` - Theme initialization and `window.rspamd.theme` API

Manages light/dark/auto theme switching, persists preferences, responds to system theme changes

### Statistics Display
`js/app/stats.js`

Fetches and displays server statistics (Status tab): version, uptime, message counts, action distribution

### Throughput Graphs
`js/app/graph.js`

Renders time-series graphs and pie charts (Throughput tab) using D3Evolution and D3Pie

### Message History
`js/app/history.js` (data fetching), `js/app/libft.js` (table rendering)

Displays processed message history (History tab), handles FooTable initialization, row expansion, symbol details

### Configuration Management
`js/app/config.js`

Manages actions and maps (Configuration tab): load, edit, save settings

### Symbol Management
`js/app/symbols.js`

Displays and edits symbol scores (Symbols tab)

### Message Scanning & Learning
`js/app/upload.js`

Handles message upload, scanning, Bayes classifier training, fuzzy hash management (Scan tab)

### Selector Testing
`js/app/selectors.js`

Tests Rspamd selectors against messages (Selectors tab)

### Table Utilities
`js/app/libft.js`

Shared utilities for FooTable: data preprocessing, table initialization, pagination, sorting

### FooTable Icons
`js/app/footable-fontawesome.js`

Integrates Font Awesome icons with FooTable

## Data Flow

**Typical interaction pattern:**
1. User action (click, input) → Event handler
2. Data preparation
3. `common.query()` → API request(s) to server(s)
4. Response processing
5. UI update (DOM, tables, charts)

## Common Patterns

### Event Handlers
Use function expressions `function() {}` when you need `this` context (event target element), otherwise use arrow functions `() => {}`.

### API Calls
Most API communication goes through `common.query(endpoint, options)` which handles multi-server requests, authentication, progress tracking, and error handling.

### Table Management
Tables use FooTable library. Two main patterns:
- **Initial load**: destroy old table → process data → initialize FooTable → bind event handlers
- **Update data**: use FooTable API to update existing table without re-initialization

### Module Structure
Each tab module returns a `ui` object with public methods (e.g., `ui.getSymbols()`, `ui.draw()`). These methods are called when tabs are activated.

## State Management

**Persistent storage (localStorage):**
- Theme preference
- Locale settings
- AJAX timeout
- Page size preferences

**Session storage (sessionStorage):**
- Authentication password
- Server credentials and capabilities
- Error suppression flags

**Global state:**
- `common.neighbours[]` - Configured servers
- `common.tables{}` - FooTable instances
- `timer_id[]` - Active refresh timers
- `checked_server` - Currently selected server

## Technical Requirements

**Browser capabilities needed:**
- Modern JavaScript (ES6+: arrow functions, const/let, template literals)
- Page Visibility API
- CSS Custom Properties

**Network:**
- Browser must have network access to all configured controllers
- WebUI makes API requests from the browser to each controller independently (the controller serving the WebUI does not act as an intermediary)