this post was submitted on 01 Feb 2024
16 points (100.0% liked)

Learning Rust and Lemmy

393 readers
1 users here now

Welcome

A collaborative space for people to work together on learning Rust, learning about the Lemmy code base, discussing whatever confusions or difficulties we're having in these endeavours, and solving problems, including, hopefully, some contributions back to the Lemmy code base.

Rules TL;DR: Be nice, constructive, and focus on learning and working together on understanding Rust and Lemmy.


Running Projects


Policies and Purposes

  1. This is a place to learn and work together.
  2. Questions and curiosity is welcome and encouraged.
  3. This isn't a technical support community. Those with technical knowledge and experienced aren't obliged to help, though such is very welcome. This is closer to a library of study groups than stackoverflow. Though, forming a repository of useful information would be a good side effect.
  4. This isn't an issue tracker for Lemmy (or Rust) or a place for suggestions. Instead, it's where the nature of an issue, what possible solutions might exist and how they could be or were implemented can be discussed, or, where the means by which a particular suggestion could be implemented is discussed.

See also:

Rules

  1. Lemmy.ml rule 2 applies strongly: "Be respectful, even when disagreeing. Everyone should feel welcome" (see Dessalines's post). This is a constructive space.
  2. Don't demean, intimidate or do anything that isn't constructive and encouraging to anyone trying to learn or understand. People should feel free to ask questions, be curious, and fill their gaps knowledge and understanding.
  3. Posts and comments should be (more or less) within scope (on which see Policies and Purposes above).
  4. See the Lemmy Code of Conduct
  5. Where applicable, rules should be interpreted in light of the Policies and Purposes.

Relevant links and Related Communities


Thumbnail and banner generated by ChatGPT.

founded 1 year ago
MODERATORS
 

The idea here is that this is a general discussion mega thread style post. Feel free to come in and ask questions, answer questions, and generally discuss.

This can go on as long as we want, and stay pinned if that works. We can simply using sorting to see the latest or "biggest" comments in here.


The worst bit about digging into a codebase, IMO, is orientating yourself and working out what does what!

The backend codebase can be found here: https://github.com/LemmyNet/lemmy

The "Contributing" section of the documentation (see here) lists how the other components of the platform interact with each other and the backend. But I don't think there's any outline of how the pieces of the backend work.

Perhaps another relevant codebase is the activity pub framework made along with lemmy: https://github.com/LemmyNet/activitypub-federation-rust.

you are viewing a single comment's thread
view the rest of the comments
[โ€“] [email protected] 12 points 1 year ago* (last edited 1 year ago) (1 children)

Hi, thanks for setting up this community. I'm not a Lemmy source contributer but I like to read open sources. Here is a very simplified web application (including Lemmy) architecture overview and I hope this text helps for some newbies:

  1. A user agent (web browser, mobile app, etc.) sends an HTTP request to a Lemmy instance.
  2. The lemmy instance examines the HTTP request and dispatches the request to a relevant function called controller. The mapping from a path in the URL to a function is called a router - see https://github.com/LemmyNet/lemmy/blob/0.19.3/src/api_routes_http.rs for example.
  3. The controller makes an HTTP response for the request and returns it to the user agent.
  4. The user agent displays the returned response to the user.

To find an controller from a path in the router, just grep (or a similar search function you use) the Lemmy source. For example, if I want to know how GET /user/export_settings works, I'll run these commands:

$ git clone https://github.com/LemmyNet/lemmy/  # if you haven't download the source yet
$ cd lemmy
$ rg export_settings
src/api_routes_http.rs
131:  user_settings_backup::{export_settings, import_settings},
274:        web::resource("/user/export_settings")
276:          .route(web::get().to(export_settings)),

crates/apub/src/api/user_settings_backup.rs
68:pub async fn export_settings(
301:  use crate::api::user_settings_backup::{export_settings, import_settings};
366:    let backup = export_settings(export_user.clone(), context.reset_request_count()).await?;
402:    let mut backup = export_settings(export_user.clone(), context.reset_request_count()).await?;

So we got the relevant route and the controller definitions very quickly. Settings to be exported are defined as a struct UserSettingsBackup. The controller is defined as pub async fn export_settings and it converts the struct to a JSON.

Rust might not be a easy programming language but the official text (calld The Book is very friendly for newbies, so don't hesitate to read and to write a simple program like guessing game.

[โ€“] [email protected] 4 points 1 year ago