Learn
Application
Ports

Ports

Ports are one of the key components that facilitate the separation of concerns, making systems more modular and adaptable.

  • Interaction Points: Serve as the primary points of interaction between the application's core logic and the outside world.
  • Abstractions: Define abstract interfaces for the core application to communicate with external elements like databases, user interfaces, and external services.

Implementing Ports

Ports are implemented as interfaces or abstract classes, depending on the programming language used.

application/src/port.rs
pub use crate::projection::TodoListProjection;
pub use domain::{todolist_event::TodoListEvent, todolist_state::TodoList};
use framework::*;
 
#[async_trait]
#[delegate]
pub trait TodoListStore {
    async fn pull(&self) -> AnyResult<TodoList>;
    async fn push(&self, events: &[TodoListEvent]) -> AnyResult<()>;
}
 
#[async_trait]
#[delegate]
pub trait TodoListRepository {
    async fn fetch(&self) -> AnyResult<TodoListProjection>;
    async fn save(&self, projection: &TodoListProjection) -> AnyResult<()>;
}