-
Notifications
You must be signed in to change notification settings - Fork 5
Refactor/phase2 workspace #11
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Conversation
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Context: - Phase: PH2 - Task: PH2-T01 Initialize Cargo workspace and member crates Changes: - Converted root Cargo.toml into a workspace manifest with members manja, manja-core, manja-http, manja-ticker, and manja-extras - Moved the existing crate configuration from the root Cargo.toml into manja/Cargo.toml, preserving package metadata, dependencies, and features - Relocated the original crate sources from src/, tests/, and examples/ into manja/src/, manja/tests/, and manja/examples/ - Added stub crates manja-core, manja-http, manja-ticker, and manja-extras with minimal Cargo.toml metadata and placeholder src/lib.rs modules Notes: - Tests: cargo build --all - Follow-up: wire manja-core, manja-http, manja-ticker, and manja-extras into the main crate in PH2-T02–PH2-T07
Context: - Phase: PH2 - Task: PH2-T02 Move shared types and errors into manja-core Changes: - Added serde/serde_json/chrono/secrecy dependencies and real module roots to manja-core for pure models and API-level errors - Moved Kite HTTP models from manja into manja-core::models and re-exported them via the manja kite::connect::models facade - Extracted KiteApiError and KiteApiException into manja-core::error and updated ManjaError to wrap the core error types - Wired the manja crate to depend on manja-core while preserving the existing public re-exports at the manja crate root - Introduced a resolve_fixture_path helper for tests and updated market and session tests to load fixtures correctly in a workspace layout - Ensured workspace builds and tests succeed with cargo build --all and cargo test -p manja Notes: - Tests: cargo build --all; cargo test -p manja - Follow-up: wire manja-http, manja-ticker, and manja-extras to consume manja-core types in PH2-T04–PH2-T07
Context: - Phase: PH2 - Task: PH2-T03 Define reusable traits in manja-core Changes: - Added transport-agnostic config/auth/login traits in manja-core/src/traits.rs - Exposed new core traits module via manja-core/src/lib.rs - Implemented CoreApiEndpoints and CoreCredentials for Config in manja/src/kite/connect/config.rs - Updated KiteAuth HeaderMap impl in manja/src/kite/traits.rs to use DefaultKiteAuth from manja-core - Imported CoreAuth into manja/src/kite/traits.rs so DefaultKiteAuth methods are in scope Notes: - Tests: cargo build --all
Context: - Phase: PH2 - Task: PH2-T04 Move HTTP client and API groups into manja-http Changes: - Implemented manja-http crate HTTP config and credentials using manja-core traits (manja-http/src/config.rs, manja-http/src/credentials.rs) - Added dedicated HTTP error type and result alias that wrap manja-core::error::KiteApiError (manja-http/src/error.rs) - Ported HTTPClient implementation to manja-http, using reqwest, optional backoff, and manja-core models for responses (manja-http/src/client.rs) - Implemented HTTP API groups (session, user, orders, portfolio, market, margins, charges) against HTTPClient and manja-core types (manja-http/src/api/*.rs) - Added checksum helper and CSV parsing utilities plus wired new modules and dependencies into manja-http (manja-http/src/utils.rs, manja-http/Cargo.toml, manja-http/src/lib.rs) Notes: - Tests: cargo build -p manja-http && cargo build --all - Follow-up: PH2-T05 should rewire manja::ManjaClient and kite::connect to depend on manja-http and gradually retire the old in-crate HTTP client and API modules
Context: - Phase: PH2 - Task: PH2-T05 Rewire ManjaClient to use manja-http Changes: - Added manja-http as a workspace dependency in manja/Cargo.toml so the facade crate can share the HTTP transport layer - Refactored manja::kite::connect::client::HTTPClient into a thin wrapper over manja_http::HTTPClient, mapping manja_http::error::Error into ManjaError to preserve the existing error surface - Kept the existing Config, KiteCredentials, and UserSession types in manja by adding helpers to convert between facade config and manja-http config (http_config_from_manja_config, config_from_http_config) - Left the ManjaClient facade API unchanged while ensuring its HTTP behavior now flows through the wrapped transport client backed by manja-http - Verified the refactor by running cargo check -p manja and cargo test -p manja to ensure the crate still builds and tests pass Notes: - Tests: cargo check -p manja; cargo test -p manja (default features) - Design: chose a wrapper-based approach so existing public types and imports (kite::connect::client::HTTPClient, crate::kite::error::Result) remain stable while HTTP behavior is delegated to the manja-http crate
Context:
- Phase: PH2
- Task: PH2-T06 Move WebSocket ticker into manja-ticker
Changes:
- Added ticker client, stream, and models modules to
manja-ticker/src/{client.rs,stream.rs,models/**} and wired crate
exports via manja-ticker/src/lib.rs
- Declared WebSocket runtime dependencies (tokio-tungstenite,
tungstenite, stubborn-io, tracing, serde, serde_json,
secrecy, futures-util, manja-core) in
manja-ticker/Cargo.toml and integrated UserSession from
manja_core::models in manja-ticker/src/stream.rs
- Updated manja/Cargo.toml to depend on manja-ticker as an
optional crate and changed the websocket feature to enable
dep:manja-ticker instead of direct WebSocket dependencies
- Replaced the in-crate ticker implementation under
manja/src/kite/ticker/** with a thin facade in
manja/src/kite/ticker/mod.rs that re-exports
KiteStreamCredentials, StreamState, Mode, TickerRequest,
TickerStream, and WebSocketClient from manja-ticker
- Adjusted manja/src/main.rs to log ticker StreamState using
to_uri() and removed the direct tungstenite import now provided
via manja-ticker
- Preserved the public ticker API used by
manja/examples/ticker.rs by keeping the
`manja::kite::ticker::{KiteStreamCredentials, Mode, StreamState,
Notes:
- Tests: cargo build --all (default features)
- Follow-up: add focused ticker tests in manja-ticker and update
docs/examples per PH2-T08/PH2-T09
Context:
- Phase: PH2
- Task: PH2-T07 Move WebDriver login into manja-extras
Changes:
- Implemented WebDriver/TOTP-based login runtime in manja-extras
(login::{chrome, flow, totp, error}) and re-exported helpers from
manja-extras/src/lib.rs
- Switched manja’s webdriver-login feature to depend on optional
manja-extras instead of directly on fantoccini, totp-rs, and base32
- Refactored manja::kite::login::{browser_login_flow, launch_browser,
generate_totp} into thin facades that delegate to manja-extras using
manja-core::traits::CoreConfig
- Updated ManjaError to decouple from fantoccini types and added an explicit
From<manja_extras::login::LoginError> mapping for WebDriver/TOTP failures
- Added README “Advanced WebDriver login usage” section and extended
manja-extras crate-level docs to show how to depend on and call manja-extras
directly
Notes:
- Tests: cargo check --workspace
- Design: manja-extras::browser_login_flow now takes C: CoreConfig + Send,
with a boxed KiteConfig adapter in manja to keep existing public signatures
while satisfying Send bounds for KiteLoginFlow
Context: - Phase: PH2 - Task: PH2-T08 Relocate and Adjust Tests Across Crates Changes: - Moved HTTP unit tests and fixture helpers from manja/src/kite/connect/** into manja-http/src/api/** and manja-http/src/test_utils.rs - Added mockito as a dev-dependency in manja-http and gated its test_utils module behind #[cfg(test)] for crate-local test usage - Added ticker unit tests in manja-ticker for TickerRequest JSON shape and StreamState/SubscriptionStream URI and message generation - Introduced facade-level integration tests in manja/tests/facade_http.rs and manja/tests/facade_ticker.rs plus shared helpers in manja/tests/support.rs - Removed legacy HTTP test modules and test_utils from the manja crate so HTTP behavior is unit-tested only in manja-http and facade tests use ManjaClient - Verified workspace test coherence so cargo test --all runs HTTP, ticker, and facade tests without duplication Notes: - Tests: - cargo test -p manja-http - cargo test -p manja-ticker - cargo test -p manja - cargo test --all - User/profile and margins fixtures remain missing; corresponding user API tests are kept commented in manja-http::api::user for future re-enabling
Context: - Phase: PH2 - Task: PH2-T09 Adjust examples to use workspace and facade Changes: - Updated ticker example fallback message to use cargo run -p manja --example ticker --features websocket - Confirmed all examples import only from the manja facade crate and not internal workspace crates - Extended README with a workspace-aware Examples section showing how to run basic_http, quotes, and ticker from the workspace root Notes: - Tests: cargo check -p manja --examples
Context: - Phase: PH2 - Task: PH2-T10 Document workspace architecture Changes: - Added ARCHITECTURE.md describing workspace crates, responsibilities, and feature layering across manja, manja-core, manja-http, manja-ticker, and manja-extras - Updated README.md introduction to mention the multi-crate workspace and point readers to ARCHITECTURE.md for detailed architecture docs - Updated .gitignore to ignore a workspace-level main.rs helper binary Notes: - Tests: not run (documentation-only and ignore-rule changes)
Context: - Phase: PH2 - Task: PH2-T11 Update CI for manja workspace Changes: - Updated .github/workflows/ci.yml to run cargo build against the manja crate using cargo build -p manja for all matrix profiles - Updated CI test step to run cargo test -p manja with the existing feature matrix (default, no-default-features, websocket, webdriver-login) - Updated CI doctest step to run cargo test -p manja --doc so docs are validated for each feature profile Notes: - Tests: workflow not executed locally; change scopes existing CI commands to the manja package to match the multi-crate workspace layout
Context: - Phase: PH2 - Task: PH2-T11 Update CI for manja workspace Changes: - Extended .github/workflows/ci.yml feature matrix to add http-backoff (HTTP + backoff only) profile - Added http-websocket-backoff profile to validate ticker + backoff combination without webdriver or dotenv - Added http-webdriver-login-backoff profile to validate webdriver login + backoff combination without websocket or dotenv - Kept build, unit/integration tests, and doctests running for each new profile against the manja crate Notes: - Tests: workflow not executed locally; changes only adjust CI matrix configuration and reuse existing steps
Context: - Phase: PH2 - Task: PH2-T08 Relocate and adjust tests across crates Changes: - Updated manja/tests/facade_ticker.rs to be compiled only when the websocket feature is enabled via a crate-level `#![cfg(feature = - Ensured ticker facade tests no longer reference the optional manja-ticker crate in HTTP-only and non-websocket CI profiles - Verified cargo test -p manja across multiple feature profiles (no-default-features, backoff, websocket, websocket+backoff, webdriver-login, webdriver-login+backoff) completes successfully Notes: - Tests: cargo test -p manja with the above feature combinations ran locally and passed; remaining warnings are unrelated (unused code)
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Phase 2 refactors the
manjaSDK from a single crate into a multi-crateCargo workspace. The new layout introduces clear boundaries between core
types, HTTP transport, WebSocket ticker, and WebDriver/TOTP login extras
while preserving the existing public facade via
ManjaClient. The changealso wires feature flags and CI so that different dependency footprints
(
websocket,webdriver-login, etc.) can be tested explicitly.This PR corresponds to the Phase 2 backlog items:
manja-coremanja-coremanja-httpManjaClientto usemanja-httpmanja-tickermanja-extrasMotivation
The original
manjacrate bundled all responsibilities into a singlepackage:
This made the crate harder to evolve and heavier than necessary for many
use cases. Phase 2 addresses the architecture gaps outlined in
.data/artifacts/review-v0/01-architecture.mdby:vs extras).
WebDriver-enabled usage).
ManjaClient) for typical users,while offering lower-level crates for advanced consumers.
High-Level Changes
manja-corecrate.
manja-httpcrate.manja-tickercrate.manja-extrascrate.manjato act as a facade over the other crates (viaManjaClientandmanja::kite::*), gated by feature flags.ARCHITECTURE.mdto describethe new workspace architecture.
manjacrate within theworkspace.
Detailed Task Breakdown
PH2-T01 – Initialize Cargo workspace and member crates
Cargo.tomlinto a workspace manifest with[workspace]and members:manjamanja-coremanja-httpmanja-tickermanja-extrasmanja/Cargo.toml, makingmanjathe primary facade crate within the workspace.Cargo.tomlandsrc/lib.rsstubs for the new crates toensure the workspace builds end-to-end.
PH2-T02 – Move shared types and errors into
manja-coremanja-corecrate with:manja-core/src/lib.rsas the crate entry point.manja-core/src/models/**hosting HTTP DTOs and enums that model KiteAPI responses and request structures (user/session, orders, portfolio,
market, margins, etc.).
manja-core/src/error.rsdefining core error types includingKiteApiErrorandKiteApiException.manjacrate intomanja-core, updating imports throughout the workspace to usemanja_core::models::*andmanja_core::error::*.manja-coredoes not depend onreqwest, Tokio, WebSocket, orWebDriver libraries, keeping it transport-agnostic and suitable for reuse
in non-networked contexts.
PH2-T03 – Define reusable traits in
manja-coremanja-core/src/traits.rswith non-IO, transport-agnostic traits:CoreApiEndpoints– base/api/login/redirect URL accessors.CoreCredentials– strongly-typed API key/secret, user ID/password,and TOTP key accessors (using
Secret<String>).CoreConfig– convenience trait alias combining endpoints andcredentials.
CoreAuthandDefaultKiteAuth– helpers for constructing authheaders such as
token {api_key}:{access_token}.CoreLoginFlow– abstraction for async login flows that produce arequest token, without tying to any particular runtime or driver.
manja,manja-http,manja-extras) toleverage these traits where appropriate, decoupling configuration and
auth semantics from specific HTTP/WebDriver implementations.
PH2-T04 – Move HTTP client and API groups into
manja-httpmanja-httpcrate with:manja-http/src/lib.rsas the crate root with crate-level docs.utilities:
manja-http/src/api/**– typed API groups for Kite domains:Session,User,Orders,Portfolio,Market,Margins,Charges.manja-http/src/client.rs–HTTPClientimplementation.manja-http/src/config.rs,credentials.rs,utils.rs,error.rs, andtest_utils.rs.manja/src/kite/connect/**intomanja-http, updating all imports to usemanja-coretypes and theinternal config/credentials types.
reqwestand backoff logic live solely inmanja-http, soHTTP-specific dependencies are isolated to this crate.
PH2-T05 – Rewire
ManjaClientto usemanja-httpManjaClientfacade inmanja/src/client.rs:manja_http::HTTPClientinternally.new(Config)andfrom_env()constructors that delegate tothe underlying
HTTPClientconfiguration.user(),session(),orders(),portfolio(),market(),margins(),charges().manja/src/lib.rsto:ManjaClient.manja-coresoexisting import patterns (e.g.,
use manja::UserProfile) continue towork.
all HTTP calls through
manja-http.PH2-T06 – Move WebSocket ticker into
manja-tickermanja-tickercrate:manja-ticker/src/lib.rswith crate-level docs explaining its role asthe WebSocket ticker implementation crate.
client,models, andstreammodules for:WebSocketClientandTickerStream.StreamStateandKiteStreamCredentials.ModeandTickerRequesttypes.manjafacade to:manja::kite::tickeras a thin re-export layer overmanja-tickerwhen thewebsocketfeature is enabled.typical users.
PH2-T07 – Move WebDriver login into
manja-extrasmanja-extrascrate:manja-extras/src/lib.rswith crate-level docs clarifying its role asan optional extras crate.
manja-extras/src/login/**containing:chrome– WebDriver/Chrome launcher.flow– browser-based login orchestration.totp– Base32 + TOTP utilities.error–LoginErrorand related result type.manja-extras:browser_login_flow,launch_browser,generate_totp.manjafacade to:manja::kite::loginwhen thewebdriver-loginfeature is enabled.PH2-T08 – Relocate and adjust tests across crates
manja/tests:facade_http.rs– exercises theManjaClientfacade against mockedHTTP endpoints for margins and charges, using shared fixtures from
kiteconnect-mocks.facade_ticker.rs– ensures that ticker types and URI construction areaccessible via the facade and remain consistent with the underlying
manja-tickerimplementation.manja-http(e.g.,test_utils.rs) to localize HTTP test harness code to the HTTP crate.manja-coremodels and errors from their new locations,aligning the test suite with the new crate boundaries.
PH2-T09 – Adjust examples to use workspace and facade
manja/examples/*to import from themanjafacade crate ratherthan internal modules:
basic_http.rs– demonstrates login and basic user/margins flows viaManjaClient.quotes.rsandticker.rs– demonstrate market data and ticker usagethrough facade-level APIs.
README.mdusecargo run -p manjawith theappropriate examples and features, reflecting the workspace layout.
PH2-T10 – Document workspace architecture
ARCHITECTURE.mdat the workspace root:manja– facade crate and example binary.manja-core– shared models, errors, and traits.manja-http– HTTP client and API groups.manja-ticker– WebSocket ticker runtime.manja-extras– WebDriver/TOTP login helpers.manjafacade vs. the internal crates(
manja-core,manja-http,manja-ticker,manja-extras).websocket,webdriver-login,backoff,dotenv-config) map onto the workspace crates.README.mdto:ARCHITECTURE.mdfor a detailed overview of crateboundaries and dependency patterns.
PH2-T11 – Update CI to match workspace + feature matrix
.github/workflows/ci.ymlto run builds and tests against themanjacrate within the workspace for each matrix profile:cargo build -p manja ${{ matrix.profile['cargo-flags'] }}cargo test -p manja ${{ matrix.profile['cargo-flags'] }} -- --nocapturecargo test -p manja ${{ matrix.profile['cargo-flags'] }} --docdefaultno-default-featureshttp-websocket(--no-default-features --features websocket)http-webdriver-login(--no-default-features --features webdriver-login)the facade crate under multiple feature combinations.
Public API & Migration Notes
manja::ManjaClient, with the same high-level usage as in Phase 1.
use manja::ManjaClient;use manja::{KiteApiResponse, UserProfile, UserSession, ...};should not require code changes; the facade and key types are re-exported
from their new crate locations.
manja-corefor shared models and errors only.manja-httpfor lower-level HTTP client access.manja-tickerormanja-extrasdirectly when they want tointegrate the ticker or WebDriver login flows into custom runtimes.
Testing & CI
cargo test -p manja(with default features) exercises the facade andintegration tests.
manja-httpand can be run viacargo test -p manja-http.tests and crate-local tests.
manjaunder multiple feature profiles, ensuring the facade crate remains
healthy across configurations.