9.7 KiB
9.7 KiB
Here’s a summary of potential additions and adjustments:
New Technical Epics/Stories (or significant additions to existing ones):
-
New Technical Story (or Sub-tasks under Epic 1): Workflow Orchestration Setup
- Goal: Implement the core workflow orchestration mechanism.
- Stories/Tasks:
- Story: Define and Implement
workflow_runsTable andWorkflowTrackerService- Acceptance Criteria:
- Supabase migration created for the
workflow_runstable as defined in the architecture document. WorkflowTrackerServiceimplemented insupabase/functions/_shared/with methods for initiating, updating step details, incrementing counters, failing, and completing workflow runs.- Service includes robust error handling and logging via Pino.
- Unit tests for
WorkflowTrackerServiceachieve >80% coverage.
- Supabase migration created for the
- Acceptance Criteria:
- Story: Implement
CheckWorkflowCompletionService(Supabase Cron Function)- Acceptance Criteria:
- Supabase Function
check-workflow-completion-servicecreated. - Function queries
workflow_runsand related tables to determine if a workflow run is ready to progress to the next major stage (e.g., from summarization to newsletter generation, from podcast initiated to delivery). - Function correctly updates
workflow_runs.statusand invokes the next appropriate service function (e.g.,NewsletterGenerationService) via a Supabase database webhook trigger or direct HTTP call if preferred. - Logic for handling podcast link availability (delay/retry/timeout before sending email) is implemented here or in conjunction with
NewsletterGenerationService. - The function is configurable to be run periodically via Vercel Cron Jobs (or
pg_cron). - Comprehensive logging implemented using Pino.
- Unit tests achieve >80% coverage.
- Supabase Function
- Acceptance Criteria:
- Story: Implement Workflow Status API Endpoint (
/api/system/workflow-status/{jobId})- Acceptance Criteria:
- Next.js API Route Handler created at
/api/system/workflow-status/{jobId}. - Endpoint secured with API Key authentication.
- Retrieves and returns status details from the
workflow_runstable for the givenjobId. - Handles cases where
jobIdis not found (404). - Unit and integration tests for the API endpoint.
- Next.js API Route Handler created at
- Acceptance Criteria:
- Story: Define and Implement
-
New Technical Story (under Epic 3: AI-Powered Content Summarization): Implement LLM Facade and Configuration
- Goal: Create a flexible interface for interacting with different LLM providers for summarization.
- Story: Design and Implement
LLMFacade- Acceptance Criteria:
LLMFacadeinterface and concrete implementations (e.g.,OllamaAdapter,RemoteLLMApiAdapter) created insupabase/functions/_shared/llm-facade.ts.- Factory function implemented to select the LLM adapter based on environment variables (
LLM_PROVIDER_TYPE,OLLAMA_API_URL,REMOTE_LLM_API_KEY,REMOTE_LLM_API_URL,LLM_MODEL_NAME). - Facades handle making requests to the respective LLM APIs and parsing responses.
- Error handling and retry logic for transient API errors implemented within the facade.
- Unit tests for the facade and adapters (mocking actual HTTP calls) achieve >80% coverage.
- Acceptance Criteria:
-
New Technical Story (or Sub-task under relevant Epics): Implement Facades for External Services
- Goal: Encapsulate all external service interactions.
- Stories/Tasks:
- Story: Implement
HNAlgoliaFacade(for HN Content Service) - Story: Implement
PlayHTFacade(for Podcast Generation Service) - Story: Implement
NodemailerFacade(for Newsletter Generation Service) - Acceptance Criteria (General for each facade):
- Facade created in
supabase/functions/_shared/. - Handles API authentication, request formation, and response parsing for the specific service.
- Implements basic retry logic for transient errors.
- Unit tests (mocking actual HTTP/library calls) achieve >80% coverage.
- Facade created in
- Story: Implement
Adjustments to Existing Epics/Stories:
-
Epic 1: Project Initialization, Setup, and HN Content Acquisition
- Story 1.3 (API and CLI trigger):
- Modify AC: "The API endpoint (
/api/system/trigger-workflow) creates an entry in theworkflow_runstable and returns thejobId." - Add AC: "The API endpoint is secured via an API key."
- Add AC: "The CLI command invokes the
/api/system/trigger-workflowendpoint or directly interacts withWorkflowTrackerServiceto start a new workflow run." - Add AC: "All interactions with the API or CLI that initiate a workflow must record the
workflow_run_idin logs."
- Modify AC: "The API endpoint (
- Story 1.4 (Retrieve HN Posts & Comments):
- Modify AC: "Retrieved data (posts and comments) is stored in Supabase database, linked to the current
workflow_run_id." - Add AC: "Upon completion, the service updates the
workflow_runstable with status and details (e.g., number of posts fetched) viaWorkflowTrackerService." - Add AC: "For each new
hn_postsrecord, a database event/webhook is configured to trigger the Article Scraping Service (Epic 2), passinghn_post_idandworkflow_run_id."
- Modify AC: "Retrieved data (posts and comments) is stored in Supabase database, linked to the current
- Story 1.3 (API and CLI trigger):
-
Epic 2: Article Scraping
- Story 2.2 & 2.3 (Scrape & Store):
- Modify AC: "Scraped article content is stored in the
scraped_articlestable, linked to thehn_post_idand the currentworkflow_run_id." - Add AC: "The
scraping_statusand anyerror_messageare recorded in thescraped_articlestable." - Add AC: "Upon completion of scraping an article (success or failure), the service updates the
workflow_runs.details(e.g., incrementing scraped counts) viaWorkflowTrackerService." - Add AC: "For each successfully scraped article, a database event/webhook is configured to trigger the Summarization Service (Epic 3) for that article, passing
scraped_article_idandworkflow_run_id."
- Modify AC: "Scraped article content is stored in the
- Story 2.4 (Trigger scraping via API/CLI): This story might become redundant if the main workflow trigger (Story 1.3) handles the entire pipeline initiation. If retained for isolated testing, ensure it also works with the
workflow_run_idconcept.
- Story 2.2 & 2.3 (Scrape & Store):
-
Epic 3: AI-Powered Content Summarization
- Story 3.1 (Integrate AI summarization): Refine to "Integrate with
LLMFacadefor summarization." - Story 3.2 & 3.3 (Generate Summaries):
- Modify AC: "Summaries are stored in
article_summariesorcomment_summariestables, linked to thescraped_article_id(for articles) orhn_post_id(for comments), and the currentworkflow_run_id." - Add AC: "The service retrieves prompts from the
summarization_promptstable." - Add AC: "Upon completion of each summarization task, the service updates
workflow_runs.details(e.g., incrementing summaries generated counts) viaWorkflowTrackerService." - Add AC (Implicit): The
CheckWorkflowCompletionServicewill monitor these tables to determine when all summarization for aworkflow_run_idis complete.
- Modify AC: "Summaries are stored in
- Story 3.1 (Integrate AI summarization): Refine to "Integrate with
-
Epic 4: Automated Newsletter Creation and Distribution
- Story 4.1 & 4.2 (Retrieve template & Generate Newsletter):
- Modify AC: "The
NewsletterGenerationServiceis triggered by theCheckWorkflowCompletionServicewhen all summaries for aworkflow_run_idare ready." - Add AC: "The service retrieves the newsletter template from
newsletter_templatestable and summaries associated with theworkflow_run_id." - Modify AC: "Generated newsletter is stored in the
newsletterstable, linked to theworkflow_run_id." - Add AC: "The service updates
workflow_runs.statusto 'generating_podcast' (or similar) after initiating podcast generation."
- Modify AC: "The
- Story 4.3 (Send newsletter):
- Modify AC: "The
NewsletterGenerationService(specifically, its delivery part) is triggered byCheckWorkflowCompletionServiceonce the podcast link is available for theworkflow_run_id(or timeout/failure occurred for podcast step)." - Modify AC: "Implements conditional logic for podcast link inclusion and handles delay/retry as per PRD, coordinated by
CheckWorkflowCompletionService." - Add AC: "Updates
newsletters.delivery_statusandworkflow_runs.statusto 'completed' or 'failed' viaWorkflowTrackerService."
- Modify AC: "The
- Story 4.1 & 4.2 (Retrieve template & Generate Newsletter):
-
Epic 5: Podcast Generation Integration
- Story 5.1, 5.2, 5.3 (Integrate Play.ht, Send Content, Webhook Handler):
- Modify AC: The
PodcastGenerationServiceis invoked byNewsletterGenerationService(orCheckWorkflowCompletionService) for a specificworkflow_run_idandnewsletter_id. - Modify AC: The
podcast_playht_job_idandpodcast_statusare stored in thenewsletterstable. - Modify AC: The
PlayHTWebhookHandlerAPI(/api/webhooks/playht) updates thenewsletterstable with the podcast URL and status. - Add AC: The
PlayHTWebhookHandlerAPIalso updates theworkflow_runs.detailswith the podcast status viaWorkflowTrackerServicefor the relevantworkflow_run_id(needs to be looked up from thenewsletter_idorplayht_job_id).
- Modify AC: The
- Story 5.1, 5.2, 5.3 (Integrate Play.ht, Send Content, Webhook Handler):
General Considerations for all Epics:
- Error Handling & Logging: Reinforce that all services must implement robust error handling, log extensively using Pino (including
workflow_run_id), and updateworkflow_runsappropriately on success or failure using theWorkflowTrackerService. - Database Webhook/Trigger Configuration: Add technical tasks/stories related to setting up the actual Supabase database webhooks (e.g.,
pg_netcalls) or triggers that connect the pipeline steps (e.g.,hn_postsinsert triggeringArticleScrapingService). This is a crucial implementation detail of the event-driven flow. - Environment Variable Management: A story to create and document
docs/environment-vars.mdand set up.env.example.