You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: ARCHITECTURE.md
+20-20Lines changed: 20 additions & 20 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -1,7 +1,7 @@
1
1
2
2
# Architecture
3
3
4
-
Table of content:
4
+
Table of contents:
5
5
6
6
*[Overview](#overview)
7
7
*[How it works](#how-it-works)
@@ -15,61 +15,61 @@ Table of content:
15
15
16
16
## Overview
17
17
18
-
The general info about this project you can read in the [README.md](https://github.com/TheBestTvarynka/crypto-helper/blob/main/README.md) file. In this document, you will find a more detailed explanation of how it works, how we write components, etc.
18
+
For general info about this project, you can read in the [README.md](https://github.com/TheBestTvarynka/crypto-helper/blob/main/README.md) file. In this document, you will find a more detailed explanation of how it works, how we write components, etc.
19
19
20
20
## How it works
21
21
22
22
> From [README.md](https://github.com/TheBestTvarynka/crypto-helper/blob/main/README.md):
23
23
>
24
24
> Written in [Rust](https://github.com/rust-lang/rust):crab: using [yew](https://github.com/yewstack/yew):sparkles:
25
25
26
-
So, as you can already guess, the Rust code is compiled into [WASM](https://en.wikipedia.org/wiki/WebAssembly) using [trunk](https://trunkrs.dev) and then executes on the client side in the browser. It also means that any heavy computation will affect the client browser performance and can even freeze it (for example, `bcrypt` with 20 rounds).
26
+
So, as you can already guess, the Rust code is compiled into [WASM](https://en.wikipedia.org/wiki/WebAssembly) using [trunk](https://trunkrs.dev) and then executed on the client side in the browser. It also means that any heavy computation will affect the client's browser performance and can even freeze it (for example, `bcrypt` with 20 rounds).
27
27
28
28
The compiled app looks like a bunch of files (`.html`, `.css`, `.wasm`, `.js`). All these files are just served in the user's browser.
Because it's a great framework for building web applications in Rust. It is very familiar to [`React.js`](https://react.dev) devs. The only disadvantage I've seen is styling: yew doesn't have any good tools/libraries for styling at this moment. At this moment, all styles are written in `.scss` files. Classes are used in components via the [`classes!`](https://docs.rs/yew/latest/yew/macro.classes.html) macro.
32
+
Because it's an excellent framework for building web applications in Rust, it is very familiar to [`React.js`](https://react.dev) devs. The only disadvantage I've seen is styling: `yew` doesn't have any good tools/libraries for styling at this moment. At this moment, all styles are written in `.scss` files. Classes are used in components via the [`classes!`](https://docs.rs/yew/latest/yew/macro.classes.html) macro.
33
33
34
34
### So, what do we have:
35
35
36
-
*[Rust](https://www.rust-lang.org/) is the main programming language in this project. It allows us to write highly maintained code with less amount of bugs.
36
+
*[Rust](https://www.rust-lang.org/) is the primary programming language in this project. It allows us to write highly maintainable code with fewer bugs.
37
37
* Fast computations thanks to the [WASM](https://en.wikipedia.org/wiki/WebAssembly).
38
38
39
39
## Code style
40
40
41
-
1. We use the custom [`rustfmt.toml`](https://github.com/TheBestTvarynka/crypto-helper/blob/main/rustfmt.toml) configuration. If you want to change some formatting options then create a pull request with changes and an explanation of your motivation, how it'll help us, etc.
41
+
1. We use the custom [`rustfmt.toml`](https://github.com/TheBestTvarynka/crypto-helper/blob/main/rustfmt.toml) configuration. If you want to change some formatting options, create a pull request with your changes and an explanation of your motivation and how it'll help us.
42
42
2. All code must be formatted using the `cargo fmt`. Run `cargo +nightly fmt --all -- --check`.
43
-
3. All build and clippy warnings must be fixed. Run `cargo clippy -- -D warnings`.
43
+
3. All build and Clippy warnings must be fixed. Run `cargo clippy -- -D warnings`.
44
44
45
45
## Components
46
46
47
47
We have three main groups of components (divided by purpose):
48
48
49
-
1. Generalpurpose components.
49
+
1. General-purpose components.
50
50
2. Crypto-helper related components.
51
-
3.Jwt related components.
51
+
3.JWT-related components.
52
52
4. Other components.
53
53
54
-
### Generalpurpose components
54
+
### General-purpose components
55
55
56
-
Those components can be used on any app page and located in the [`src/common`](https://github.com/TheBestTvarynka/crypto-helper/tree/main/src/common) directory. They are small, without side effects, and have only one special purpose. Examples:
56
+
Those components can be used on any app page and located in the [`src/common`](https://github.com/TheBestTvarynka/crypto-helper/tree/main/src/common) directory. They are small, side-effect-free, and have only one special purpose. Examples:
57
57
58
-
*[`ByteInput`](https://github.com/TheBestTvarynka/crypto-helper/blob/main/src/common/byte_input.rs). This component is used for the bytes entering. You can use it in any place where you need to take any input bytes from the user. It automatically supports many input formats, validation, etc.
58
+
*[`ByteInput`](https://github.com/TheBestTvarynka/crypto-helper/blob/main/src/common/byte_input.rs). This component is used for the bytes entering. You can use it anywhere you need to read input bytes from the user. It automatically supports many input formats, validation, etc.
*[`Switch`](https://github.com/TheBestTvarynka/crypto-helper/blob/main/src/common/switch.rs). Just a regular switch. Can be used to switch between any two options. For example, `encrypt <-> decrypt`, `hash <-> verify`, etc.
61
+
*[`Switch`](https://github.com/TheBestTvarynka/crypto-helper/blob/main/src/common/switch.rs). Just a regular switch. It can be used to switch between any two options. For example, `encrypt <-> decrypt`, `hash <-> verify`, etc.
* There are and will be more common components. The above two are just examples. **If some component was purposespecialized during creation but become common, then it should be moved in the [`src/common`](https://github.com/TheBestTvarynka/crypto-helper/tree/main/src/common) directory.**
64
+
* There are and will be more common components. The above two are just examples. **If some component was purpose-specialized during creation but became common, then it should be moved to the [`src/common`](https://github.com/TheBestTvarynka/crypto-helper/tree/main/src/common) directory.**
65
65
66
66
### Crypto-helper related components
67
67
68
68
In short: all components from the [`src/crypto_helper`](https://github.com/TheBestTvarynka/crypto-helper/tree/main/src/crypto_helper) directory belong to this group. Here are the input/output components for the different algorithms, computations, etc.
69
69
70
70
If some components will be used only on the `/crypto-helper` page, then they should be placed somewhere in the [`src/crypto_helper`](https://github.com/TheBestTvarynka/crypto-helper/tree/main/src/crypto_helper) directory.
71
71
72
-
### Jwtrelated components
72
+
### Jwt-related components
73
73
74
74
In short: all components from the [`src/jwt`](https://github.com/TheBestTvarynka/crypto-helper/tree/main/src/jwt) directory belong to this group. Here are the input/output components for the JWT, its parts parsing/editing/viewing, etc.
75
75
@@ -83,9 +83,9 @@ The `About` page, `Header`, `Footer`, etc.
83
83
84
84
1. Validate on input.
85
85
86
-
Components that take some input from the user usually have their validation rules. For example, the `ByteInput` component with the `ByteFormat::Hex` parameter will require only hex-encoded bytes from the user.
86
+
Components that take user input usually have validation rules. For example, the `ByteInput` component with the `ByteFormat::Hex` parameter will require only hex-encoded bytes from the user.
87
87
88
-
In the app state, we save only validated/parsed data. If the user enters an invalid string, then inform about it. But do not save raw `String` or smth like that in the state. If you look at the `Algorithm` enum, you can see that all input data for algorithms save in a "parsed" state:
88
+
In the app state, we save only validated/parsed data. If the user enters an invalid string, inform them. But do not save raw `String` or smth like that in the state. If you look at the `Algorithm` enum, you can see that all input data for algorithms is saved in a "parsed" state:
89
89
90
90
```rust
91
91
// some fields and structures are omitted
@@ -111,13 +111,13 @@ You won't find any raw Strings. Bytes for hashing/encryption are `Vec<u8>` (not
111
111
112
112
2. Logging.
113
113
114
-
This app has a simple and typical logging system: [`wasm-logger`](https://crates.io/crates/wasm-logger) +[`log`](https://crates.io/crates/log) crates. If you want to log something, then just use any suitable for you macros from the `log` crate. All logs will be written into the browser's console. This is how it looks:
114
+
This app uses a simple, typical logging system: [`tracing-web`](https://docs.rs/tracing-web/latest/tracing_web/) and[`tracing`](https://docs.rs/tracing/latest/tracing/). If you want to log something, then use any suitable macros from the `tracing` crate. All logs will be written into the browser's console. This is how it looks:
115
115
116
116

117
117
118
-
3. Inform user about everything.
118
+
3. Inform the user about everything.
119
119
120
-
You have two main ways how to tell the user that something went wrong:
120
+
You have two main ways to tell the user that something went wrong:
121
121
122
122
* Spawn notifications using the [`use_notifications`](https://yn-docs.qkation.com/yew_notifications/fn.use_notification.html) hook from the [`yew_notifications`](https://github.com/TheBestTvarynka/yew-notifications) crate.
123
123
* Different UI tricks like painting the input component in red, on-page messages, etc. Example:
0 commit comments