feat(types): extract shared DTOs into mokosh-types workspace crate (PMS-129) #67

Merged
nrupard merged 3 commits from feat/pms-129-mokosh-types into main 2026-06-04 21:22:00 +02:00
Owner

Summary

  • Extract the five shared DTO modules (auth, contacts, tenants, tickets, time_tracking) from src/modules/<m>/models.rs into a new workspace crate crates/mokosh-types. Both mokosh-server and (in a follow-up PR) mokosh-clients depend on this crate, replacing the manual copy-paste sync described in dev-docs/codebase-state.md cross-cutting issue #12.
  • Each src/modules/<m>/models.rs becomes a 1-line re-export (pub use mokosh_types::<m>::*;) so every super::models::* path inside the consuming module continues to resolve unchanged. Zero type-signature or logic changes; pure relocation.
  • mokosh-types deps are the union of the imports the five model files actually use: serde, chrono, uuid, validator, rust_decimal. No sqlx, no axum, no async runtime so the WASM client can consume it without server-only transitives.

Why now

The project doc (dev-docs/client-server-integration.md) recommended (b) drift CI today, (a) shared crate when a fifth shared module is added. The fifth (time_tracking) landed 2026-06-03; recent server work (PMS-126 tracing, PMS-127 pagination) drifted the trees by ~130 cumulative lines. Doing the shared-crate move now beats first reconciling drift back to the clients repo before adding a CI check.

Follow-up

mokosh-clients needs a matching PR to delete its five models.rs files and add mokosh-types = { path = "../mokosh-server/crates/mokosh-types" } (or via a workspace dep). That work is intentionally NOT in this PR.

Test plan

  • CI: cargo fmt --all --check
  • CI: cargo clippy --all-targets -- -D warnings
  • CI: cargo check --all-targets
  • CI: every integration test still passes (types are bit-for-bit identical, just moved).

Closes PMS-129.

## Summary - Extract the five shared DTO modules (`auth`, `contacts`, `tenants`, `tickets`, `time_tracking`) from `src/modules/<m>/models.rs` into a new workspace crate `crates/mokosh-types`. Both `mokosh-server` and (in a follow-up PR) `mokosh-clients` depend on this crate, replacing the manual copy-paste sync described in `dev-docs/codebase-state.md` cross-cutting issue #12. - Each `src/modules/<m>/models.rs` becomes a 1-line re-export (`pub use mokosh_types::<m>::*;`) so every `super::models::*` path inside the consuming module continues to resolve unchanged. Zero type-signature or logic changes; pure relocation. - `mokosh-types` deps are the union of the imports the five model files actually use: `serde`, `chrono`, `uuid`, `validator`, `rust_decimal`. No `sqlx`, no `axum`, no async runtime so the WASM client can consume it without server-only transitives. ## Why now The project doc (`dev-docs/client-server-integration.md`) recommended `(b) drift CI today, (a) shared crate when a fifth shared module is added`. The fifth (`time_tracking`) landed 2026-06-03; recent server work (PMS-126 tracing, PMS-127 pagination) drifted the trees by ~130 cumulative lines. Doing the shared-crate move now beats first reconciling drift back to the clients repo before adding a CI check. ## Follow-up `mokosh-clients` needs a matching PR to delete its five `models.rs` files and add `mokosh-types = { path = "../mokosh-server/crates/mokosh-types" }` (or via a workspace dep). That work is intentionally NOT in this PR. ## Test plan - [ ] CI: `cargo fmt --all --check` - [ ] CI: `cargo clippy --all-targets -- -D warnings` - [ ] CI: `cargo check --all-targets` - [ ] CI: every integration test still passes (types are bit-for-bit identical, just moved). Closes PMS-129.
feat(types): extract shared DTOs into a mokosh-types workspace crate (PMS-129)
Some checks failed
Check / fmt + clippy + compile + tests (pull_request) Failing after 14s
Build OCI container / Build and push mokosh-api image (push) Failing after 2m2s
5454f62cfb
Closes cross-cutting issue #12 (`dev-docs/codebase-state.md`): the five shared modules (`auth`, `contacts`, `tenants`, `tickets`, `time_tracking`) had their `models.rs` byte-identical between mokosh-server and mokosh-clients via manual copy-paste. The trigger the project doc set for the move from copy-paste to a shared crate was hit on 2026-06-03 when `time_tracking` became the fifth shared module; recent server work (PMS-126 tracing, PMS-127 pagination) then drifted the trees apart by ~130 cumulative lines, which would silently grow.

Adds `crates/mokosh-types` as a workspace member with one `pub mod` per shared module (`auth`, `contacts`, `tenants`, `tickets`, `time_tracking`). The five `src/modules/<m>/models.rs` files become 1-line re-exports (`pub use mokosh_types::<m>::*;`) so every `super::models::*` path inside the consuming module continues to resolve unchanged. No type signature changes, no logic changes; this is a pure relocation. Deps: `serde`, `chrono`, `uuid`, `validator`, `rust_decimal` (the union of the imports the five model files actually use). The crate is pure DTOs - no `sqlx`, no `axum`, no async runtime, so the WASM client can pull it in without dragging in server-only transitives.

The companion change in `mokosh-clients` (delete its five `models.rs` files and depend on `mokosh-types` the same way) ships in a separate PR over there.

#PMS-129
fix(types): replace AppError reference with crate-local AuthRequired marker (PMS-129)
Some checks failed
Check / fmt + clippy + compile + tests (pull_request) Failing after 16s
Build OCI container / Build and push mokosh-api image (push) Failing after 24s
02fa99f4d4
The extracted `AuthState::require_user` / `require_tenant` returned `Result<_, crate::utils::error::AppError>`. After moving the file into `mokosh-types`, `crate::` resolves to that crate, which has no `utils::error::AppError`. Add a tiny `AuthRequired` marker error inside `mokosh-types` and have the two helpers return it; the server-side caller (none today; the existing call sites are inside model tests) can map it to `AppError::Unauthorized` if it adopts the helper later.

#PMS-129
fix(types): add serde_json dep + refresh Cargo.lock for new crate (PMS-129)
All checks were successful
Check / fmt + clippy + compile + tests (pull_request) Successful in 1m0s
Create release / Create release from merged PR (pull_request) Has been skipped
Build OCI container / Build and push mokosh-api image (push) Successful in 3m7s
99ca90e655
The extracted `mokosh-types` crate references `serde_json::Value` in several struct fields (`User::notification_preferences`, `Contact::custom_fields`, `Ticket::custom_fields`, etc.) but the new `Cargo.toml` did not list `serde_json`, so CI failed to compile. Adds the workspace dep and refreshes `Cargo.lock` to register the new workspace member.

Verified locally (`cargo check --workspace`, `cargo fmt --all --check`, `cargo clippy --all-targets -- -D warnings`) via the shared rust-builder image.

#PMS-129
nrupard deleted branch feat/pms-129-mokosh-types 2026-06-04 21:22:00 +02:00
Sign in to join this conversation.
No reviewers
No labels
No milestone
No project
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set

Reference
psa-systems/mokosh-server!67
No description provided.