Extending Sparrow¶
Use this page as a practical checklist when adding functionality.
Add a normal client feature¶
- Decide which existing feature module owns the behavior. Do not create a new module for one screen unless it has a real independent responsibility.
- Add/extend unsuffixed domain models and a one-purpose
*UseCase. - Add/extend a repository contract only if persistence/network behavior is needed.
- Add data representations as
*Dtoand map them withtoNameDto()/toName(). - Implement the repository in
data/repository; repositories use their datasources/mappers and must not call repositories/use cases. - Keep datasources below repositories; a datasource never calls a repository.
- Wire the implementation in the owning Koin module.
- Make the ViewModel call use cases only.
- Add presentation models as
*Uiand map withtoNameUi(). - Put required composable previews in the same file as their composable.
- Add focused tests and run quality checks.
flowchart LR
UI[Compose] --> VM[ViewModel] --> UC[UseCase] --> R[Repository contract]
RI[RepositoryImpl] --> R
RI --> DS[Datasource]
DS --> IO[Room / Ktor / platform]
Use cases may call other use cases. Repositories never call other repositories, and datasources never call repositories: when data of another module is needed, its datasource implements a …Source contract in :protocol, or a use case fetches the value and hands it to the repository.
Add a data/domain/presentation model¶
Keep the naming symmetric:
SomethingDto data representation
Something domain representation
SomethingUi presentation representation
and mappings target the destination by name:
Room entities remain SomethingEntity; wire packets remain explicit protocol packet/content types.
Add attachment/chat content¶
:feature:attachments owns attachment source data, blob transfer, cache, saved attachment storage and attachment management. :feature:media owns platform media/file access/rendering/export.
:feature:chats owns the chat representation:
When adding a new attachment type, extend the attachment source/protocol behavior in the attachment-owning boundary, then map it into the typed chats part variants. Do not make Direct/Group messages expose the attachment module's source model directly, and do not introduce parallel top-level fields for every attachment kind.
Add Direct-chat behavior¶
Stay inside the Direct path where possible:
domain/usecase/direct
domain/repository/direct
domain/model/direct
data/direct/...
presentation/direct/...
Use existing Direct components rather than routing the change through Group code.
Chats is read-only. A new Direct write (send/edit/delete/…) is a DirectConversationCommand plus a workflow under :feature:conversationorchestration:message (domain/workflow/direct); the ViewModel submits it with orchestrator.awaitResult(command). See Conversation orchestration.
Add Group behavior¶
First decide whether it is message sending/delivery, membership/invitation/activation/admin, group security/epoch, verification, typing or presentation only. Presentation and read-only data go into the corresponding Chats group package; writes become a GroupMessageCommand / GroupAdministrationCommand with a workflow in :feature:conversationorchestration:message or membership. Read Chats architecture and Conversation orchestration before changing this area.
Add platform behavior¶
Keep common contracts/models in commonMain. Put Android/iOS implementations in the owning module's androidMain/iosMain top-level device responsibility. Do not introduce Android APIs into common code or create a nested data/device package for convenience.
Add a new application packet¶
- Define the packet in
:protocoland updatePacketCodecsupport as required. - Decide which feature owns its meaning.
- Add an explicit incoming handler/route in that feature. For conversation packets this is a
Receive*Workflowin:feature:conversationorchestration:incomingplus a branch inGroupPacketDispatcherorControlPacketDispatcher. - Define outgoing creation in that feature, enqueue through
ProtocolOutboxrather than calling the transport directly. - Decide its transport policy/encryption requirements deliberately.
- Add routing-ID handling in
:feature:messagingonly if the packet needs a special routing rule. - Add unit/integration tests for decode, policy, outgoing and incoming behavior.
Do not teach :feature:transport the business meaning of the packet.
Add a server endpoint¶
- Choose the owning service (
gateway,federation,mailbox, registry, presence). - Put wire models in
server:protocolonly if they are genuinely shared across service/client boundaries. - Add authentication/replay/rate-limit handling appropriate to the endpoint.
- Keep service persistence behind the service's store/database types.
- Add readiness/metrics/logging where useful.
- If operator-relevant, add a relative link to that deployment's
/indexpage. - Update Caddy only if the path must be public.
- Add server tests/smoke coverage.
Change module dependencies¶
Review the generated graph before committing.
Finish the change¶
For Android platform changes also run device tests; for server changes run the relevant Docker smoke test.