Transferring API requests to the backend#32
Conversation
Adding .gitkeep for PR creation (default mode). This file will be removed when the task is complete. Issue: Payel-git-ol#31
Working session summaryDone. PR #32 is finalized and ready for review. SummaryIssue #31 ("Transferring API requests to the backend") is fully addressed on branch What was delivered (every issue requirement met):
Verification:
One deliberate scoping note (documented in the PR): This summary was automatically extracted from the AI working session output. |
🤖 Solution Draft LogThis log file contains the complete execution trace of the AI solution draft process. 💰 Cost: $5.110814📊 Context and tokens usage:Claude Opus 4.8: (2 sub-sessions)
Total: (6.7K new + 168.6K cache writes + 5.4M cache reads) input tokens, 52.1K output tokens, $5.110814 cost 🤖 Models used:
📎 Log file uploaded as Gist (2348KB)Now working session is ended, feel free to review and add any feedback on the solution draft. |
✅ Ready to mergeThis pull request is now ready to be merged:
Monitored by hive-mind with --auto-restart-until-mergeable flag |
Transferring API requests to the backend (#31)
Moves the entire API surface to the backend and routes the CLI through it along the
cli → GraphQL → backend → apipath. Both ends own a repository, and everyGraphQL class lives in its own file in a
graphql/folder on each side. Themonolithic
App.tsxand the flatsrc/cli/layout are broken into folders.Backend —
src/backend/graphql/facade.ts—TRADEFAST_FACADEtoken +TradefastApiFacadeinterface (the onlycontract the backend depends on; keeps backend files minimalist).
dto/— one@ObjectTypeper file:table-count,strategy,analytics,status,symbol-run,run-report.repository.ts—@Injectable() TradefastRepositorymaps the facade onto theDTOs (
status/strategies/start/update/clear).tradefast.resolver.ts— thin resolver delegating to the repository.index.ts— barrel.src/backend/graphql.ts(185 lines) is deleted.Frontend —
src/cli/graphql/client.ts— minimalGraphqlClient(fetch-based POST,GraphqlRequestError).table-count,analytics,strategy,status,symbol-run,run-report,clear) holding the typed document + result types,fully decoupled from the backend Nest decorators.
repository.ts—GraphqlTradefastRepository: the only place the CLI talksto the API.
status,strategiesandclearcommands now make their requeststhrough this repository (spinning up the in-process backend).
CLI split into folders —
src/cli/components/Theme,Exchange,Interval,Mode,Currency,Level,Platform) are extracted fromApp.tsxinto one file each, shrinkingApp.tsxby ~270 lines.Scope note
start/updateand the interactive TUI are intentionally not rerouted throughGraphQL: the GraphQL
RunReportDtodoes not model the analysis/validation/intervalfields the trade-log renderer needs, and the TUI relies on progress streaming and
local config mutation not expressed in the schema. Only the cleanly-mappable
headless commands go through the new path, keeping the backend minimalist.
Implementation note
Nest DI uses explicit
@Inject(...)tokens throughout — the esbuild-based bundler(tsx/tsup) does not emit decorator metadata, so type-only DI fails silently.
Tests
tests/graphql-repository.test.ts(new): end-to-endGraphqlTradefastRepository→ in-process backend assertions for every method, plus
GraphqlClienterror paths.tests/backend.test.ts: updated to construct the resolver with the repository.typecheckclean,tsupbuild green.Fixes #31