feat: v2 rewrite — hexagonal arch, ActivityPub federation, NATS, deployment-ready #1
@@ -3,7 +3,7 @@ use sqlx::PgPool;
|
||||
use std::sync::Arc;
|
||||
|
||||
use activitypub::ThoughtsObjectHandler;
|
||||
use activitypub_base::{ApFederationConfig, FederationData};
|
||||
use activitypub_base::service::ActivityPubService;
|
||||
use domain::{errors::DomainError, events::DomainEvent, ports::EventPublisher};
|
||||
use event_transport::EventPublisherAdapter;
|
||||
use nats::NatsTransport;
|
||||
@@ -16,7 +16,7 @@ use crate::config::Config;
|
||||
/// Everything the binary needs to start serving.
|
||||
pub struct Infrastructure {
|
||||
pub state: AppState,
|
||||
pub fed_config: ApFederationConfig,
|
||||
pub ap_service: Arc<ActivityPubService>,
|
||||
}
|
||||
|
||||
struct NoOpEventPublisher;
|
||||
@@ -61,24 +61,26 @@ pub async fn build(cfg: &Config) -> Infrastructure {
|
||||
};
|
||||
|
||||
// 3. ActivityPub federation
|
||||
let fed_data = FederationData::new(
|
||||
Arc::new(PostgresFederationRepository::new(pool.clone())),
|
||||
Arc::new(PostgresApUserRepository::new(
|
||||
pool.clone(),
|
||||
let ap_service = Arc::new(
|
||||
ActivityPubService::new(
|
||||
Arc::new(PostgresFederationRepository::new(pool.clone())),
|
||||
Arc::new(PostgresApUserRepository::new(
|
||||
pool.clone(),
|
||||
cfg.base_url.clone(),
|
||||
)),
|
||||
Arc::new(ThoughtsObjectHandler::new(
|
||||
Arc::new(PgActivityPubRepository::new(pool.clone())),
|
||||
&cfg.base_url,
|
||||
)),
|
||||
cfg.base_url.clone(),
|
||||
)),
|
||||
Arc::new(ThoughtsObjectHandler::new(
|
||||
Arc::new(PgActivityPubRepository::new(pool.clone())),
|
||||
&cfg.base_url,
|
||||
)),
|
||||
cfg.base_url.clone(),
|
||||
cfg.allow_registration,
|
||||
"thoughts".to_string(),
|
||||
None,
|
||||
);
|
||||
let fed_config = ApFederationConfig::new(fed_data, cfg.debug)
|
||||
cfg.allow_registration,
|
||||
"thoughts".to_string(),
|
||||
cfg.debug,
|
||||
None,
|
||||
)
|
||||
.await
|
||||
.expect("Failed to build federation config");
|
||||
.expect("Failed to build ActivityPubService"),
|
||||
);
|
||||
|
||||
// 4. Application state
|
||||
let state = AppState {
|
||||
@@ -107,7 +109,8 @@ pub async fn build(cfg: &Config) -> Infrastructure {
|
||||
)),
|
||||
hasher: Arc::new(auth::Argon2PasswordHasher),
|
||||
events: event_publisher,
|
||||
federation: ap_service.clone() as Arc<dyn domain::ports::FederationActionPort>,
|
||||
};
|
||||
|
||||
Infrastructure { state, fed_config }
|
||||
Infrastructure { state, ap_service }
|
||||
}
|
||||
|
||||
@@ -67,7 +67,7 @@ async fn main() {
|
||||
"/users/{username}/following",
|
||||
axum::routing::get(following_handler),
|
||||
)
|
||||
.layer(infra.fed_config.middleware());
|
||||
.layer(infra.ap_service.federation_config().middleware());
|
||||
|
||||
let base = presentation::routes::router()
|
||||
.merge(ap_router)
|
||||
|
||||
@@ -19,4 +19,5 @@ pub struct AppState {
|
||||
pub auth: Arc<dyn AuthService>,
|
||||
pub hasher: Arc<dyn PasswordHasher>,
|
||||
pub events: Arc<dyn EventPublisher>,
|
||||
pub federation: Arc<dyn FederationActionPort>,
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user