Skip to content

Apply SOLID principles: repository layer, service action map, named constants#5

Open
Valamorde wants to merge 1 commit into
refactor/phase-4-hygienefrom
refactor/phase-5-solid
Open

Apply SOLID principles: repository layer, service action map, named constants#5
Valamorde wants to merge 1 commit into
refactor/phase-4-hygienefrom
refactor/phase-5-solid

Conversation

@Valamorde
Copy link
Copy Markdown
Owner

Summary

  • Repository layer (src/repositories/): introduces connectionRepo, sceneRepo, and campaignRepo — plain objects that encapsulate all DynamoDB access patterns. Handlers no longer import DDB command types, key builders, or the table name directly.
  • Services action map: mirrors the sendmessage dispatch pattern. The 8-branch if-chain in services/handler.ts becomes a Record<string, ServiceAction> map; each action moves to its own file under src/handlers/services/.
  • Named constants (src/shared/constants.ts): eliminates magic numbers scattered across the codebase (TTL_SECONDS = 7200, DEFAULT_SCENE_ID = '666', BATCH_SIZE = 25, SCENE_ORDER_SPACING = 1_000_000).
  • Discriminated union for VTTMessage in types.ts — handlers receive narrowed types.
  • Code hygiene: removes console.log(event) in setCampaignData (was logging full requests including headers), replaces the profanity-laden error log in forward.ts with console.error, deduplicates getCurrentSceneId logic shared between dmjoin and playerjoin.

Notes

No observable behavior changes. Existing tests pass without modification — mockClient(DynamoDBDocumentClient) patches the shared singleton that all repositories use internally.

Test plan

  • pnpm test — all tests pass
  • No handler file imports from @aws-sdk/lib-dynamodb directly
  • No handler file imports keys.ts directly
  • No console.log with raw event data in production handlers

…ap, constants

- Repository pattern: connection/scene/campaign repos encapsulate all DDB access;
  no handler imports DDB commands or keys directly
- Services handler split into 7 action files under src/services/actions/ mirroring
  the sendmessage dispatch-map pattern (SRP + OCP)
- Named constants: TTL_SECONDS, DEFAULT_SCENE_ID, BATCH_SIZE, SCENE_ORDER_SPACING
- dmjoin: eliminate duplicated getCurrentSceneId helper via sceneRepo.getDmScene()
- forward.ts: remove profanity log, use console.error for query failure
- All 20 smoke tests pass; cdk synth unchanged
@Valamorde Valamorde force-pushed the refactor/phase-5-solid branch from 5779d1c to f1c2687 Compare April 21, 2026 19:53
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant