From 98050bb77015fa0d36e0f87cada4f4c7bf01c4e5 Mon Sep 17 00:00:00 2001 From: Nell Date: Wed, 29 Jul 2026 16:25:12 +0200 Subject: [PATCH] init --- .junie/plans/migrate-dtos-to-domain.md | 71 ++++++++++++++++++++++++++ src/core/mod.rs | 12 ++--- src/services/mod.rs | 4 +- 3 files changed, 76 insertions(+), 11 deletions(-) create mode 100644 .junie/plans/migrate-dtos-to-domain.md diff --git a/.junie/plans/migrate-dtos-to-domain.md b/.junie/plans/migrate-dtos-to-domain.md new file mode 100644 index 0000000..f3dfd32 --- /dev/null +++ b/.junie/plans/migrate-dtos-to-domain.md @@ -0,0 +1,71 @@ +--- +sessionId: session-260729-161736-1psq +--- + +# Requirements + +### Overview & Goals +Migrate all DTOs (Data Transfer Objects) currently located in `src/routes//dto.rs` into the `src/domain/` directory. This aligns the project architecture by separating domain types and DTOs from HTTP routing and handler implementation details. + +### Scope +- **In Scope**: + - Moving all DTO files from `src/routes//dto.rs` to `src/domain//dto.rs` (or equivalent domain submodules). + - Updating all imports across the codebase (`src/routes/...`, handlers, mappers, etc.) to reference the new domain locations. + - Re-exporting or organizing modules cleanly in `src/domain/mod.rs`. +- **Out of Scope**: + - Modifying business logic or changing DTO field definitions. + - Changing database models (`src/models/`). + +### Functional Requirements +- Every DTO previously defined in `src/routes/*/dto.rs` must be accessible under `src/domain/`. +- All handlers, mappers, and services must compile successfully after updating their imports. +- OpenAPI schema generation via `utoipa` must continue to function correctly with the relocated DTOs. + +# Technical Design + +### Current Implementation +Currently, each feature module in `src/routes//` contains a `dto.rs` file (along with `handlers.rs`, `mapper.rs`, `routes.rs`, `service.rs`, `domain.rs`). Meanwhile, `src/domain/` currently only contains `events/` and `mod.rs`. + +### Key Decisions +- **Domain DTO Folder Organization**: Centralize all DTOs into a dedicated `src/domain/dto/` folder (e.g., `src/domain/dto/auth.rs`, `src/domain/dto/user.rs`, etc., declared in `src/domain/dto/mod.rs` and re-exported or accessed via `crate::domain::dto::::*`). +- **Import Path Updates**: Update all `use crate::routes::::dto::*` imports to `use crate::domain::dto::::*` (or via `crate::domain::dto::*`). + +### Proposed Changes +1. Create a `src/domain/dto/` directory with individual module files (e.g., `auth.rs`, `user.rs`, etc.) and a `src/domain/dto/mod.rs`. +2. Move the contents of `src/routes//dto.rs` to `src/domain/dto/.rs`. +3. Update `src/domain/mod.rs` to declare `pub mod dto;` and configure `src/domain/dto/mod.rs`. +4. Update all files referencing `src/routes/::dto` to point to `src/domain::dto::` (or `crate::domain::dto::`). +5. Remove `dto.rs` from each `src/routes//` directory and update `src/routes//mod.rs`. + +### File Structure Changes +- **Added**: + - `src/domain/dto/mod.rs` + - `src/domain/dto/auth.rs` (and other DTO files like user, channel, message, category, role, attachment, core, etc.) +- **Modified**: + - `src/domain/mod.rs` + - `src/routes//mod.rs` for each migrated module (removing `pub mod dto;`) + - All handler, mapper, and route files importing the old DTO paths. +- **Removed**: + - `src/routes//dto.rs` for all modules. + +# Testing + +### Validation Approach +- Run `cargo check` to verify that all type references and module paths compile correctly. +- Run `cargo test` to ensure tests pass and there are no runtime regressions. +- Inspect OpenAPI generation / documentation endpoints to ensure `utoipa` correctly registers all DTO schemas. + +# Delivery Steps + +### Step 1: Create domain DTO directory and module structure +- Create `src/domain/dto/` directory along with `src/domain/dto/mod.rs`. +- Set up module declarations for each DTO file (auth, user, channel, message, category, role, attachment, core, etc.) under `src/domain/dto/`. +- Expose `pub mod dto;` in `src/domain/mod.rs`. + +### Step 2: Migrate DTO files to `src/domain/dto/` and update imports +- Move each `dto.rs` file from `src/routes//dto.rs` into `src/domain/dto/.rs`. +- Update all import statements across handlers, mappers, services, and route files in `src/routes/` and elsewhere to reference `crate::domain::dto::::*`. +- Remove the old `dto.rs` files from `src/routes//` and remove `pub mod dto;` from `src/routes//mod.rs`. + +### Step 3: Verify compilation and test suite +- Run `cargo check` and `cargo test` to ensure all DTO types resolve correctly and there are no broken imports or compilation errors.\n- Verify OpenAPI schema generation (`utoipa`) correctly picks up the migrated DTO schemas. \ No newline at end of file diff --git a/src/core/mod.rs b/src/core/mod.rs index a9e6887..c31da1e 100644 --- a/src/core/mod.rs +++ b/src/core/mod.rs @@ -1,12 +1,12 @@ pub mod state; use crate::config::AppConfig; -use crate::core::state::Services; use crate::database::Database; use crate::http::server::HttpServer; use crate::metrics::{AppMetrics, reporter}; use crate::repositories::Repositories; use crate::routes::gateway::GatewayManager; +use crate::services::Services; use crate::udp::server::UdpServer; use event_bus::EventBus; use migration::{Migrator, MigratorTrait}; @@ -17,7 +17,6 @@ use uuid::Uuid; pub struct App { pub state: AppState, - pub services: Services, } impl App { @@ -70,8 +69,6 @@ impl App { let services = Arc::new(Services::new(repositories.clone(), event_bus.clone())); - let permission_sync = PermissionSyncService::new(repositories.clone(), event_bus.clone()); - let state = AppState { db, config: Arc::new(config), @@ -81,13 +78,10 @@ impl App { metrics, gateway, event_bus, + services, }; - let services = Services { - permission_sync: Arc::new(permission_sync), - }; - - Ok(Self { state, services }) + Ok(Self { state }) } pub async fn run(self) -> Result<(), Box> { diff --git a/src/services/mod.rs b/src/services/mod.rs index 4d5a897..c3f7d61 100644 --- a/src/services/mod.rs +++ b/src/services/mod.rs @@ -16,8 +16,8 @@ pub struct ServicesContext { #[derive(Debug, Clone)] pub struct Services { - permission_sync: Arc, - server_order: Arc, + pub permission_sync: Arc, + pub server_order: Arc, } impl Services {