Skip to content

[Refactor-Unified-Server-Chat]: Server Chat Response Simplifying #246

@Castro19

Description

@Castro19

💡 User Story

As a developer, I want to consolidate the chat message flow into a single backend endpoint so that the frontend remains simple, consistent, and synced with the server-side source of truth.


📖 Description

We are refactoring the current message lifecycle to reduce complexity and improve maintainability. Currently, the frontend handles multiple responsibilities: generating IDs, managing log creation/updating, and calling multiple backend endpoints. This leads to redundant state management, increased surface area for bugs, and difficult onboarding for new contributors.

The new plan involves:

  • Creating a single backend endpoint (/chat-message) that handles:
    • Generating IDs and timestamps
    • Checking for new vs. existing chats
    • Creating or updating the chat log
    • Streaming the assistant response
    • Sending a final JSON payload to the frontend
  • Shifting all orchestration responsibility to the backend
  • Simplifying the frontend to call only one Redux thunk
  • Ensuring the Redux state is updated from the server's authoritative response

This change improves reliability, error handling, and developer clarity.


✅ Acceptance Criteria

  • ✅ A single endpoint handles message submission, log creation/update, and streaming
  • ✅ Backend generates all IDs and timestamps
  • ✅ Final server response includes updated log, messages, and metadata
  • ✅ Frontend uses one Redux thunk (sendMessageThunk) to send message and stream assistant response
  • ✅ Redux state is updated solely from server response
  • ✅ Errors during any part of the process are properly handled and reported to the frontend

📌 Technical Details

  • Server will verify if a chat ID is new or existing and take appropriate action
  • The final JSON response should include chatId, messages, timestamp, and optional title
  • Redux logSlice and messageSlice remain separate but are updated together from server response
  • Frontend no longer creates UUIDs or timestamps
  • Streaming remains functional, with partial updates handled via SSE or chunked fetch

🖼️ UI/UX Mockups (If applicable)

N/A – No UI changes, backend-focused refactor


📎 Related Issues or Dependencies

  • Related to #XX (Streaming improvements)
  • Related to #XX (Log structure updates)

🚀 Priority & Story Points

  • Priority: High
  • Story Points: 5

Metadata

Metadata

Assignees

Labels

enhancementImprove an existing feature

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions