Skip to content

Conversation

@luhmirin-s
Copy link
Contributor

@luhmirin-s luhmirin-s commented Jan 28, 2026

JIRA ticket
Will be released in: 2026.2.0

Notable changes

After spending way too much time trying out different approaches, I landed on 2 small improvements (in relative terms) that are worth doing. The rest of experimentation provided almost zero ROI.

  1. Introduce a dedicated "backend-api" module to be the single point of interaction with networking (It could be argued that it can be merged with the network module, but I decided to leave it for later module pruning). This module hides the complexity of client instantiation and simplifies the backend interaction to:
  • Add simprints.library.backendApi plugin to the module (instead of separate auth-store, network and retrofit dependencies)
  • Define API remote interface with Retrofit annotations and data models (same as before)
  • Inject BackendApiClient into your VM/use case/manager (instead of AuthStore or some sort of client factory)
  • Invoke apiClient.executeCall(MyNewRemoteInterface::class) { api -> api.getStuff() } to do the thing (no need explicitly create a client on caller side).

But doesn't it remove an option to "cache" the client if I need multiple calls on same interface, you might ask. In practice we have not had an case like that in the current code base, so likely YAGNI. Additionally, creation of new Retrofit API instance is relatively low cost (compared to the network call itself) since we are re-using the actual HTTP client instance and the clear abstraction of the BackendApiClient could allow us to implement some more complicated caching in the future without significant changes on the caller side.

  1. Call execution results are wrapped in an ApiResult sealed class to avoid throwing the exception deep into the networking stack. This result class has a couple of convenience getters to start with:
  • result.getOrThrow() - replicates the old behaviour, but it moves the decision to throw closer to the caller. This makes it more explicit that the exception must be handled in one way or another.
  • result.getOrMapFailure {} - provides a convenient way to either simply return the fallback value or map the exact networking exception to a specific value (e.g. to an error message based on the exception type)

Testing guidance

  • Automated regression testing should cover most cases.
  • Smoke testing around the parts that interact with the backend.

Additional work checklist

  • Effect on other features and security has been considered
  • Design document marked as "In development" (if applicable)
  • External (Gitbook) and internal (Confluence) Documentation is up to date (or ticket created)
  • Test cases in Testiny are up to date (or ticket created)
  • Other teams notified about the changes (if applicable)

Copy link

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This pull request introduces significant improvements to the networking layer by centralizing backend API interactions and improving error handling.

Changes:

  • Introduces a new backend-api module with BackendApiClient as the single point of interaction for backend API calls
  • Wraps API call results in an ApiResult sealed class with Success and Failure cases to make error handling more explicit
  • Migrates all existing API client code to use the new BackendApiClient instead of directly using AuthStore or factory classes

Reviewed changes

Copilot reviewed 43 out of 43 changed files in this pull request and generated 6 comments.

