[E7.S3] Embedded Server Setup - Ktor Configuration #48

Closed
opened 2025-06-03 21:19:07 +00:00 by rwachters · 0 comments
rwachters commented 2025-06-03 21:19:07 +00:00 (Migrated from github.com)

Description

As a developer, I will implement an embedded Ktor server within the Windows desktop application that provides a local HTTP/WebSocket API for communication between the UI (app module) and backend services (server module). This server will handle API routes for chat sessions, messages, and configuration operations.

Acceptance Criteria

  • Implement a Ktor server in the server module's api.server package.
  • Configure the server to listen only on localhost (127.0.0.1) for security.
  • Auto-select an available port on startup and communicate this port to the frontend.
  • Set up Ktor features:
    • Content negotiation with JSON serialization/deserialization
    • CORS configured for localhost only
    • Proper exception handling with status codes and error responses
    • WebSocket support for future streaming responses
    • Request/response logging for debugging
  • Implement a health check endpoint (GET /api/health) to verify server status.
  • Properly manage the server lifecycle (start on app launch, graceful shutdown).
  • (Cross-cutting Requirement E7.S6): Server setup and request handling use proper coroutine scopes and dispatchers.

Implementation Details

The server implementation should:

  1. Use proper Kotlin Coroutines for async request handling
  2. Follow the layered architecture from E7.S5, with API routes (server.api.server.routes) delegating to service layer implementations (server.service)
  3. Configure proper serialization for DTOs defined in the common module
  4. Ensure the server can only be accessed from the local machine
  5. Include appropriate error handling and logging
  6. Set up versioning paths for the API (/api/v1/*)

Dependencies

  • PR #42 (Initial Multi-Module Project Setup) must be completed first
  • PR #44 (Common Module Data Models) should be completed to ensure proper DTO serialization

Parent Epic

Epic 7: Application Core Framework & Windows 11 Integration

  • E7.S5 - Implement Layered Architecture (this implements the API server layer)
  • E7.S6 - Async Operations & Thread Management (cross-cutting requirement)
  • E1.S2 - API Client Implementation (will use this server)
## Description As a developer, I will implement an embedded Ktor server within the Windows desktop application that provides a local HTTP/WebSocket API for communication between the UI (app module) and backend services (server module). This server will handle API routes for chat sessions, messages, and configuration operations. ## Acceptance Criteria - [ ] Implement a Ktor server in the `server` module's `api.server` package. - [ ] Configure the server to listen only on localhost (`127.0.0.1`) for security. - [ ] Auto-select an available port on startup and communicate this port to the frontend. - [ ] Set up Ktor features: - [ ] Content negotiation with JSON serialization/deserialization - [ ] CORS configured for localhost only - [ ] Proper exception handling with status codes and error responses - [ ] WebSocket support for future streaming responses - [ ] Request/response logging for debugging - [ ] Implement a health check endpoint (`GET /api/health`) to verify server status. - [ ] Properly manage the server lifecycle (start on app launch, graceful shutdown). - [ ] (Cross-cutting Requirement E7.S6): Server setup and request handling use proper coroutine scopes and dispatchers. ## Implementation Details The server implementation should: 1. Use proper Kotlin Coroutines for async request handling 2. Follow the layered architecture from E7.S5, with API routes (`server.api.server.routes`) delegating to service layer implementations (`server.service`) 3. Configure proper serialization for DTOs defined in the common module 4. Ensure the server can only be accessed from the local machine 5. Include appropriate error handling and logging 6. Set up versioning paths for the API (`/api/v1/*`) ## Dependencies - PR #42 (Initial Multi-Module Project Setup) must be completed first - PR #44 (Common Module Data Models) should be completed to ensure proper DTO serialization ## Parent Epic Epic 7: Application Core Framework & Windows 11 Integration ## Related Stories - E7.S5 - Implement Layered Architecture (this implements the API server layer) - E7.S6 - Async Operations & Thread Management (cross-cutting requirement) - E1.S2 - API Client Implementation (will use this server)
Sign in to join this conversation.
No milestone
No project
No assignees
1 participant
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
Torvian.eu/chatbot#48
No description provided.