Untangle Spike architecture with bridge pattern #9

Merged
probablycorey merged 3 commits from probablycorey/ai-project-structure into main 2026-03-09 23:03:30 +00:00

Refactored Spike into three focused, decoupled libs:

  • gitea/ — Pure API client and types (no Discord, no DB)
  • discord/ — Discord bot client, events, slash commands
  • bridge/ — New integration layer: webhook handler, DB mappings, Discord helpers

Dependencies flow one way: bridge → gitea and bridge → discord. Eliminated circular imports. Each lib has a barrel (index.ts) and README documenting its public API.

Also added self-contained integration tests for webhooks (each test creates its own PR, callback-based expectations, retry logic for Gitea merge timing) and unit tests for pure functions.

Refactored Spike into three focused, decoupled libs: - **gitea/** — Pure API client and types (no Discord, no DB) - **discord/** — Discord bot client, events, slash commands - **bridge/** — New integration layer: webhook handler, DB mappings, Discord helpers Dependencies flow one way: bridge → gitea and bridge → discord. Eliminated circular imports. Each lib has a barrel (index.ts) and README documenting its public API. Also added self-contained integration tests for webhooks (each test creates its own PR, callback-based expectations, retry logic for Gitea merge timing) and unit tests for pure functions.
probablycorey added 2 commits 2026-03-09 23:02:51 +00:00
Split the monolithic gitea/helpers.ts (which had Discord imports and created circular dependencies) into three focused libs:

1. **gitea/** — Pure API client: fetchPR, fetchReviewComments, convertUsername, threadName. No side effects or external deps.

2. **discord/** — Discord client setup: bot login, event listeners, slash commands. Now isolated from Gitea internals.

3. **bridge/** — New integration layer: webhook handler, DB mappings (Gitea PR ↔ Discord thread), Discord helpers, and createPRComment.

Dependencies now flow one direction: bridge → gitea and bridge → discord. No circular imports.

Added:
- Barrel exports (index.ts) for each lib with public API
- README.md for each lib documenting the barrel exports
- Comprehensive spike README.md with setup guide and architecture explanation
- Integration tests for webhooks (callback-based, no race conditions)
- Unit tests for pure API functions
- CLAUDE.md with links to each lib's README

This architecture makes it possible for AI to understand a lib by reading just its README, keeping context focused and small.

Co-Authored-By: Claude Haiku 4.5 <noreply@anthropic.com>
Make webhook tests independent with isolated PRs and retry on merge timing issues
Some checks failed
CI / test (pull_request) Has been cancelled
a71bf2d492
Each test now creates its own PR and cleans up after itself. Tests no longer depend on shared state or ordering, making them resilient to failures.

Added retry logic to mergePR for Gitea's 404/405 responses while computing mergeability. Used crypto.randomUUID() for unique branch names instead of Date.now() to eliminate collision risk.
probablycorey added 1 commit 2026-03-09 23:03:26 +00:00
Merge branch 'main' into probablycorey/ai-project-structure
Some checks failed
CI / test (pull_request) Has been cancelled
4bcec23c22
probablycorey merged commit f7684cf141 into main 2026-03-09 23:03:30 +00:00
Sign in to join this conversation.
No reviewers
No Label
No Milestone
No project
No Assignees
1 Participants
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: probablycorey/workshop#9
No description provided.