Show a summary per file
File Description
settings.gradle.kts Adds the new :infra:backend-api module to the project
infra/backend-api/src/main/java/com/simprints/infra/backendapi/BackendApiClient.kt New centralized client for backend API interactions
infra/backend-api/src/test/java/com/simprints/infra/backendapi/BackendApiClientTest.kt Test coverage for the new BackendApiClient
infra/backend-api/build.gradle.kts Build configuration for the new backend-api module
infra/network/src/main/java/com/simprints/infra/network/ApiResult.kt New sealed class for wrapping API results
infra/network/src/test/java/com/simprints/infra/network/ApiResultTest.kt Test coverage for ApiResult
infra/network/src/main/java/com/simprints/infra/network/SimNetwork.kt Updated interface to return ApiResult instead of throwing
infra/network/src/main/java/com/simprints/infra/network/apiclient/SimApiClientImpl.kt Updated implementation to return ApiResult
infra/network/src/test/java/com/simprints/infra/network/apiclient/SimApiClientImplTest.kt Updated tests for new ApiResult return type
infra/auth-store/src/main/java/com/simprints/infra/authstore/AuthStore.kt Removed buildClient method, added getFirebaseToken method
infra/auth-store/src/main/java/com/simprints/infra/authstore/AuthStoreImpl.kt Updated implementation with getFirebaseToken
infra/auth-store/src/main/java/com/simprints/infra/authstore/network/SimApiClientFactory.kt Removed - functionality moved to BackendApiClient
infra/auth-store/src/test/java/com/simprints/infra/authstore/AuthStoreImplTest.kt Updated tests for removed buildClient method
infra/license/src/main/java/com/simprints/infra/license/remote/LicenseRemoteDataSourceImpl.kt Migrated to use BackendApiClient with ApiResult error handling
infra/license/src/test/java/com/simprints/infra/license/remote/LicenseRemoteDataSourceImplTest.kt Updated tests for new API client
infra/license/build.gradle.kts Added backendApi plugin, removed direct dependencies
infra/event-sync/src/main/java/com/simprints/infra/eventsync/event/remote/EventRemoteDataSource.kt Migrated to use BackendApiClient
infra/event-sync/src/test/java/com/simprints/infra/eventsync/event/remote/EventRemoteDataSourceTest.kt Updated tests for new API client
infra/event-sync/build.gradle.kts Added backendApi plugin
infra/enrolment-records/repository/src/main/java/com/simprints/infra/enrolment/records/repository/remote/EnrolmentRecordRemoteDataSourceImpl.kt Migrated to use BackendApiClient, refactored constructor
infra/enrolment-records/repository/src/test/java/com/simprints/infra/enrolment/records/repository/remote/EnrolmentRecordRemoteDataSourceImplTest.kt Updated tests for new API client
infra/enrolment-records/repository/build.gradle.kts Added backendApi plugin
infra/config-store/src/main/java/com/simprints/infra/config/store/remote/ConfigRemoteDataSourceImpl.kt Migrated to use BackendApiClient
infra/config-store/src/test/java/com/simprints/infra/config/store/remote/ConfigRemoteDataSourceImplTest.kt Updated tests for new API client
infra/config-store/build.gradle.kts Added backendApi plugin
infra/images/src/main/java/com/simprints/infra/images/remote/signedurl/usecase/*.kt Migrated image upload use cases to use BackendApiClient
infra/images/src/test/java/com/simprints/infra/images/remote/signedurl/usecase/*.kt Updated tests for new API client
infra/images/build.gradle.kts Added backendApi plugin
infra/auth-logic/src/main/java/com/simprints/infra/authlogic/authenticator/remote/AuthenticationRemoteDataSource.kt Migrated to use BackendApiClient (affected by critical bug)
infra/auth-logic/src/main/java/com/simprints/infra/authlogic/authenticator/remote/UnauthenticatedClientFactory.kt Removed - functionality moved to BackendApiClient
infra/auth-logic/src/test/java/com/simprints/infra/authlogic/authenticator/remote/AuthenticationRemoteDataSourceTest.kt Updated tests for new API client
infra/auth-logic/build.gradle.kts Added backendApi plugin
fingerprint/infra/scanner/src/main/java/com/simprints/fingerprint/infra/scanner/data/remote/network/*.kt Migrated to use BackendApiClient, removed factory classes
fingerprint/infra/scanner/src/test/java/com/simprints/fingerprint/infra/scanner/data/remote/network/*.kt Updated tests for new API client
fingerprint/infra/scanner/build.gradle.kts Added backendApi plugin
build-logic/convention/src/main/kotlin/LibraryBackendConventionPlugin.kt New Gradle convention plugin for backend API dependencies
build-logic/convention/build.gradle.kts Registered the new backendApi plugin
.github/workflows/pr-checks.yml Added backend-api module to CI workflow

@luhmirin-s luhmirin-s force-pushed the spike/MS-1275-network-rework branch 2 times, most recently from 4c37de3 to 5301f2c Compare January 28, 2026 09:26
@luhmirin-s luhmirin-s requested a review from Copilot January 28, 2026 09:27
Copy link

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Copilot reviewed 40 out of 40 changed files in this pull request and generated 1 comment.

@luhmirin-s luhmirin-s force-pushed the spike/MS-1275-network-rework branch from 5301f2c to d646bac Compare January 28, 2026 09:35
@luhmirin-s luhmirin-s marked this pull request as ready for review January 28, 2026 09:35
@luhmirin-s luhmirin-s requested review from a team, BurningAXE, TristramN, alex-vt, alexandr-simprints, meladRaouf and ybourgery and removed request for a team January 28, 2026 09:36
Copy link
Contributor

@BurningAXE BurningAXE left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Seems contained enough and simplifies things a bit.

@luhmirin-s luhmirin-s force-pushed the spike/MS-1275-network-rework branch from d646bac to 89eff7e Compare January 29, 2026 07:55
…to a backend client

# Conflicts:
#	infra/auth-store/src/main/java/com/simprints/infra/authstore/AuthStore.kt
#	infra/auth-store/src/main/java/com/simprints/infra/authstore/AuthStoreImpl.kt
@luhmirin-s luhmirin-s force-pushed the spike/MS-1275-network-rework branch from 89eff7e to d1c9a23 Compare February 2, 2026 08:32
@sonarqubecloud
Copy link

sonarqubecloud bot commented Feb 2, 2026

@luhmirin-s luhmirin-s merged commit 4210f6b into main Feb 2, 2026
14 checks passed
@luhmirin-s luhmirin-s deleted the spike/MS-1275-network-rework branch February 2, 2026 09:03
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants