# deference3/form-doctor architecture

> Architecture diagram of the GitHub repository deference3/form-doctor, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2026-08-25). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/deference3/form-doctor
- Repository: https://github.com/deference3/form-doctor

## Overview

#### Purpose and module layout
FormDoc is a Kotlin Multiplatform, Compose-oriented form-validation library. It combines runtime form state management (`formdoc`), compile-time KSP metadata generation (`processor`), and a Compose Multiplatform sample consumer (`composeApp`). Root Gradle configuration assembles these modules: `settings.gradle.kts`, `build.gradle.kts`.

#### Runtime validation core
The `formdoc` module defines the portable validation contract and reactive state model. `FormState` owns a model instance plus metadata, exposes validation/submission operations, and updates per-property `FieldState`; `FormScope` supports Compose-facing form content. Annotation declarations express built-in and custom constraints, while validators execute them.
Paths: `formdoc/src/commonMain/kotlin/me/deference/formdoc/FormState.kt`, `formdoc/src/commonMain/kotlin/me/deference/formdoc/FieldState.kt`, `formdoc/src/commonMain/kotlin/me/deference/formdoc/ValidationAnnotations.kt`, `formdoc/src/commonMain/kotlin/me/deference/formdoc/Validators.kt`.

#### Compile-time metadata pipeline
Consumers annotate data classes/properties, then KSP invokes the registered provider and processor. The processor scans validatable symbols and generates typed `FormMetadata` implementations mapping model properties to validator definitions. This is the key boundary: validation rules are discovered at build time, avoiding runtime reflection.
Paths: `processor/src/main/kotlin/me/deference/processor/FormProcessorProvider.kt`, `processor/src/main/kotlin/me/deference/processor/FormProcessor.kt`, `processor/src/main/resources/META-INF/services/com.google.devtools.ksp.processing.SymbolProcessorProvider`.

#### Metadata registry boundary
Generated metadata must be surfaced to common Compose code through an application-owned expect registry. The sample declares this registry in `commonMain`; its forms request metadata by model type before creating form state. This manual integration exists because generated code is not directly placed in common source sets.
Paths: `composeApp/src/commonMain/kotlin/formdoc/registry/FormMetadataRegistry.kt`, `composeApp/src/commonMain/kotlin/me/deference/formsample/customer/CustomerFormModel.kt`, `composeApp/src/commonMain/kotlin/me/deference/formsample/customer/CustomerForm.kt`.

#### Sample UI and form flow
The sample is the reference integration: app startup renders Compose UI, customer form components bind field values to reactive field state, selector/address widgets collect nested input, and submission invokes validation callbacks. Customer model annotations and master data drive the demonstrated validation and selection behavior.
Paths: `composeApp/src/commonMain/kotlin/me/deference/formsample/App.kt`, `composeApp/src/commonMain/kotlin/me/deference/formsample/customer/CustomerForm.kt`, `composeApp/src/commonMain/kotlin/me/deference/formsample/customer/components/AddressForm.kt`.

#### Platform entry points and runtimes
Shared Kotlin/Compose code targets Android, iOS, JVM desktop, JS/web, and Wasm JS through platform-specific actual platform implementations. Android starts from an Activity; iOS bridges Compose through a view controller and an Xcode host; JVM and web have explicit main functions. The library itself supplies Android, iOS, JVM, and web platform source sets.
Paths: `composeApp/src/androidMain/kotlin/me/deference/formsample/MainActivity.kt`, `composeApp/src/iosMain/kotlin/me/deference/formsample/MainViewController.kt`, `composeApp/src/jvmMain/kotlin/me/deference/formsample/main.kt`, `composeApp/src/webMain/kotlin/me/deference/formsample/main.kt`.

#### Delivery and external build infrastructure
Gradle manages Kotlin Multiplatform, Compose, and KSP compilation; the processor is consumed as a KSP dependency by downstream projects. GitHub Actions publishes artifacts, making the runtime library and annotation processor separately distributable.
Paths: `formdoc/build.gradle.kts`, `processor/build.gradle.kts`, `composeApp/build.gradle.kts`, `.github/workflows/publish.yml`.

