4.2 KiB
4.2 KiB
sessionId
| sessionId |
|---|
| session-260729-161736-1psq |
Requirements
Overview & Goals
Migrate all DTOs (Data Transfer Objects) currently located in src/routes/<module>/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/<module>/dto.rstosrc/domain/<module>/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.
- Moving all DTO files from
- 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.rsmust be accessible undersrc/domain/. - All handlers, mappers, and services must compile successfully after updating their imports.
- OpenAPI schema generation via
utoipamust continue to function correctly with the relocated DTOs.
Technical Design
Current Implementation
Currently, each feature module in src/routes/<module>/ 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 insrc/domain/dto/mod.rsand re-exported or accessed viacrate::domain::dto::<module>::*). - Import Path Updates: Update all
use crate::routes::<module>::dto::*imports touse crate::domain::dto::<module>::*(or viacrate::domain::dto::*).
Proposed Changes
- Create a
src/domain/dto/directory with individual module files (e.g.,auth.rs,user.rs, etc.) and asrc/domain/dto/mod.rs. - Move the contents of
src/routes/<module>/dto.rstosrc/domain/dto/<module>.rs. - Update
src/domain/mod.rsto declarepub mod dto;and configuresrc/domain/dto/mod.rs. - Update all files referencing
src/routes/<module>::dtoto point tosrc/domain::dto::<module>(orcrate::domain::dto::<module>). - Remove
dto.rsfrom eachsrc/routes/<module>/directory and updatesrc/routes/<module>/mod.rs.
File Structure Changes
- Added:
src/domain/dto/mod.rssrc/domain/dto/auth.rs(and other DTO files like user, channel, message, category, role, attachment, core, etc.)
- Modified:
src/domain/mod.rssrc/routes/<module>/mod.rsfor each migrated module (removingpub mod dto;)- All handler, mapper, and route files importing the old DTO paths.
- Removed:
src/routes/<module>/dto.rsfor all modules.
Testing
Validation Approach
- Run
cargo checkto verify that all type references and module paths compile correctly. - Run
cargo testto ensure tests pass and there are no runtime regressions. - Inspect OpenAPI generation / documentation endpoints to ensure
utoipacorrectly registers all DTO schemas.
Delivery Steps
Step 1: Create domain DTO directory and module structure
- Create
src/domain/dto/directory along withsrc/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;insrc/domain/mod.rs.
Step 2: Migrate DTO files to src/domain/dto/ and update imports
- Move each
dto.rsfile fromsrc/routes/<module>/dto.rsintosrc/domain/dto/<module>.rs. - Update all import statements across handlers, mappers, services, and route files in
src/routes/and elsewhere to referencecrate::domain::dto::<module>::*. - Remove the old
dto.rsfiles fromsrc/routes/<module>/and removepub mod dto;fromsrc/routes/<module>/mod.rs.
Step 3: Verify compilation and test suite
- Run
cargo checkandcargo testto 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.