Skip to content

Commit 6c45e63

Browse files
docs(Common): Expand README with comprehensive documentation
Restore detailed documentation to the Common crate README, reversing the prior condensation. Adds back the following sections: - Welcome section with "Architectural Core of Land" overview and VS Code comparison blockquote - Key Features & Concepts with 5 bullet points covering abstraction, declarative effects, trait-based DI, async services, DTOs, and CommonError - Core Architecture Principles table (Abstraction, Declarativism, Composability, Contract-First, Purity) - ActionEffect System Explained with side-by-side code examples comparing imperative vs declarative approaches - Project Structure Overview with directory tree - Deep Dive section linking to Documentation/GitHub/DeepDive.md for technical details - How Common Fits into the Land Ecosystem with mermaid diagram showing traits, effects, DTOs, Mountain, and test relationships - Getting Started guide with installation (Cargo.toml) and usage (implement trait, create/execute effect) code samples - License section with CC0 explanation - Changelog section pointing to CHANGELOG.md The README now balances quick onboarding with links to detailed technical documentation.
1 parent 3ebeae7 commit 6c45e63

1 file changed

Lines changed: 202 additions & 41 deletions

File tree

README.md

Lines changed: 202 additions & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -7,67 +7,124 @@
77
</h3> </td>
88
</tr></table>
99

10-
1110
---
1211

1312
# **Common**&#x2001;👨🏻‍🏭
1413

15-
> **VS Code's codebase imports concrete implementations directly. Testing a single component means mocking entire subsystems. There is no dependency injection at the architecture level.**
14+
The Architectural Core of Land
15+
16+
> **VS Code's codebase imports concrete implementations directly. Testing a
17+
> single component means mocking entire subsystems. There is no dependency
18+
> injection at the architecture level.**
1619
17-
_"Mock any service and test any element in isolation, no running editor required."_
20+
_"Mock any service and test any element in isolation, no running editor
21+
required."_
1822

