{"id":20829478,"url":"https://github.com/inkapplications/regolith","last_synced_at":"2026-03-17T06:49:32.624Z","repository":{"id":174819412,"uuid":"652832743","full_name":"InkApplications/Regolith","owner":"InkApplications","description":"🪨 General purpose application interfaces","archived":false,"fork":false,"pushed_at":"2024-08-17T01:35:38.000Z","size":323,"stargazers_count":1,"open_issues_count":0,"forks_count":1,"subscribers_count":3,"default_branch":"master","last_synced_at":"2024-08-17T02:41:43.295Z","etag":null,"topics":["kotlin","kotlin-multiplatform"],"latest_commit_sha":null,"homepage":"","language":"Kotlin","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/InkApplications.png","metadata":{"files":{"readme":"README.md","changelog":"CHANGELOG.md","contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2023-06-12T22:21:38.000Z","updated_at":"2024-08-17T01:35:35.000Z","dependencies_parsed_at":"2024-03-06T03:24:41.033Z","dependency_job_id":"ca274637-c6e9-4c7d-a625-1516fba3eb3f","html_url":"https://github.com/InkApplications/Regolith","commit_stats":null,"previous_names":["inkapplications/regolith"],"tags_count":22,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/InkApplications%2FRegolith","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/InkApplications%2FRegolith/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/InkApplications%2FRegolith/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/InkApplications%2FRegolith/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/InkApplications","download_url":"https://codeload.github.com/InkApplications/Regolith/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":225101971,"owners_count":17421149,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["kotlin","kotlin-multiplatform"],"created_at":"2024-11-17T23:20:31.594Z","updated_at":"2026-03-17T06:49:27.588Z","avatar_url":"https://github.com/InkApplications.png","language":"Kotlin","funding_links":[],"categories":[],"sub_categories":[],"readme":"Regolith\n========\n\nA collection of generalized application system components that can be used\nin mobile, desktop and web applications to create reusable functionality\nacross platforms.\n\nModules\n=======\n\nRegolith is broken up into distinct modules that can be used independently.\nEach module provides different abstractions on system components common\nin applications.\n\nInit Module\n-----------\n\nInitializers are the start of your application. They can be used to configure\nlibraries, or start services.\n\n### Maven Coordinates\n\n    com.inkapplications.regolith:init\n\n### Create an Initializer\n\nThe interface for an Initializer has a single-method that is called when\nthe application starts:\n\n```kotlin\nobject DatabaseInitializer: Initializer {\n    override fun initialize(targetManager: TargetManager) {\n        Database.init()\n    }\n}\n```\n\nInitializers are then added to an `InitRunner` to be started immediately\nwhen `initialize()` is called:\n\n```kotlin\nfun main() {\n    val myInitializers = listOf(DatabaseInitializer)\n    RegolithInitRunner(\n        initializers = myInitializers\n    ).initialize()\n}\n```\n\n### Initialization Targets\n\nAll initializers are started *immediately* on application start. However,\nTargets may be used to wait for initializers or to pass data between\ninitializers.\n\nTo create a target, extend the empty `InitTarget` interface:\n\n```kotlin\nobject DatabaseInitTarget: InitTarget\n```\n\nIf your initializer provides data that may be needed by other initializers,\nit can be passed through the Target as data in the Target object:\n\n\n```kotlin\ndata class DatabaseInitTarget(\n    val session: DatabaseSession\n)\n```\n\nTargets can be emitted by any initializer through\n`targetManager.postTarget()` provided in the `initialize` call:\n\n```kotlin\nobject DatabaseInitializer: Initializer {\n    override fun initialize(targetManager: TargetManager) {\n        val session = Database.init()\n        targetManager.postTarget(DatabaseInitTarget(session))\n    }\n}\n```\n\nYou can wait for a Target with the `targetManager.awaitTarget()` method:\n\n```kotlin\nclass TokenRefreshInitializer(\n    val api: MyApi\n): Initializer {\n    override fun initialize(targetManager: TargetManager) {\n        // Wait for DatabaseInitTarget and use its provided session data:\n        val session = targetManager.awaitTarget(DatabaseInitTarget)\n        session.updateToken(api.fetchToken())\n    }\n}\n```\n\nTargets can also be posted to the manager via the `RegolithInitRunner`.\nFor example, an Android application may use this mechanism to provide\nthe application instance as a target:\n\n```kotlin\ndata class ApplicationTarget(\n    val application: Application\n)\n\nclass MyApplication: Application() {\n    private val initializers = listOf(DatabaseInitializer)\n    private val initRunner = RegolithInitRunner(\n        initializers = myInitializers\n    )\n    override fun onCreate() {\n        initRunner.initialize()\n        initRunner.postTarget(ApplicationTarget(this))\n    }\n}\n```\n\nProcesses\n---------\n\nThe processes module provices abstractions on long-running components of\nyour application\n\n### Maven coordinates\n\n    com.inkapplications.regolith:processes\n\n### Daemons\n\nDaemons are similar to initializers, except that they are intended to\nnever stop running. While initializers may not suspend and must return\nfor initialization to complete, Daemons *cannot* be completed.\n\nTo create a Daemon, implement the `Daemon` interface:\n\n```\nclass WebServerDaemon(\n    private val server: WebServer\n): Daemon {\n    suspend fun startDaemon(): Nothing {\n        server.start()\n        throw IllegalStateException(\"Server exited unexpectedly\")\n    }\n}\n```\n\nDaemons can be started with the `DaemonInitializer` which can be run\nas a part of the `init` component:\n\n```kotlin\nfun main() {\n    val daemonInitializer = DaemonInitializer(\n        daemons = listOf(webServerDaemon)\n    )\n    val myInitializers = listOf(daemonInitializer)\n\n    RegolithInitRunner(\n        initializers = myInitializers\n    ).initialize()\n}\n```\n\n### Crons\n\nCrons are similar to Daemons, except that they are expected to run and\ncomplete on a predetermined time schedule.\n\nCrons can be created by implementing the `CronJob` interface:\n\n```kotlin\nclass DatabaseFlushCron(\n    private val database: Database\n): CronJob {\n    override val schedule = Schedule().withMinutes { it % 10 } // Every 10 minutes\n    suspend fun runCron(time: LocalDateTime, zone: TimeZone) {\n        database.flush()\n    }\n}\n```\n\nCrons can be run automatically by using the `CoroutineCronDaemon`:\n\n```kotlin\nfun main() {\n    val cronDaemon = CoroutineCronDaemon(\n        jobs = DatabaseFlushCron(myDatabase),\n    )\n    val daemonInitializer = DaemonInitializer(\n        daemons = listOf(webServerDaemon, cronDaemon)\n    )\n    val myInitializers = listOf(daemonInitializer)\n\n    RegolithInitRunner(\n        initializers = myInitializers\n    ).initialize()\n}\n```\n\nResources\n---------\n\nThe resources module provides abstractions around application resources like\nfiles and strings.\n\n### Maven coordinates\n\n    com.inkapplications.regolith:resources\n\n### String Resources\n\nThe `StringResources` interface provides a way to load localized strings\nin an application.\n\nStrings can be Identified either by string or integer, and supports parameter\nformatting.\n\nAndroid has a default implementation to its internal string localization\nloader via the `AndroidStringResources` class.\n\n### File Resources\n\nThe `FileResources` interface provides a way to load files from the\nfilesystem or the local application resources.\n\nApplication packaged resources can be loaded with by name or ID with the\n`FileResources.Local` id type. External files can be loaded by path or URI.\n\nAndroid has a default implementation via the `AndroidFileResources` class.\n\nJVM has a default implementation via the `JvmFileResources` class.\n\n### Testing\n\nTesting implementations are provided in the `doubles` package, including:\n`DummyResources`, `StubResources`, and `ParrotResources`.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Finkapplications%2Fregolith","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Finkapplications%2Fregolith","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Finkapplications%2Fregolith/lists"}