Skip to content

Commit

Permalink
Fix workspace parsing (#8)
Browse files Browse the repository at this point in the history
  • Loading branch information
pfazzi authored Jan 16, 2025
1 parent cabe913 commit 6ba68ba
Show file tree
Hide file tree
Showing 33 changed files with 625 additions and 188 deletions.
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -4,3 +4,6 @@
/examples/sample_project/Cargo.lock
/examples/acme_project/target/
/examples/acme_project/Cargo.lock
/examples/workspace_project/target
/examples/workspace_project/Cargo.lock
/examples/sbarter
6 changes: 4 additions & 2 deletions Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "rust_arkitect"
version = "0.1.1"
version = "0.1.2"
authors = ["Patrick Luca Fazzi <patrick91@live.it>"]
edition = "2021"
description = "rust_arkitect is a lightweight library for defining and validating architectural rules in Rust projects"
Expand All @@ -19,4 +19,6 @@ syn = { version = "2.0", features = ["full", "visit"] }
quote = "1.0"
ansi_term = "0.12"
env_logger = "0.11"
log = "0.4.22"
log = "0.4.22"
toml = "0.7"
serde = "1"
18 changes: 9 additions & 9 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -25,15 +25,15 @@ use rust_arkitect::dsl::{ArchitecturalRules, Arkitect, Project};

#[test]
fn test_architectural_rules() {
let project = Project::from_relative_path(file!(), "./../src");
let project = Project::from_relative_path(file!(), "./../");

let rules = ArchitecturalRules::define()
.component("Domain")
.located_at("crate::domain")
.located_at("my_project::domain")
.allow_external_dependencies(&["std::fmt"])
.must_not_depend_on_anything()
.component("Application")
.located_at("crate::application")
.located_at("my_project::application")
.may_depend_on(&["Domain"])
.finalize();

Expand Down Expand Up @@ -70,20 +70,20 @@ You can define and test architectural rules:
```rust
#[test]
fn test_architecture_baseline() {
let project = Project::from_relative_path(file!(), "./../src");
let project = Project::from_relative_path(file!(), "./../");

let rules = ArchitecturalRules::define()
.component("Application")
.located_at("crate::application")
.located_at("my_project::application")
.may_depend_on(&["Domain"])

.component("Domain")
.located_at("crate::domain")
.located_at("my_project::domain")
.allow_external_dependencies(&["std::fmt"])
.must_not_depend_on_anything()

.component("Infrastructure")
.located_at("crate::infrastructure")
.located_at("my_project::infrastructure")
.allow_external_dependencies(&["serde"])
.may_depend_on(&["Domain", "Application"])

Expand Down Expand Up @@ -126,8 +126,8 @@ RUST_LOG=error cargo test -- --nocapture
```
Example Output:
```plaintext
[2024-12-30T12:17:08Z ERROR rust_arkitect::dsl] 🟥 Rule crate::event_sourcing may depend on [std::fmt] violated: forbidden dependencies to [crate::domain::events::event] in file:///users/random/projects/acme_project/src/event_sourcing/events.rs
[2024-12-30T12:17:08Z ERROR rust_arkitect::dsl] 🟥 Rule crate::utils may not depend on any modules violated: forbidden dependencies to [crate::infrastructure::redis::*] in file:///users/random/projects/acme_project/src/utils/refill.rs
[2024-12-30T12:17:08Z ERROR rust_arkitect::dsl] 🟥 Rule my_project::event_sourcing may depend on [std::fmt] violated: forbidden dependencies to [my_project::domain::events::event] in file:///users/random/projects/acme_project/src/event_sourcing/events.rs
[2024-12-30T12:17:08Z ERROR rust_arkitect::dsl] 🟥 Rule my_project::utils may not depend on any modules violated: forbidden dependencies to [my_project::infrastructure::redis::*] in file:///users/random/projects/acme_project/src/utils/refill.rs
```

# 😇 Built with Its Own Rules
Expand Down
10 changes: 0 additions & 10 deletions examples/acme_project/Cargo.toml

This file was deleted.

54 changes: 0 additions & 54 deletions examples/acme_project/lib.rs

This file was deleted.

2 changes: 1 addition & 1 deletion examples/sample_project/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -4,4 +4,4 @@ version = "0.1.0"
edition = "2021"

[dependencies]
rust_arkitect = "0.1"
rust_arkitect = { path = "./../../" }
19 changes: 10 additions & 9 deletions examples/sample_project/src/architecture_rules_test.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,15 +7,15 @@ fn test_vertical_slices_architecture_rules() {
#[rustfmt::skip]
let rules = ArchitecturalRules::define()
.component("Conversion")
.located_at("crate::conversion")
.located_at("sample_project::conversion")
.may_depend_on(&["Contracts"])

.component("PolicyManagement")
.located_at("crate::policy_management")
.located_at("sample_project::policy_management")
.may_depend_on(&["Contracts"])

.component("Contracts")
.located_at("crate::contracts")
.located_at("sample_project::contracts")
.must_not_depend_on_anything()

.finalize();
Expand All @@ -36,15 +36,15 @@ fn test_mvc_architecture_rules() {
#[rustfmt::skip]
let rules = ArchitecturalRules::define()
.component("Model")
.located_at("crate::policy_management::model")
.located_at("sample_project::policy_management::model")
.must_not_depend_on_anything()

.component("Repository")
.located_at("crate::policy_management::repository")
.located_at("sample_project::policy_management::repository")
.may_depend_on(&["Model"])

.component("Controller")
.located_at("crate::policy_management::controller")
.located_at("sample_project::policy_management::controller")
.may_depend_on(&["Repository", "Model"])
.finalize();

Expand All @@ -62,15 +62,16 @@ fn test_three_tier_architecture() {
#[rustfmt::skip]
let rules = ArchitecturalRules::define()
.component("Application")
.located_at("crate::conversion::application")
.located_at("sample_project::conversion::application")
.allow_external_dependencies(&["sample_project::contract"])
.may_depend_on(&["Domain"])

.component("Domain")
.located_at("crate::conversion::domain")
.located_at("sample_project::conversion::domain")
.must_not_depend_on_anything()

.component("Infrastructure")
.located_at("crate::conversion::infrastructure")
.located_at("sample_project::conversion::infrastructure")
.may_depend_on(&["Domain", "Application"])

.finalize();
Expand Down
2 changes: 2 additions & 0 deletions examples/sample_project/src/conversion/application.rs
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
use crate::contracts::external_services::service_call_one;
use crate::conversion::domain::{domain_function_1, domain_function_2};

pub fn application_function() {
domain_function_1();
domain_function_2();
service_call_one();
}

mod use_cases {
Expand Down
1 change: 1 addition & 0 deletions examples/sample_project/src/lib.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
mod architecture_rules_test;
mod contracts;
mod conversion;
mod policy_management;

Expand Down
8 changes: 8 additions & 0 deletions examples/workspace_project/Cargo.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
[workspace]
members = [
"application",
"contracts",
"conversion",
"policy_management",
"tests"
]
8 changes: 8 additions & 0 deletions examples/workspace_project/application/Cargo.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
[package]
name = "application"
version = "0.1.0"
edition = "2021"

[dependencies]
conversion = { path = "./../conversion"}
policy_management = { path = "./../policy_management"}
8 changes: 8 additions & 0 deletions examples/workspace_project/application/src/lib.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
use conversion::application::application_function;
use policy_management::controller::controller;

#[allow(dead_code)]
fn main() {
application_function();
controller();
}
1 change: 1 addition & 0 deletions examples/workspace_project/assets/file_1.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Random
4 changes: 4 additions & 0 deletions examples/workspace_project/contracts/Cargo.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
[package]
name = "contracts"
version = "0.1.0"
edition = "2021"
3 changes: 3 additions & 0 deletions examples/workspace_project/contracts/src/external_services.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
pub fn service_call_one() {
println!("call_one");
}
1 change: 1 addition & 0 deletions examples/workspace_project/contracts/src/lib.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
pub mod external_services;
7 changes: 7 additions & 0 deletions examples/workspace_project/conversion/Cargo.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
[package]
name = "conversion"
version = "0.1.0"
edition = "2021"

[dependencies]
contracts = { path = "../contracts"}
15 changes: 15 additions & 0 deletions examples/workspace_project/conversion/src/application.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
use crate::domain::{domain_function_1, domain_function_2};

pub fn application_function() {
domain_function_1();
domain_function_2();
}

mod use_cases {
use crate::domain::domain_function_2;

#[allow(dead_code)]
fn application_use_case() {
domain_function_2();
}
}
7 changes: 7 additions & 0 deletions examples/workspace_project/conversion/src/domain.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
pub fn domain_function_1() {
println!("Domain function 1");
}

pub fn domain_function_2() {
println!("Domain function 2");
}
8 changes: 8 additions & 0 deletions examples/workspace_project/conversion/src/infrastructure.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
use super::application::application_function;
use contracts::external_services::service_call_one;

pub fn infrastructure_function() {
application_function();
println!("Infrastructure function");
service_call_one();
}
3 changes: 3 additions & 0 deletions examples/workspace_project/conversion/src/lib.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
pub mod application;
mod domain;
mod infrastructure;
4 changes: 4 additions & 0 deletions examples/workspace_project/policy_management/Cargo.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
[package]
name = "policy_management"
version = "0.1.0"
edition = "2021"
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
use crate::model::Policy;
use crate::repository::get;

pub fn controller() -> Policy {
let policy = get();

policy
}
3 changes: 3 additions & 0 deletions examples/workspace_project/policy_management/src/lib.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
pub mod controller;
mod model;
mod repository;
3 changes: 3 additions & 0 deletions examples/workspace_project/policy_management/src/model.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
pub struct Policy {
pub id: String,
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
use crate::model::Policy;

pub fn get() -> Policy {
Policy {
id: String::from("1234"),
}
}
7 changes: 7 additions & 0 deletions examples/workspace_project/tests/Cargo.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
[package]
name = "tests"
version = "0.1.0"
edition = "2021"

[dependencies]
rust_arkitect = { path = "./../../../" }
Loading

0 comments on commit 6ba68ba

Please sign in to comment.