Skip to main content

cosmic_applet_avestruz/guide/
architecture.rs

1// SPDX-License-Identifier: MIT
2
3//! What the parts are, what each may know of the others, where each runs,
4//! and where things are kept. Documentation only.
5//!
6//! 1. [In one picture](#in-one-picture)
7//! 2. [The loop](#the-loop)
8//! 3. [The layers, and what each may know](#the-layers-and-what-each-may-know)
9//! 4. [The model](#the-model)
10//! 5. [Which view is on show](#which-view-is-on-show)
11//! 6. [Starting up](#starting-up)
12//! 7. [The popup's life](#the-popups-life)
13//! 8. [Where things run](#where-things-run)
14//! 9. [Where things are kept](#where-things-are-kept)
15//! 10. [What is asked of the web](#what-is-asked-of-the-web)
16//! 11. [The modules](#the-modules)
17//! 12. [What the program weighs](#what-the-program-weighs)
18//!
19//! # In one picture
20//!
21//! Avestruz is one process, started by the COSMIC panel, with one button
22//! in the panel and one popup under it. Everything it shows is in the
23//! popup; everything it knows is in one model; everything that changes
24//! the model is a message.
25//!
26//! ```mermaid
27//! flowchart TB
28//!     reader(["Whoever is at the desktop"])
29//!     subgraph panel["The COSMIC panel"]
30//!         button["The applet's button"]
31//!         popup["The popup: the whole client"]
32//!     end
33//!     subgraph process["Avestruz, one process"]
34//!         views["views: draw the model"]
35//!         model[("AppModel: all that outlives the popup")]
36//!         handlers["handlers: take one message at a time"]
37//!         service["NostrService: two relay pools over one store"]
38//!         signer["Signer: signs, encrypts, decrypts"]
39//!         fetched["ImageStore and PreviewStore"]
40//!     end
41//!     subgraph here["On this machine"]
42//!         config[("COSMIC config")]
43//!         keyring[("System keyring")]
44//!         store[("Event store, LMDB")]
45//!     end
46//!     subgraph away["Elsewhere"]
47//!         own["The account's own relays"]
48//!         theirs["Other people's relays"]
49//!         bunker["A remote signer"]
50//!         web["Web servers"]
51//!     end
52//!     reader --> button --> popup
53//!     popup -- "messages" --> handlers
54//!     handlers -- "change" --> model
55//!     model -- "is read by" --> views
56//!     views -- "widgets" --> popup
57//!     handlers --> service
58//!     handlers --> signer
59//!     handlers --> fetched
60//!     handlers <--> config
61//!     service <--> store
62//!     service <--> own
63//!     service <--> theirs
64//!     signer <--> keyring
65//!     signer <-. "NIP-46, by way of relays" .-> bunker
66//!     fetched --> web
67//! ```
68//!
69//! The names in the picture are the names in the code:
70//! [`AppModel`](crate::state::AppModel),
71//! [`Message`](crate::messages::Message), [`crate::handlers`],
72//! [`crate::views`], [`NostrService`](crate::nostr::client::NostrService),
73//! [`Signer`](crate::nostr::account::Signer),
74//! [`ImageStore`](crate::images::ImageStore) and
75//! [`PreviewStore`](crate::previews::PreviewStore).
76//!
77//! # The loop
78//!
79//! Avestruz is a libcosmic application, and libcosmic is iced: the Elm
80//! architecture. There is a model, a function that draws it, and a
81//! function that changes it when a message comes. Nothing else changes
82//! it, and nothing is drawn from anything else.
83//!
84//! ```mermaid
85//! sequenceDiagram
86//!     actor reader as Reader
87//!     participant view as views
88//!     participant update as app update
89//!     participant handler as A handler
90//!     participant task as A task
91//!     participant world as Store, relays, web
92//!     reader->>view: presses, types, scrolls
93//!     view->>update: a Message
94//!     update->>handler: the handler for it
95//!     handler->>handler: changes the model
96//!     handler-->>task: starts what takes time
97//!     update-->>view: the view is built again from the model
98//!     task->>world: asks
99//!     world-->>task: answers, or doesn't
100//!     task->>update: a Message carrying the answer
101//!     update->>handler: the handler for it
102//!     handler->>handler: changes the model
103//!     update-->>view: the view is built again from the model
104//! ```
105//!
106//! [`AppModel::update`](crate::app) is one `match` over every
107//! [`Message`](crate::messages::Message), and each arm calls a handler. A
108//! handler does two things and no third: it changes the model, at once and
109//! without waiting on anything, and it may return a `Task`, which is
110//! whatever takes time (a question to the store, to a relay, to a web
111//! server, a signature) wrapped so that its answer comes back as another
112//! message. Nothing in a handler blocks, since the handler runs where the
113//! window is drawn.
114//!
115//! Besides what the reader does, messages come from five subscriptions,
116//! set up in [`AppModel::subscription`](crate::app):
117//!
118//! | From | Message | How often |
119//! |---|---|---|
120//! | A timer | `CheckForNewNotes` | Every minute while the popup is open, every five while it is closed |
121//! | A timer | `SweepStore` | Every hour; the store is swept once a day (see [`crate::handlers::store`]) |
122//! | COSMIC's config watch | `UpdateConfig` | When the config changes on disk |
123//! | The picture requests | `LoadImage` | When a row on screen wants a picture that isn't there (see [`crate::requests`]) |
124//! | The preview requests | `LoadPreview` | When a row on screen links to a page nobody asked yet |
125//!
126//! ## Answers that come too late
127//!
128//! A task's answer arrives some time after it was started, and by then
129//! the model may have moved on: the profile was closed, another account
130//! signed in, a newer search was made. So an answer says what it is an
131//! answer *to*, and the handler that takes it looks whether that is still
132//! there:
133//!
134//! - a list of notes has an id of its own
135//!   ([`FeedState::id`](crate::state::FeedState::id)), and what was asked
136//!   for it comes back with the id, to find the list or find it gone;
137//! - a search has a serial number, and only the newest one's answers are
138//!   taken;
139//! - what belongs to an account (its bookmarks, its relay lists, its
140//!   drafts) comes back with the account's public key, and is dropped if
141//!   somebody else is signed in by then.
142//!
143//! # The layers, and what each may know
144//!
145//! ```mermaid
146//! flowchart TB
147//!     subgraph ui["What is seen"]
148//!         views["views and views::components"]
149//!     end
150//!     subgraph core["What is known and what is done"]
151//!         state["state: AppModel"]
152//!         messages["messages: Message"]
153//!         handlers["handlers"]
154//!     end
155//!     subgraph nostr["What speaks Nostr"]
156//!         client["nostr::client: NostrService"]
157//!         account["nostr::account: Signer"]
158//!         pure["nostr::*: events made and read, no I/O"]
159//!     end
160//!     subgraph io["What reaches outside"]
161//!         http["http, images, previews"]
162//!         config["config, drafts, screen, links, logging"]
163//!     end
164//!     views -- "reads" --> state
165//!     views -- "sends" --> messages
166//!     handlers -- "changes" --> state
167//!     handlers -- "takes" --> messages
168//!     handlers --> client
169//!     handlers --> account
170//!     handlers --> http
171//!     handlers --> config
172//!     client --> pure
173//!     client --> account
174//!     pure -.-> http
175//! ```
176//!
177//! - **Views** take `&AppModel` and return widgets. They can't change the
178//!   model, and they never ask the store or a relay anything. What a view
179//!   finds missing (a picture, a link's preview) it asks for through a
180//!   store that hands the request on as a message: see [`crate::requests`].
181//! - **Handlers** are `impl AppModel` blocks, one file for each kind of
182//!   thing that can happen ([`crate::handlers`]). They are the only code
183//!   that changes the model.
184//! - **The `nostr` modules** know nothing of the toolkit: none of them
185//!   names a widget, a message or the model. Most are pure: an event goes
186//!   in and a model for the views comes out
187//!   ([`content`](crate::nostr::content), [`thread`](crate::nostr::thread),
188//!   [`feed`](crate::nostr::feed)), or what someone wrote goes in and an
189//!   unsigned event comes out ([`compose`](crate::nostr::compose),
190//!   [`contacts`](crate::nostr::contacts),
191//!   [`bookmarks`](crate::nostr::bookmarks)). Two do the talking:
192//!   [`client`](crate::nostr::client) to relays and the store,
193//!   [`account`](crate::nostr::account) to the keyring and a remote
194//!   signer. Three ask a web server one question each
195//!   ([`nip05`](crate::nostr::nip05), [`zap`](crate::nostr::zap),
196//!   [`relay_info`](crate::nostr::relay_info)).
197//! - **Everything from the web** goes through [`crate::http`], which is
198//!   where what may be fetched, and how much of it, is decided once.
199//!
200//! # The model
201//!
202//! [`AppModel`](crate::state::AppModel) is one struct. It is large because
203//! of what the popup is (see [the popup's life](#the-popups-life)): nothing
204//! can be left in a widget. What is in it, by what it is for:
205//!
206//! | What | Fields | Notes |
207//! |---|---|---|
208//! | The window | `core`, `popup`, `view_state`, `screen` | `popup` is `None` while it is closed |
209//! | Who is signed in | `account`, `signer`, `login_*` | The account is a public key and whether it can sign; no secret is in the model |
210//! | The relay client | `nostr` | `None` until the store is open |
211//! | The feed | `following`, `follows`, `feeds_made`, `feed_checked_at`, `feed_modes` | A [`FeedState`](crate::state::FeedState) |
212//! | What is open over the feed | `pages` | A stack of [`Page`](crate::state::Page): threads, profiles, the bookmarks, searches, the notifications |
213//! | What the account is told of | `notifications`, `notification_tabs` | A [`NotificationsState`](crate::state::NotificationsState): kept up while no page shows it, for the count of what is new |
214//! | Writing | `composer`, `compose_tabs`, `drafts`, `drafts_kept`, `draft_path` | The editor's content is here, not in the editor, and so is what is written as it would show, while that is looked at |
215//! | What was made of notes | `engagement`, `engagement_asked`, `pending_marks`, `seen_on` | Counts by note, and the reactions and reposts on their way |
216//! | Reacting | `reaction_menu`, `reaction_suggestions` | What to react with, on offer for one note, and the emoji offered first |
217//! | Bookmarks | `bookmarks`, `bookmark_pending`, `bookmark_first_list` | A [`BookmarkState`](crate::state::BookmarkState) |
218//! | The account's relays | `relays` | A [`RelaysState`](crate::state::RelaysState): the lists, and what was changed and not saved |
219//! | The account's media servers, and what is attached | `media` | A [`MediaState`](crate::state::MediaState): the server list, what was changed and not saved, the files on their way, and what a note says of each that arrived |
220//! | People | `profiles`, `profiles_requested`, `nip05`, `follow_pending` | Everyone's profile is in one map, by public key |
221//! | Pictures and previews | `images`, `previews`, and their request channels | Stores the views read and ask |
222//! | Zapping | `zap` | A [`ZapState`](crate::state::ZapState) |
223//! | What went wrong | `error_message` | One line, shown in a banner over whatever is on show |
224//!
225//! A list of notes is always the same shape, whether it is the feed or the
226//! notes on a profile: its notes, how tall each row measured, how far it
227//! is scrolled, and what is on its way.
228//!
229//! ```mermaid
230//! classDiagram
231//!     class AppModel {
232//!         view_state
233//!         following
234//!         pages
235//!         composer
236//!         profiles
237//!     }
238//!     class FeedState {
239//!         id
240//!         feed
241//!         heights
242//!         position
243//!         pending
244//!     }
245//!     class Page {
246//!         <<enumeration>>
247//!         Thread
248//!         Profile
249//!         Bookmarks
250//!         Search
251//!     }
252//!     class ThreadState {
253//!         thread
254//!         heights
255//!         position
256//!     }
257//!     class ProfileState {
258//!         public_key
259//!         notes
260//!     }
261//!     AppModel "1" *-- "1" FeedState : following
262//!     AppModel "1" *-- "0..16" Page : pages
263//!     Page --> ThreadState
264//!     Page --> ProfileState
265//!     ProfileState *-- FeedState : notes
266//! ```
267//!
268//! # Which view is on show
269//!
270//! [`ViewState`](crate::state::ViewState) names the view, and the stack of
271//! pages says what is under it. The feed is under everything. Threads,
272//! profiles, the bookmarks and searches open over it as pages, one from
273//! another; Back closes the last. The composer, the zap view, the
274//! settings, the relays page and the view of what the keys do show *in
275//! place of* whatever list was on show and leave it as it was, so
276//! closing them goes back to the last page, or to the feed if no page is
277//! open
278//! ([`show_list_view`](crate::state::AppModel::show_list_view)).
279//!
280//! ```mermaid
281//! stateDiagram-v2
282//!     state "Compose, Zap, Settings, Relays or Keys" as Aside
283//!     [*] --> Login: no account in the config
284//!     [*] --> Feed: an account in the config
285//!     Login --> Feed: signed in
286//!     Feed --> Page: a thread, a profile, the bookmarks or a search opens
287//!     Page --> Page: another opens from it
288//!     Page --> Feed: Back, from the last page
289//!     Feed --> Aside: opened
290//!     Page --> Aside: opened
291//!     Aside --> Feed: closed, with no page open
292//!     Aside --> Page: closed, with a page open
293//!     Aside --> Login: signed out, in the settings
294//! ```
295//!
296//! No more than
297//! [`MAX_OPEN_PAGES`](crate::handlers::navigation::MAX_OPEN_PAGES) pages
298//! are kept: the applet runs for as long as the session does, and each
299//! page holds a list of notes. Opening one more closes the first.
300//!
301//! # Starting up
302//!
303//! `main` does three things before there is a window: it names the TLS
304//! crypto provider (there must be exactly one, see [`crate::http`]), sets
305//! up logging so that the level can be changed while the applet runs
306//! ([`crate::logging`]), and picks the language. Then
307//! [`AppModel::init`](crate::app) reads the config and starts four things
308//! at once, none of which waits for another:
309//!
310//! ```mermaid
311//! sequenceDiagram
312//!     participant init as init
313//!     participant store as Event store
314//!     participant keyring as Keyring
315//!     participant relays as Relays
316//!     participant model as AppModel
317//!     par the store and the relays
318//!         init->>store: open (NostrService::open)
319//!         store-->>model: NostrReady
320//!         init->>relays: connect to the config's relays, in the background
321//!     and the account
322//!         init->>keyring: is the secret of the config's account there?
323//!         keyring-->>model: AccountRestored: full access or read-only
324//!     and the draft file
325//!         init-->>model: DraftLoaded
326//!     and the screen
327//!         init-->>model: ScreenMeasured
328//!     end
329//!     Note over model: load_account runs when both the store and the account are there
330//!     model->>store: who does the account follow? what is its relay list?
331//!     store-->>model: the feed as it was, at once
332//!     model->>relays: the same questions, and the newest notes
333//!     relays-->>model: answers, as they come
334//! ```
335//!
336//! [`load_account`](crate::state::AppModel::load_account) is called both
337//! when the store opens and when
338//! the account is known, and does nothing until both are there. What it
339//! starts: the account's outbox relays joining the pool, its contact list
340//! (which fills the feed), its own profile, and, only if the popup is
341//! open, its bookmarks, the relay lists that are gone by all the time, and
342//! its drafts. Those three take the account's key to read, which may mean
343//! asking a remote signer, which may mean asking a person: none of that
344//! happens before there is someone looking at the popup.
345//!
346//! A feed that was read before shows before any relay has answered: what
347//! the store holds is asked first and answers within the frame.
348//!
349//! # The popup's life
350//!
351//! Avestruz is two processes: the button in the panel, and the window,
352//! which is everything else and is what this page is about (why two is
353//! in [`crate::button`]). The window has nothing on the screen until the
354//! button is pressed: then it puts up the popup, a surface of its own on
355//! the compositor, against the edge the panel is on.
356//!
357//! The popup closes whenever something else is clicked, as a panel's own
358//! popup does. When it closes, its widget tree is gone: every scroller's position, every
359//! text field's content, every row's measured height. When it opens
360//! again, a new tree is built from the model. So the rule is that
361//! **whatever should still be there when the popup opens again is in the
362//! model**, and the widgets are given it back:
363//!
364//! | What a widget would have kept | Where it is kept instead |
365//! |---|---|
366//! | How far a list is scrolled | A [`ScrollPosition`](crate::views::components::ScrollPosition) cell in the list's state, scrolled back to before the first frame |
367//! | How tall each row measured | A [`RowHeights`](crate::views::components::RowHeights), by note id, in the list's state |
368//! | Which long notes show in full | An [`Expanded`](crate::state::Expanded), by note id, in the list's state |
369//! | What is being written | The composer's `text_editor::Content`, in the model; and every target's draft in [`Drafts`](crate::drafts::Drafts) |
370//! | Which page is open over which | [`AppModel::pages`](crate::state::AppModel::pages) |
371//! | What was typed in a search, and what it found | The search's [`SearchPage`](crate::state::SearchPage) |
372//! | Relays changed and not saved | [`RelaysState::edited`](crate::state::RelaysState::edited) |
373//! | Which row of each list the keyboard is at | `marked`, in each list's own state: [`FeedState::marked`](crate::state::FeedState::marked) and its like |
374//! | Media servers changed and not saved, and files on their way to them | [`MediaState::edited`](crate::state::MediaState::edited), [`MediaState::uploads`](crate::state::MediaState::uploads) |
375//!
376//! ```mermaid
377//! stateDiagram-v2
378//!     [*] --> Closed
379//!     Closed --> Open: the button is pressed
380//!     Open --> Closed: the button, or a click anywhere else
381//! ```
382//!
383//! | When | What happens |
384//! |---|---|
385//! | The popup opens | New notes are looked for, if that was not done in the last half minute. The bookmarks, the blocked and indexer relays and the drafts are read, each of which takes the key. The screen is measured again |
386//! | The popup closes | What is in the composer is kept as its draft, and an open menu is put away |
387//! | While it is closed | New notes are still looked for, every five minutes, and wait to be asked for |
388//!
389//! The popup may be as tall as the screen it opens on has room. A
390//! program is not told how much that is, so the window keeps a surface
391//! from the top of the screen to the bottom, which shows nothing, and
392//! asks how tall the compositor made it ([`crate::screen`]).
393//!
394//! # Where things run
395//!
396//! | Where | What runs there |
397//! |---|---|
398//! | The main thread | The window's event loop: `update`, every handler, `view`, layout and drawing. The popup is drawn by the GPU (`wgpu`), and by the CPU (`tiny_skia`) where there is none to be had. |
399//! | The button's process | The button in the panel and nothing else, drawn by the CPU: it starts the window, tells it of each press, and shows the dot it is told to ([`crate::button`]) |
400//! | The tokio runtime libcosmic starts | Every `Task`: questions to relays and to the store, signing, everything fetched from the web. Each relay connection is a task of the relay library's. |
401//! | tokio's blocking threads | Decoding a picture ([`crate::images`]), every call to the keyring ([`crate::nostr::account`]) |
402//! | yt-dlp, a process of its own | Finding a stream of a YouTube video, when one is played: run, waited for off the main thread, and gone ([`crate::youtube`]) |
403//! | GStreamer's threads | A video that plays: fetching it, decoding it, its sound. The main thread only takes the newest frame, on a timer ([`crate::video`]) |
404//! | The event store's writer thread | Every write to the store, in the order they were asked for: events saved as relays send them, and what a sweep takes out ([`crate::nostr::sweep`]) |
405//!
406//! Two things follow from the first row. A handler must not wait on
407//! anything, since nothing is drawn while it does. And a message must not
408//! be sent *while a frame is being drawn* if the popup may be changing
409//! size just then, or the CPU renderer, where it is the one drawing,
410//! presents into a buffer of the old size and panics: this is why a list says it was scrolled near its end
411//! in answer to an event and never during a redraw (see
412//! [`crate::views::components::virtual_list`]).
413//!
414//! What is shared between tasks is behind a lock that is never held across
415//! an `await` of something slow: the client's bookkeeping in
416//! [`NostrService`](crate::nostr::client::NostrService) is behind
417//! `std::sync::Mutex`es taken for a few lines at a time. Two async locks
418//! are held longer, on purpose, to keep two things from happening at once:
419//! connecting to a relay somebody else is already connecting to, and
420//! changing whose relays are in use while they are being changed.
421//!
422//! # Where things are kept
423//!
424//! ```mermaid
425//! flowchart LR
426//!     subgraph disk["On disk"]
427//!         config[("COSMIC config: settings, and the account's npub")]
428//!         keyring[("Keyring: nsec or bunker address, client keys")]
429//!         events[("Event store: every event a relay sent, and drafts")]
430//!         draft[("draft.txt: one draft, when all else failed")]
431//!     end
432//!     subgraph memory["In memory, for as long as the applet runs"]
433//!         model["The model"]
434//!         pictures["Decoded pictures, up to a budget"]
435//!         previews["What linked pages said"]
436//!         seen["Which relay sent which note"]
437//!     end
438//!     model --- pictures
439//!     model --- previews
440//!     model --- seen
441//! ```
442//!
443//! | What | Where | Notes |
444//! |---|---|---|
445//! | Settings: relays, which account, text size, how long notes are kept, how much is logged, the emoji reacted with, when the notifications were last looked at | COSMIC config, under the app's id | [`Config`](crate::config::Config). Read at start, watched for changes |
446//! | An account's `nsec` or `bunker://` address | The system keyring, under its `npub` | Never in the config, the store or a log |
447//! | The key a remote signer knows this client by | The keyring, one for each signer | Kept when signing out |
448//! | Every event a relay sent | LMDB, under the data directory | The cache everything shows from first. Swept by age ([`crate::nostr::sweep`]) |
449//! | Drafts | The same store, as NIP-37 events, encrypted | [`crate::nostr::kept_drafts`] |
450//! | The draft of a new note, when it could not be kept as an event | A text file beside the store | [`crate::drafts`] |
451//! | Fonts of the applet's own, if any were put there | A directory beside the store | Read at start, before the system's ([`crate::fonts`]) |
452//! | Pictures | Memory only | Up to [`DEFAULT_BUDGET_BYTES`](crate::images::DEFAULT_BUDGET_BYTES) decoded; the least recently shown go first |
453//! | Link previews | Memory only | Asked once in a run |
454//! | The video that plays | Memory only | One at a time: its latest frame, and what GStreamer holds of it ([`crate::video`]) |
455//! | Which relays a note was seen on | Memory only | [`crate::nostr::sightings`] |
456//!
457//! There is no database beside the event store. What Avestruz knows of the
458//! account that is not a setting is an *event*: who it follows is its
459//! contact list, what it bookmarked is its bookmark list, where it writes
460//! is its relay list, what it left unfinished is a draft event. They are
461//! read from the store like anything else, and what other clients write
462//! shows up here by the same road.
463//!
464//! # What is asked of the web
465//!
466//! Relays are spoken to over WebSocket by the relay library. Everything
467//! else goes over `https` through one client and one function
468//! ([`crate::http`]), which is where the rules are: only `https`, redirects
469//! included; a time limit; and no more read than the caller asked to
470//! keep. Every address fetched was written by somebody else.
471//!
472//! | Who is asked | What | When | Where |
473//! |---|---|---|---|
474//! | Whoever hosts a picture | The picture | A row with it is on screen | [`crate::images`] |
475//! | A page a note links to | Its head, for a title, a line and a picture | A row with the link is on screen | [`crate::previews`] |
476//! | Whoever hosts a video | The video, fetched by GStreamer and not by [`crate::http`] | Its reader pressed play | [`crate::video`] |
477//! | YouTube | What a video is called, and its picture | A row with a link to it is on screen | [`crate::previews`], [`crate::images`] |
478//! | YouTube, by yt-dlp | Which streams a video has; then, by GStreamer, one of them | Its reader pressed play | [`crate::youtube`] |
479//! | The domain of a NIP-05 name | Whether the name is that person's | Their profile is open, or the name was typed in a search | [`crate::nostr::nip05`] |
480//! | A Lightning address's server | What it accepts, then an invoice | A note is being zapped | [`crate::nostr::zap`] |
481//! | A relay, over `https` | What it says of itself (NIP-11) | The relays page shows, or its address was typed in a search | [`crate::nostr::relay_info`] |
482//!
483//! Each of those servers sees the request, and so learns that someone at
484//! this address looked. That is why a NIP-05 name is only checked when a
485//! profile is open: a feed would have a hundred domains told who reads
486//! what.
487//!
488//! # The modules
489//!
490//! ```mermaid
491//! flowchart LR
492//!     main --> app
493//!     app --> handlers
494//!     app --> views
495//!     app --> state
496//!     app --> messages
497//!     handlers --> state
498//!     handlers --> nostr
499//!     handlers --> images
500//!     handlers --> previews
501//!     handlers --> drafts
502//!     handlers --> config
503//!     handlers --> screen
504//!     handlers --> links
505//!     views --> state
506//!     views --> components["views::components"]
507//!     components --> images
508//!     components --> previews
509//!     images --> http
510//!     previews --> http
511//!     images --> requests
512//!     previews --> requests
513//!     nostr --> http
514//!     state --> nostr
515//!     messages --> nostr
516//! ```
517//!
518//! | Module | What it is |
519//! |---|---|
520//! | [`crate::app`] | The `cosmic::Application`: init, the subscriptions, and `update`, which hands each message to its handler |
521//! | [`crate::state`] | The model, and the state of each thing the model holds |
522//! | [`crate::messages`] | Every message |
523//! | [`crate::handlers`] | What happens on each message, one file for each kind of thing |
524//! | [`crate::views`] | What each view looks like, and the components they share |
525//! | [`crate::nostr`] | Everything that speaks Nostr |
526//! | [`crate::config`] | The settings, as COSMIC's config store keeps them |
527//! | [`crate::http`] | The one way anything is fetched from the web |
528//! | [`crate::images`], [`crate::previews`], [`crate::requests`] | Pictures, what linked pages say of themselves, and how a view asks for either |
529//! | [`crate::drafts`] | What is being written, by what it is written to |
530//! | [`crate::screen`], [`crate::links`], [`crate::logging`], [`crate::helpers`], [`crate::i18n`] | How tall the screen is, opening a link, how much is logged, small pure helpers, the language |
531//!
532//! The crates underneath, and what each is for:
533//!
534//! | Crate | What for |
535//! |---|---|
536//! | `libcosmic` | The application framework, the widgets, the theme, the panel applet |
537//! | `nostr-sdk` | The protocol, the relay pool, and the relay Avestruz runs itself |
538//! | `nostr-lmdb` | The event store |
539//! | `nostr-connect` | Signing through a remote signer (NIP-46) |
540//! | `keyring` | The system keyring (Secret Service) |
541//! | `reqwest`, `rustls` | Everything fetched from the web |
542//! | `image` | Decoding pictures |
543//! | `gstreamer`, `gstreamer-app`, `gstreamer-video` | Playing videos: fetching, decoding, sound, and the frames a row draws |
544//! | `html5gum` | Reading the head of a linked page |
545//! | `qrcode` | An invoice as a QR code |
546//! | `tokio-tungstenite` | The WebSocket the relay Avestruz runs itself is spoken to over |
547//!
548//! # What the program weighs
549//!
550//! The program as installed is 49 MiB, of which 34.2 MiB is code (its
551//! `.text` section) and most of the rest is what the code reads rather
552//! than runs: tables, text, and other data that does not change. That
553//! was measured in November 2026, and is a picture of that day: `just
554//! bloat-check` measures it as it is now, from a build that keeps the
555//! names `cargo bloat` tells one crate's code from another's by.
556//!
557//! The code comes from some three hundred and fifty crates, and no one
558//! of them is much of it. Taken by what they are for:
559//!
560//! ```mermaid
561//! pie showData title The program's code, by what it is for (% of .text)
562//!     "Rust's standard library" : 11.9
563//!     "Drawing on the GPU" : 11.5
564//!     "D-Bus" : 11.1
565//!     "Windows, Wayland and X11" : 10.1
566//!     "Avestruz itself" : 9.3
567//!     "Pictures" : 7.6
568//!     "The toolkit" : 7.5
569//!     "The web" : 7.4
570//!     "Text" : 6.8
571//!     "Nostr" : 6.0
572//!     "Accessibility" : 3.1
573//!     "Everything else" : 7.7
574//! ```
575//!
576//! | What for | Share | The crates that are most of it, and the share of each |
577//! |---|---|---|
578//! | Rust's standard library | 11.9% | `std` |
579//! | Drawing on the GPU | 11.5% | `naga` 5.5, `wgpu_core` 2.9, `wgpu_hal` 1.4, `iced_wgpu` 0.7, `wgpu` 0.4 |
580//! | D-Bus: the keyring, the desktop's portals | 11.1% | `zbus` 8.6, `dbus` 0.7, `zvariant` 0.6, `ashpd` 0.4 |
581//! | Windows, Wayland and X11 | 10.1% | `iced_winit` 2.2, `winit_wayland` 1.4, `winit_x11` 1.3, `wayland_client` 1.0, `wayland_protocols` 0.7, `clipboard_wayland` 0.7 |
582//! | Avestruz itself | 9.3% | `cosmic_applet_avestruz` |
583//! | Pictures: decoding them, and drawing SVG | 7.6% | `image_webp` 1.3, `image` 1.2, `usvg` 1.1, `tiny_skia` 1.1, `zune_jpeg` 0.5, `resvg` 0.4 |
584//! | The toolkit: libcosmic and iced | 7.5% | `cosmic` 2.3, `cosmic_theme` 1.6, `iced_graphics` 0.5, `cosmic_config` 0.5 |
585//! | The web: TLS, HTTP, and what runs the tasks | 7.4% | `rustls` 1.6, `tokio` 1.3, `ring` 0.9, `reqwest` 0.8, `html5gum` 0.6 |
586//! | Text: fonts, and shaping | 6.8% | `harfrust` 1.3, `skrifa` 1.1, `read_fonts` 0.9, `rustybuzz` 0.8, `cosmic_text` 0.8 |
587//! | Nostr | 6.0% | `nostr_sdk` 2.5, `nostr` 1.0, `nostr_lmdb` 0.7, `nostr_connect` 0.4 |
588//! | Accessibility | 3.1% | `accesskit_unix` 2.5 |
589//! | Everything else | 7.7% | Small crates, none over 0.8, and the 1.1 that `cargo bloat` gives to no crate |
590//!
591//! `just bloat-check` names the thirty largest crates; `cargo bloat
592//! --profile release-bloat --crates -n 0` names them all, which is what
593//! the shares above were added up from. They are `cargo bloat`'s best
594//! guess, as it says itself: code made from one crate's generics for
595//! another's types has no one owner.
596//!
597//! What Avestruz itself adds is under a tenth. Drawing on the GPU, which
598//! the popup does (see [`crate::button`]), is more than that. Playing
599//! videos is next to nothing, 0.1%: GStreamer is the system's, and no
600//! part of the program. And about 2% is for X11 (`winit_x11`, `x11rb`,
601//! `x11_dl`), which a popup that is a layer surface on a Wayland
602//! compositor never runs. No feature of libcosmic's leaves it out, its
603//! defaults turned off or not: libcosmic takes `iced_winit` with that
604//! crate's defaults, which name X11; `iced_winit` takes `winit` with
605//! its own, which do too; and the clipboard crate under both takes its
606//! X11 half whatever is asked of it.