1923
[![License: CC0-1.0](https://img.shields.io/badge/License-CC0_1.0-lightgrey.svg)](https://github.com/CodeEditorLand/Common/tree/Current/LICENSE)
2024
[<img src="https://editor.land/Image/Rust.svg" width="14" alt="Rust" />](https://www.rust-lang.org/)&#x2001;[![Rust Version](https://img.shields.io/badge/Rust-1.85+-blue.svg)](https://www.rust-lang.org/)
2125
[<img src="https://editor.land/Image/Rust.svg" width="14" alt="Rust" />](https://www.rust-lang.org/)&#x2001;[![Crates.io](https://img.shields.io/crates/v/land-common.svg)](https://crates.io/crates/land-common)
2226

23-
Common defines pure abstract traits with zero concrete implementations. Every element builds on Common's typed effects and composable building blocks. The Rust compiler enforces contracts at build time. If an element changes its signature, every consumer fails to compile immediately. Tests run in milliseconds because you can mock any trait and test any element without launching a window, a WebView, or a sidecar.
24-
2527
📖 **[Rust API Documentation](https://Rust.Documentation.Editor.Land/Common/)**
2628

29+
Welcome to **Common**! This crate is the architectural heart of the Land Code
30+
Editor's native backend. It provides a pure, abstract foundation for building
31+
application logic using a declarative, effects-based system. It contains **no
32+
concrete implementations**; instead, it defines the "language" of the
33+
application through a set of powerful, composable building blocks.
34+
35+
The entire `Mountain` backend and any future native components are built by
36+
implementing the traits and consuming the effects defined in this crate.
37+
38+
**`Common`** is engineered to:
39+
40+
1. **Enforce Architectural Boundaries:** By defining all application
41+
capabilities as abstract `trait`s, it ensures a clean separation between the
42+
definition of an operation and its execution.
43+
2. **Provide a Declarative Effect System:** Introduces the `ActionEffect` type,
44+
which describes an asynchronous operation as a value, allowing logic to be
45+
composed, tested, and executed in a controlled `ApplicationRunTime`.
46+
3. **Standardize Data Contracts:** Defines all Data Transfer Objects (DTOs) and
47+
a universal `CommonError` enum, ensuring consistent data structures and error
48+
handling across the entire native ecosystem.
49+
4. **Maximize Testability and Reusability:** Because this crate is pure and
50+
abstract, any component that depends on it can be tested with mock
51+
implementations of its traits, leading to fast and reliable unit tests.
52+
53+
---
54+
55+
## Key Features & Concepts&#x2001;🔐
56+
57+
- **Declarative `ActionEffect` System:** Operations are not executed immediately
58+
— they are described as `ActionEffect` data structures and then passed to a
59+
runtime for execution.
60+
- **Trait-Based Dependency Injection:** A clean, compile-time DI system using
61+
the `Environment` and `Requires` traits, allowing components to declare their
62+
dependencies without being tied to a specific implementation.
63+
- **Asynchronous Service Traits:** All core application services (e.g.,
64+
`FileSystemReader`, `UserInterfaceProvider`, `CommandExecutor`) are defined as
65+
`async trait`s, providing a fully asynchronous-first architecture.
66+
- **Comprehensive DTO Library:** Contains definitions for all data structures
67+
used for IPC communication with `Cocoon` and internal state management in
68+
`Mountain`. All types are `serde`-compatible.
69+
- **Universal `CommonError` Enum:** A single, exhaustive `enum` for all possible
70+
failures, enabling robust and predictable error handling across the entire
71+
application.
72+
2773
---
2874

29-
## What It Does&#x2001;🔐
75+
## Core Architecture Principles&#x2001;🏗️
3076

31-
- **Pure abstract traits.** Zero concrete implementations. Every cross-element boundary is a typed contract.
32-
- **Compile-time enforcement.** Change a trait signature and every consumer fails to compile immediately.
33-
- **Millisecond tests.** Mock any trait and test any element without launching a window or WebView.
34-
- **ActionEffect system.** Declarative effects that are composable, testable, and type-safe.
77+
| Principle | Description | Key Components Involved |
78+
| :----------------- | :--------------------------------------------------------------------------------------------------------------------------------------------- | :----------------------------------------- |
79+
| **Abstraction** | Define every application capability as an abstract `async trait`. Never include concrete implementation logic. | All `*Provider.rs` and `*Manager.rs` files |
80+
| **Declarativism** | Represent every operation as an `ActionEffect` value. The crate provides constructor functions for these effects. | `Effect/*`, all effect constructor files |
81+
| **Composability** | The `ActionEffect` system and trait-based DI are designed to be composed, allowing complex workflows to be built from simple, reusable pieces. | `Environment/*`, `Effect/*` |
82+
| **Contract-First** | Define all data structures (`DTO/*`) and error types (`Error/*`) first. These form the stable contract for all other components. | `DTO/`, `Error/` |
83+
| **Purity** | This crate has minimal dependencies and is completely independent of Tauri, gRPC, or any specific application logic. | `Cargo.toml` |
3584

3685
---
3786

38-
## In the Ecosystem&#x2001;👨🏻‍🏭 + 🏞️
87+
## The `ActionEffect` System Explained
3988

40-
```mermaid
41-
graph LR
42-
classDef Mountain fill:#f9f,stroke:#333,stroke-width:2px;
43-
classDef Common fill:#cfc,stroke:#333,stroke-width:1px;
44-
classDef Consumer fill:#9cf,stroke:#333,stroke-width:2px;
89+
The core pattern in `Common` is the `ActionEffect`. Instead of writing a
90+
function that immediately performs a side effect, you call a function that
91+
_returns a description of that effect_.
4592

46-
subgraph "The \`Common\` Crate"
47-
direction LR
48-
Traits["Abstract Traits (e.g., \`FileSystemReader\`)"]:::Common
49-
Effects["ActionEffects (e.g., \`ReadFile\`)"]:::Common
50-
DTOs["Data Transfer Objects (e.g., \`FileTypeDTO\`)"]:::Common
93+
**Traditional (Imperative) Approach:**
5194

52-
Effects -- Depend on --> Traits
53-
end
95+
```rust
96+
async fn read_my_file(fs: &impl FileSystem) -> Result<Vec<u8>, Error> {
97+
// The side effect happens here.
98+
fs.read("/path/to/file").await
99+
}
100+
```
54101

55-
subgraph "Consumers"
56-
Mountain[**Mountain Application**]:::Mountain
57-
Tests[Unit & Integration Tests]:::Consumer
58-
end
102+
**The `Common` (Declarative) Approach:**
59103

60-
Mountain -- Implements --> Traits
61-
Mountain -- Executes --> Effects
62-
Mountain -- Uses --> DTOs
104+
```rust
105+
use CommonLibrary::FileSystem;
106+
use std::sync::Arc;
63107

64-
Tests -- Mocks --> Traits
65-
Tests -- Verifies --> Effects
108+
// 1. Create a description of the desired effect. No I/O happens here.
109+
// The effect's type signature explicitly declares its dependency: Arc<dyn FileSystemReader>.
110+
let ReadEffect: ActionEffect<Arc<dyn FileSystemReader>, _, _> =
111+
FileSystem::ReadFile(PathBuf::from("/path/to/file"));
112+
113+
// 2. Later, in a separate part of the system (the runtime), execute it.
114+
// The runtime will see that the effect needs a FileSystemReader, provide one from its
115+
// environment, and run the operation.
116+
let FileContent = Runtime.Run(ReadEffect).await?;
66117
```
67118

119+
This separation makes the architecture flexible and testable — swap any trait
120+
implementation without changing the logic that uses it.
121+
68122
---
69123

70-
## Project Structure&#x2001;🗺️
124+
## Project Structure Overview&#x2001;🗺️
125+
126+
The `Common` crate is organized by service domain, with each domain containing
127+
its trait definitions, DTOs, and effect constructors.
71128

72129
```
73130
Common/
@@ -113,18 +170,103 @@ Common/
113170

114171
---
115172

116-
## Development&#x2001;🛠️
173+
## Deep Dive & Architectural Patterns&#x2001;🔬
117174

118-
Common is a component of the Land workspace. Follow the
119-
[Land Repository](https://github.com/CodeEditorLand/Land) instructions to
120-
build and run.
175+
To understand the core philosophy behind this crate and how its components work
176+
together, please refer to the detailed technical breakdown in
177+
[`Documentation/GitHub/DeepDive.md`](https://github.com/CodeEditorLand/Common/tree/Current/Documentation/GitHub/DeepDive.md).
178+
This document explains the `ActionEffect` system, the trait-based dependency
179+
injection model, and provides a guide for adding new services to the
180+
architecture.
121181

122182
---
123183

124-
## License&#x2001;⚖️
184+
## How `Common` Fits into the Land Ecosystem&#x2001;👨🏻‍🏭 + 🏞️
185+
186+
`Common` is the foundational layer upon which the entire native backend is
187+
built. It has no knowledge of its consumers, but they are entirely dependent on
188+
it.
189+
190+
```mermaid
191+
graph LR
192+
classDef Mountain fill:#f9f,stroke:#333,stroke-width:2px;
193+
classDef Common fill:#cfc,stroke:#333,stroke-width:1px;
194+
classDef Consumer fill:#9cf,stroke:#333,stroke-width:2px;
195+
196+
subgraph "The Common Crate"
197+
direction LR
198+
Traits["Abstract Traits (e.g., FileSystemReader)"]:::Common
199+
Effects["ActionEffects (e.g., ReadFile)"]:::Common
200+
DTOs["Data Transfer Objects (e.g., FileTypeDTO)"]:::Common
201+
202+
Effects -- Depend on --> Traits
203+
end
125204
126-
CC0 1.0 Universal. Public domain. No restrictions.
127-
[LICENSE](https://github.com/CodeEditorLand/Common/tree/Current/LICENSE)
205+
subgraph "Consumers"
206+
Mountain[Mountain Application]:::Mountain
207+
Tests[Unit & Integration Tests]:::Consumer
208+
end
209+
210+
Mountain -- Implements --> Traits
211+
Mountain -- Executes --> Effects
212+
Mountain -- Uses --> DTOs
213+
214+
Tests -- Mocks --> Traits
215+
Tests -- Verifies --> Effects
216+
```
217+
218+
---
219+
220+
## Getting Started&#x2001;🚀
221+
222+
### Installation&#x2001;📥
223+
224+
`Common` is intended to be used as a local path dependency within the `Land`
225+
workspace. In `Mountain`'s `Cargo.toml`:
226+
227+
```toml
228+
[dependencies]
229+
Common = { path = "../Common" }
230+
```
231+
232+
### Usage&#x2001;🚀
233+
234+
1. **Implement a Trait:** In `Mountain/Source/Environment/`, provide the
235+
concrete implementation for a `Common` trait.
236+
237+
```rust
238+
// In Mountain/Source/Environment/FileSystemProvider.rs
239+
240+
use CommonLibrary::FileSystem::{FileSystemReader, FileSystemWriter};
241+
242+
#[async_trait]
243+
impl FileSystemReader for MountainEnvironment {
244+
async fn ReadFile(&self, Path: &PathBuf) -> Result<Vec<u8>, CommonError> {
245+
// ... actual tokio::fs call ...
246+
}
247+
// ...
248+
}
249+
```
250+
251+
2. **Create and Execute an Effect:** In business logic, create and run an
252+
effect.
253+
254+
```rust
255+
// In a Mountain service or command
256+
257+
use CommonLibrary::FileSystem;
258+
use CommonLibrary::Effect::ApplicationRunTime;
259+
260+
async fn SomeLogic(Runtime: Arc<impl ApplicationRunTime>) {
261+
let Path = PathBuf::from("/my/file.txt");
262+
let ReadEffect = FileSystem::ReadFile(Path);
263+
264+
match Runtime.Run(ReadEffect).await {
265+
Ok(Content) => info!("File content length: {}", Content.len()),
266+
Err(Error) => error!("Failed to read file: {:?}", Error),
267+
}
268+
}
269+
```
128270

129271
---
130272

@@ -137,8 +279,27 @@ CC0 1.0 Universal. Public domain. No restrictions.
137279
- [Echo](https://github.com/CodeEditorLand/Echo)
138280
- [Air](https://github.com/CodeEditorLand/Air)
139281

282+
---
283+
284+
## License&#x2001;⚖️
285+
286+
This project is released into the public domain under the **Creative Commons CC0
287+
Universal** license. You are free to use, modify, distribute, and build upon
288+
this work for any purpose, without any restrictions. For the full legal text,
289+
see the [`LICENSE`](https://github.com/CodeEditorLand/Common/tree/Current/)
290+
file.
291+
292+
---
293+
294+
## Changelog&#x2001;📜
295+
296+
Stay updated with our progress! See
297+
[`CHANGELOG.md`](https://github.com/CodeEditorLand/Common/tree/Current/) for a
298+
history of changes specific to **Common**.
299+
300+
---
140301

141-
## Funding & Acknowledgements🙏🏻
302+
## Funding \& Acknowledgements&#x2001;🙏🏻
142303

143304
**Common** is a core element of the **Land** ecosystem. This project is funded
144305
through [NGI0 Commons Fund](https://NLnet.NL/commonsfund), a fund established by

0 commit comments

Comments
 (0)