Main entry points: [`composeApp/src/commonMain/kotlin/me/deference/formsample/App.kt`](https://github.com/deference3/form-doctor/blob/master/composeApp/src/commonMain/kotlin/me/deference/formsample/App.kt) (Sample App), [`processor/src/main/kotlin/me/deference/processor/FormProcessor.kt`](https://github.com/deference3/form-doctor/blob/master/processor/src/main/kotlin/me/deference/processor/FormProcessor.kt) (FormProcessor), [`composeApp/src/commonMain/kotlin/me/deference/formsample/customer/CustomerForm.kt`](https://github.com/deference3/form-doctor/blob/master/composeApp/src/commonMain/kotlin/me/deference/formsample/customer/CustomerForm.kt) (CustomerForm), [`composeApp/src/commonMain/kotlin/me/deference/formsample/customer/CustomerFormModel.kt`](https://github.com/deference3/form-doctor/blob/master/composeApp/src/commonMain/kotlin/me/deference/formsample/customer/CustomerFormModel.kt) (CustomerFormModel)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_runtime["Runtime library"]
  node_annotations["Validation annotations<br/>constraint declarations"]
  node_validators["Validators<br/>validation engine<br/>[Validators.kt]"]
  node_form_state["FormState<br/>reactive form state<br/>[FormState.kt]"]
  node_field_state["FieldState<br/>reactive field state<br/>[FieldState.kt]"]
end

subgraph group_processing["Metadata generation"]
  node_ksp_service["KSP provider registration<br/>service descriptor"]
  node_processor_provider["FormProcessorProvider<br/>KSP provider"]
  node_processor["FormProcessor<br/>symbol processor<br/>[FormProcessor.kt]"]
  node_generated_metadata["Generated FormMetadata<br/>generated source"]
end

subgraph group_sample["Sample integration"]
  node_customer_model["CustomerFormModel<br/>annotated model"]
  node_metadata_registry["FormMetadataRegistry<br/>expect registry"]
  node_customer_form["CustomerForm<br/>Compose form<br/>[CustomerForm.kt]"]
  node_address_form["AddressForm<br/>nested input UI<br/>[AddressForm.kt]"]
  node_app["Sample App<br/>Compose root<br/>[App.kt]"]
end

subgraph group_platforms["Platform delivery"]
  node_platform_entries{{"Platform entry points<br/>Android, iOS, JVM, web"}}
  node_android_entry["Android Activity<br/>Android entry<br/>[MainActivity.kt]"]
  node_ios_entry["iOS ViewController<br/>iOS entry"]
  node_jvm_entry["JVM main<br/>desktop entry<br/>[main.kt]"]
  node_web_entry["Web main<br/>web entry<br/>[main.kt]"]
  node_gradle_build["Gradle build<br/>multiplatform build<br/>[build.gradle.kts]"]
  node_publishing["Artifact publishing<br/>GitHub Actions<br/>[publish.yml]"]
end

node_annotations -->|"scanned by"| node_processor
node_ksp_service -->|"registers"| node_processor_provider
node_processor_provider -->|"creates"| node_processor
node_processor -->|"generates"| node_generated_metadata
node_customer_model -->|"uses"| node_annotations
node_customer_model -->|"processed by KSP"| node_processor
node_generated_metadata -->|"surfaced through"| node_metadata_registry
node_metadata_registry -->|"provides metadata"| node_customer_form
node_customer_model -->|"edited by"| node_customer_form
node_customer_form -->|"creates"| node_form_state
node_form_state -->|"updates"| node_field_state
node_form_state -->|"runs"| node_validators
node_generated_metadata -->|"defines rules for"| node_validators
node_address_form -->|"nested in"| node_customer_form
node_app -->|"renders"| node_customer_form
node_android_entry -->|"launches"| node_app
node_ios_entry -->|"hosts"| node_app
node_jvm_entry -->|"launches"| node_app
node_web_entry -->|"launches"| node_app
node_platform_entries -.->|"includes"| node_android_entry
node_platform_entries -.->|"includes"| node_ios_entry
node_platform_entries -.->|"includes"| node_jvm_entry
node_platform_entries -.->|"includes"| node_web_entry
node_gradle_build -->|"compiles"| node_processor
node_gradle_build -->|"builds"| node_app
node_publishing -->|"runs"| node_gradle_build

click node_annotations "https://github.com/deference3/form-doctor/blob/master/formdoc/src/commonMain/kotlin/me/deference/formdoc/ValidationAnnotations.kt"
click node_validators "https://github.com/deference3/form-doctor/blob/master/formdoc/src/commonMain/kotlin/me/deference/formdoc/Validators.kt"
click node_form_state "https://github.com/deference3/form-doctor/blob/master/formdoc/src/commonMain/kotlin/me/deference/formdoc/FormState.kt"
click node_field_state "https://github.com/deference3/form-doctor/blob/master/formdoc/src/commonMain/kotlin/me/deference/formdoc/FieldState.kt"
click node_ksp_service "https://github.com/deference3/form-doctor/blob/master/processor/src/main/resources/META-INF/services/com.google.devtools.ksp.processing.SymbolProcessorProvider"
click node_processor_provider "https://github.com/deference3/form-doctor/blob/master/processor/src/main/kotlin/me/deference/processor/FormProcessorProvider.kt"
click node_processor "https://github.com/deference3/form-doctor/blob/master/processor/src/main/kotlin/me/deference/processor/FormProcessor.kt"
click node_customer_model "https://github.com/deference3/form-doctor/blob/master/composeApp/src/commonMain/kotlin/me/deference/formsample/customer/CustomerFormModel.kt"
click node_metadata_registry "https://github.com/deference3/form-doctor/blob/master/composeApp/src/commonMain/kotlin/formdoc/registry/FormMetadataRegistry.kt"
click node_customer_form "https://github.com/deference3/form-doctor/blob/master/composeApp/src/commonMain/kotlin/me/deference/formsample/customer/CustomerForm.kt"
click node_address_form "https://github.com/deference3/form-doctor/blob/master/composeApp/src/commonMain/kotlin/me/deference/formsample/customer/components/AddressForm.kt"
click node_app "https://github.com/deference3/form-doctor/blob/master/composeApp/src/commonMain/kotlin/me/deference/formsample/App.kt"
click node_android_entry "https://github.com/deference3/form-doctor/blob/master/composeApp/src/androidMain/kotlin/me/deference/formsample/MainActivity.kt"
click node_ios_entry "https://github.com/deference3/form-doctor/blob/master/composeApp/src/iosMain/kotlin/me/deference/formsample/MainViewController.kt"
click node_jvm_entry "https://github.com/deference3/form-doctor/blob/master/composeApp/src/jvmMain/kotlin/me/deference/formsample/main.kt"
click node_web_entry "https://github.com/deference3/form-doctor/blob/master/composeApp/src/webMain/kotlin/me/deference/formsample/main.kt"
click node_gradle_build "https://github.com/deference3/form-doctor/blob/master/composeApp/build.gradle.kts"
click node_publishing "https://github.com/deference3/form-doctor/blob/master/.github/workflows/publish.yml"

classDef toneNeutral fill:#f8fafc,stroke:#334155,stroke-width:1.5px,color:#0f172a
classDef toneBlue fill:#dbeafe,stroke:#2563eb,stroke-width:1.5px,color:#172554
classDef toneAmber fill:#fef3c7,stroke:#d97706,stroke-width:1.5px,color:#78350f
classDef toneMint fill:#dcfce7,stroke:#16a34a,stroke-width:1.5px,color:#14532d
classDef toneRose fill:#ffe4e6,stroke:#e11d48,stroke-width:1.5px,color:#881337
classDef toneIndigo fill:#e0e7ff,stroke:#4f46e5,stroke-width:1.5px,color:#312e81
classDef toneTeal fill:#ccfbf1,stroke:#0f766e,stroke-width:1.5px,color:#134e4a
class node_annotations,node_validators,node_form_state,node_field_state toneBlue
class node_ksp_service,node_processor_provider,node_processor,node_generated_metadata toneAmber
class node_customer_model,node_metadata_registry,node_customer_form,node_address_form,node_app toneMint
class node_platform_entries,node_android_entry,node_ios_entry,node_jvm_entry,node_web_entry,node_gradle_build,node_publishing toneRose
```

## Components

### Runtime library

- [Validation annotations](https://github.com/deference3/form-doctor/blob/master/formdoc/src/commonMain/kotlin/me/deference/formdoc/ValidationAnnotations.kt): constraint declarations · Built-in and custom validation constraints. · `formdoc/src/commonMain/kotlin/me/deference/formdoc/ValidationAnnotations.kt`
- [Validators](https://github.com/deference3/form-doctor/blob/master/formdoc/src/commonMain/kotlin/me/deference/formdoc/Validators.kt): validation engine · `formdoc/src/commonMain/kotlin/me/deference/formdoc/Validators.kt`
- [FormState](https://github.com/deference3/form-doctor/blob/master/formdoc/src/commonMain/kotlin/me/deference/formdoc/FormState.kt): reactive form state · Owns the model, metadata, validation, and submission flow. · `formdoc/src/commonMain/kotlin/me/deference/formdoc/FormState.kt`
- [FieldState](https://github.com/deference3/form-doctor/blob/master/formdoc/src/commonMain/kotlin/me/deference/formdoc/FieldState.kt): reactive field state · `formdoc/src/commonMain/kotlin/me/deference/formdoc/FieldState.kt`

### Metadata generation

- [KSP provider registration](https://github.com/deference3/form-doctor/blob/master/processor/src/main/resources/META-INF/services/com.google.devtools.ksp.processing.SymbolProcessorProvider): service descriptor · `processor/src/main/resources/META-INF/services/com.google.devtools.ksp.processing.SymbolProcessorProvider`
- [FormProcessorProvider](https://github.com/deference3/form-doctor/blob/master/processor/src/main/kotlin/me/deference/processor/FormProcessorProvider.kt): KSP provider · `processor/src/main/kotlin/me/deference/processor/FormProcessorProvider.kt`
- [FormProcessor](https://github.com/deference3/form-doctor/blob/master/processor/src/main/kotlin/me/deference/processor/FormProcessor.kt): symbol processor · Generates typed FormMetadata without runtime reflection. · `processor/src/main/kotlin/me/deference/processor/FormProcessor.kt`
- **Generated FormMetadata**: generated source · Typed property-to-validator metadata implementations.

### Sample integration

- [CustomerFormModel](https://github.com/deference3/form-doctor/blob/master/composeApp/src/commonMain/kotlin/me/deference/formsample/customer/CustomerFormModel.kt): annotated model · `composeApp/src/commonMain/kotlin/me/deference/formsample/customer/CustomerFormModel.kt`
- [FormMetadataRegistry](https://github.com/deference3/form-doctor/blob/master/composeApp/src/commonMain/kotlin/formdoc/registry/FormMetadataRegistry.kt): expect registry · Application-owned bridge from common code to generated metadata. · `composeApp/src/commonMain/kotlin/formdoc/registry/FormMetadataRegistry.kt`
- [CustomerForm](https://github.com/deference3/form-doctor/blob/master/composeApp/src/commonMain/kotlin/me/deference/formsample/customer/CustomerForm.kt): Compose form · Obtains metadata, creates form state, and handles submission. · `composeApp/src/commonMain/kotlin/me/deference/formsample/customer/CustomerForm.kt`
- [AddressForm](https://github.com/deference3/form-doctor/blob/master/composeApp/src/commonMain/kotlin/me/deference/formsample/customer/components/AddressForm.kt): nested input UI · `composeApp/src/commonMain/kotlin/me/deference/formsample/customer/components/AddressForm.kt`
- [Sample App](https://github.com/deference3/form-doctor/blob/master/composeApp/src/commonMain/kotlin/me/deference/formsample/App.kt): Compose root · `composeApp/src/commonMain/kotlin/me/deference/formsample/App.kt`

### Platform delivery

- **Platform entry points**: Android, iOS, JVM, web · Platform hosts launch shared Compose UI.
- [Android Activity](https://github.com/deference3/form-doctor/blob/master/composeApp/src/androidMain/kotlin/me/deference/formsample/MainActivity.kt): Android entry · `composeApp/src/androidMain/kotlin/me/deference/formsample/MainActivity.kt`
- [iOS ViewController](https://github.com/deference3/form-doctor/blob/master/composeApp/src/iosMain/kotlin/me/deference/formsample/MainViewController.kt): iOS entry · `composeApp/src/iosMain/kotlin/me/deference/formsample/MainViewController.kt`
- [JVM main](https://github.com/deference3/form-doctor/blob/master/composeApp/src/jvmMain/kotlin/me/deference/formsample/main.kt): desktop entry · `composeApp/src/jvmMain/kotlin/me/deference/formsample/main.kt`
- [Web main](https://github.com/deference3/form-doctor/blob/master/composeApp/src/webMain/kotlin/me/deference/formsample/main.kt): web entry · `composeApp/src/webMain/kotlin/me/deference/formsample/main.kt`
- [Gradle build](https://github.com/deference3/form-doctor/blob/master/composeApp/build.gradle.kts): multiplatform build · Builds runtime, processor, sample, and KSP integration. · `composeApp/build.gradle.kts`
- [Artifact publishing](https://github.com/deference3/form-doctor/blob/master/.github/workflows/publish.yml): GitHub Actions · Publishes runtime and processor artifacts separately. · `.github/workflows/publish.yml`

## Connections

- Validation annotations → FormProcessor: scanned by
- KSP provider registration → FormProcessorProvider: registers
- FormProcessorProvider → FormProcessor: creates
- FormProcessor → Generated FormMetadata: generates
- CustomerFormModel → Validation annotations: uses
- CustomerFormModel → FormProcessor: processed by KSP
- Generated FormMetadata → FormMetadataRegistry: surfaced through
- FormMetadataRegistry → CustomerForm: provides metadata
- CustomerFormModel → CustomerForm: edited by
- CustomerForm → FormState: creates
- FormState → FieldState: updates
- FormState → Validators: runs
- Generated FormMetadata → Validators: defines rules for
- AddressForm → CustomerForm: nested in
- Sample App → CustomerForm: renders
- Android Activity → Sample App: launches
- iOS ViewController → Sample App: hosts
- JVM main → Sample App: launches
- Web main → Sample App: launches
- Platform entry points → Android Activity: includes
- Platform entry points → iOS ViewController: includes
- Platform entry points → JVM main: includes
- Platform entry points → Web main: includes
- Gradle build → FormProcessor: compiles
- Gradle build → Sample App: builds
- Artifact publishing → Gradle build: runs
