Skip to content

feat: Protocol interfaces + TypedDict schemas for target architecture (#496)#640

Merged
ShaerWare merged 1 commit intomainfrom
server/protocol-interfaces
Mar 23, 2026
Merged

feat: Protocol interfaces + TypedDict schemas for target architecture (#496)#640
ShaerWare merged 1 commit intomainfrom
server/protocol-interfaces

Conversation

@ShaerWare
Copy link
Owner

Summary

  • Define target Protocol interfaces for 4 domains: KnowledgeService, LLMService, ChatService, AuthService
  • Define ideal TypedDict response schemas: SearchResult, SessionInfo, MessageInfo, ProviderInfo, UserInfo, LoginResult, etc.
  • Protocols describe the architectural north star — current implementations do not yet conform
  • TypedDicts are backward-compatible with dict (minimal blast radius for future adoption)
  • 28 unit tests verify schema construction and protocol method signatures

Structure

modules/{domain}/schemas.py    ← TypedDict response types
modules/{domain}/protocols.py  ← Protocol service contracts
Domain Protocol Key methods
Knowledge KnowledgeService search, retrieve_context, get_collections, sync_documents, find_faq_answer
LLM LLMService generate, stream, resolve_backend, list_providers
Chat ChatService create_session, send_message, stream_message, get_history, share_session
Auth AuthService authenticate, validate_token, get_permissions, has_permission, get_roles

Design decisions

  • Ideal, not current: Protocols describe what should be, not wrapping current fragmented services
  • TypedDict over dataclass: backward-compatible with dict — existing session["id"] code works unchanged
  • runtime_checkable: enables isinstance() checks for future DI validation
  • No DI changes: Protocols are purely additive — no service wiring changes
  • TCH suppressed in tests: test files need runtime imports for schema construction

Test plan

  • 28 new tests pass (pytest tests/unit/test_protocols.py)
  • All 134 unit tests pass (no regressions)
  • CI checks (lint-backend, lint-frontend, security)

Closes #496

🤖 Generated with Claude Code

…#496)

Define ideal service contracts as Protocol classes and response types
as TypedDicts for four domains: Knowledge, LLM, Chat, Auth.

Protocols describe the *target* architecture (north star), not the
current implementation. Current services do not yet conform — the
Protocols guide future refactoring toward clean, unified facades.

Schemas:
- knowledge/schemas.py: SearchResult, CollectionInfo, DocumentInfo, SyncResult, FAQEntryInfo
- llm/schemas.py: LLMConfig, ProviderInfo, LLMParams, StreamChunk, ToolCall, TokenUsage
- chat/schemas.py: SessionInfo, SessionSummary, MessageInfo, StreamChunk, ShareInfo
- core/schemas.py: UserInfo, TokenInfo, LoginResult, PermissionMap, RoleInfo, WorkspaceInfo

Protocols:
- knowledge/protocols.py: KnowledgeService (search + collections + documents + FAQ)
- llm/protocols.py: LLMService (generate + stream + resolve_backend + list_providers)
- chat/protocols.py: ChatService (sessions + messages + generation + sharing)
- core/protocols.py: AuthService (auth + permissions + users + roles + workspaces)

28 unit tests covering schema construction and protocol method signatures.
TCH lint rule suppressed for test files (runtime type usage).

Closes #496

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
@ShaerWare ShaerWare merged commit 429fa79 into main Mar 23, 2026
3 checks passed
@ShaerWare ShaerWare deleted the server/protocol-interfaces branch March 23, 2026 20:20
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.

Фаза 6: Protocol interfaces — типизация контрактов между модулями

2 participants