AgentSkillsCN

thor-code-patterns

为TypeScript引擎(Fastify + tRPC)、TanStack Start管理面板,以及Python ML服务,提供专属于Thor的架构模式。在构建功能、添加流程、打通数据流,或编写测试时参考这些模式。

SKILL.md
--- frontmatter
name: thor-code-patterns
description: Thor-specific architectural patterns for the TypeScript engine (Fastify + tRPC), TanStack Start admin panel, and Python ML service. Reference when building features, adding procedures, wiring data flows, or writing tests.

Thor Code Patterns

Architectural patterns specific to the Thor trading bot. These define how features are built — the data flow, library wiring, and conventions that every new piece of code should follow.

For universal React/JS performance rules, see docs/react-best-practices/SKILL.md.

Patterns

PatternFileScope
Error Handlingerror-handling.mdAppErrorCode enum, TRPCError with structured cause, BFF error propagation, 6 UI error display channels
tRPC Router & Procedurestrpc.mdDomain-based routers, procedure naming, two-hop subscription demux, middleware chain, full procedure listing
Type Systemtype-system.mdZod 4 .meta(), compositional atoms, branded types, decimal.js serialization, no as/any, as const satisfies, parse-at-boundaries
Database Accessdatabase.mdThin service layer, transaction composability, soft delete, baseColumns/auditColumns, Drizzle schema files
BullMQ Jobsbullmq.mdSelf-contained job files, queue naming, retry/backoff/timeout, dual-write results (DB + SSE)
Environment & Configurationenv-config.mdZod-validated env vars, Pydantic BaseSettings, runtime config boundary, constants strategy
Logging & Correlationlogging.mdPino base logger, OTel trace ID correlation, request-scoped children, log levels, standard log shapes
React Componentsreact.mdRoute loader prefetch, query + subscription bridge hooks, TanStack Form flow, loading/error/empty states, table pagination
Events & Subscriptionsevents.mdTyped event envelope (15 types), mitt emitter, three-layer SSE pipeline, domain-filtered BFF subscriptions
Testing (Universal)testing.mdFile location, naming, two-layer factories, mocking strategy, test structure conventions, superfluous test detection, broad-to-narrow debugging
Unit & Integration Testingtesting-unit-integration.mdRTL query priority, userEvent, async handling, custom hooks, timers, forms, MSW tRPC interception, tRPC procedure tests, testcontainers, Python conventions
E2E Testingtesting-e2e.mdPlaywright file organization, storageState auth, selector priority, waiting strategies, tRPC API mocking, test isolation, axe-core a11y
Code Reviewcode-review.mdReview workflow, severity levels, review area → rule file mapping, TanStack Start-specific review points, when NOT to flag
Formsform.mdTanStack Form validation, Standard Schema gotchas, defaultValues reset bug, dual-error system, persistence, operation ID cancellation
UI Componentsui-components.mdCVA variants, HugeIcons, theme tokens, shadcn/ui directory structure, component catalog, adding new components
Project Structureproject-structure.mdPlacement rules, path aliases, model domain structure, expected domains, utility functions layer
Auth & Securityauth.mdSession cache busting, server-side auth authority, sign-out invalidation, auth file locations