Skip to content

Commit

Permalink
remove groupId and systemId from application data and introduce stati…
Browse files Browse the repository at this point in the history
…c metadata for naming and grouping of components
  • Loading branch information
slu-it committed Mar 15, 2024
1 parent 1b03095 commit 473703c
Show file tree
Hide file tree
Showing 12 changed files with 133 additions and 41 deletions.
1 change: 1 addition & 0 deletions .build/buildSrc/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -10,4 +10,5 @@ dependencies {
implementation("com.fasterxml.jackson.core:jackson-databind:2.16.1")
implementation("com.fasterxml.jackson.module:jackson-module-kotlin:2.16.1")
implementation("net.sourceforge.plantuml:plantuml:1.2024.3")
implementation("org.springframework:spring-core:6.1.5")
}
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
package documentation.generators.asciidoc

import documentation.generators.componentName
import documentation.model.Application
import documentation.model.ComponentType.BACKEND
import documentation.model.Dependency
import documentation.model.Distance.CLOSE
import documentation.model.Distance.DISTANT
import documentation.model.Distance.OWNED
import documentation.model.HttpEndpoint
import documentation.model.componentName

class EndpointsOverviewGenerator(applications: List<Application>) {

Expand Down
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
package documentation.generators.plantuml

import documentation.generators.componentName
import documentation.model.Component
import documentation.model.ComponentType
import documentation.model.Dependency
import documentation.model.Distance
import documentation.model.componentName

abstract class AbstractDiagramGenerator(
private val options: DiagramGeneratorOptions
Expand Down
Original file line number Diff line number Diff line change
@@ -1,15 +1,15 @@
package documentation.generators.plantuml

import documentation.generators.groupName
import documentation.generators.plantuml.DiagramDirection.LEFT_TO_RIGHT
import documentation.generators.systemName
import documentation.model.Application
import documentation.model.Component
import documentation.model.ComponentType
import documentation.model.ComponentType.DATABASE
import documentation.model.Dependency
import documentation.model.Dependent
import documentation.model.Distance.OWNED
import documentation.model.groupName
import documentation.model.systemName
import kotlin.contracts.ExperimentalContracts
import kotlin.contracts.contract

Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -6,13 +6,13 @@ import com.fasterxml.jackson.module.kotlin.jacksonObjectMapper
import com.fasterxml.jackson.module.kotlin.readValue
import java.io.File

private val objectMapper = jacksonObjectMapper()
internal val loadingObjectMapper = jacksonObjectMapper()
.disable(FAIL_ON_UNKNOWN_PROPERTIES)
.enable(READ_UNKNOWN_ENUM_VALUES_AS_NULL)

fun loadApplications(sourceFolder: File): List<Application> {
check(sourceFolder.isDirectory)
return sourceFolder.listFiles()!!
.filter { file -> file.extension == "json" }
.map(objectMapper::readValue)
.map(loadingObjectMapper::readValue)
}
53 changes: 53 additions & 0 deletions .build/buildSrc/src/main/kotlin/documentation/model/metadata.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
package documentation.model

import com.fasterxml.jackson.module.kotlin.readValue
import org.springframework.core.io.ClassPathResource
import kotlin.text.Charsets.UTF_8

private val metadata = Metadata.load()

data class Metadata(
val components: List<ComponentMetadata>,
val groups: List<GroupMetadata>,
val systems: List<SystemMetadata>,
) {
companion object {
fun load(): Metadata {
val resource = ClassPathResource("/metadata.json")
val json = resource.getContentAsString(UTF_8)
return loadingObjectMapper.readValue(json)
}
}
}

data class ComponentMetadata(
val id: String,
val name: String,
val groupId: String?,
val systemId: String?,
)

data class GroupMetadata(
val id: String,
val name: String,
)

data class SystemMetadata(
val id: String,
val name: String,
)

fun componentName(id: String): String =
metadata.components.firstOrNull { it.id == id }?.name ?: id

fun groupName(id: String): String =
metadata.groups.firstOrNull { it.id == id }?.name ?: id

fun systemName(id: String): String =
metadata.systems.firstOrNull { it.id == id }?.name ?: id

fun groupIdOfComponent(componentId: String): String? =
metadata.components.firstOrNull { it.id == componentId }?.groupId

fun systemIdOfComponent(componentId: String): String? =
metadata.components.firstOrNull { it.id == componentId }?.systemId
20 changes: 14 additions & 6 deletions .build/buildSrc/src/main/kotlin/documentation/model/model.kt
Original file line number Diff line number Diff line change
@@ -1,19 +1,24 @@
package documentation.model

import com.fasterxml.jackson.annotation.JsonIgnore

// (!) The content of this file is copied from repository to repository.
// It is the model used by the various generation Gradle tasks and is the same for all repositories.
// In a real project this would likely be packaged as library package and distributed using some kind of registry.

sealed interface Component {
val id: String
val groupId: String?
val systemId: String?
val type: ComponentType?
val distanceFromUs: Distance?
}

enum class ComponentType { BACKEND, FRONTEND, DATABASE }
enum class Distance { OWNED, CLOSE, DISTANT }
@get:JsonIgnore
val groupId: String?
get() = groupIdOfComponent(id)

@get:JsonIgnore
val systemId: String?
get() = systemIdOfComponent(id)
}

data class Application(
override val id: String,
Expand Down Expand Up @@ -43,5 +48,8 @@ data class Dependency(
val httpEndpoints: List<HttpEndpoint> = emptyList(),
) : Component

data class HttpEndpoint(val method: String, val path: String)
enum class ComponentType { BACKEND, FRONTEND, DATABASE }
enum class Distance { OWNED, CLOSE, DISTANT }
enum class Credentials(val label: String) { JWT("JWT"), BASIC_AUTH("Basic-Auth") }

data class HttpEndpoint(val method: String, val path: String)
7 changes: 0 additions & 7 deletions .build/buildSrc/src/main/resources/i18n/components.properties

This file was deleted.

1 change: 0 additions & 1 deletion .build/buildSrc/src/main/resources/i18n/groups.properties

This file was deleted.

2 changes: 0 additions & 2 deletions .build/buildSrc/src/main/resources/i18n/systems.properties

This file was deleted.

59 changes: 59 additions & 0 deletions .build/buildSrc/src/main/resources/metadata.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
{
"components": [
{
"id": "frontend",
"name": "Frontend",
"groupId": "application",
"systemId": "platform"
},
{
"id": "backend-service-1",
"name": "Backend Service #1",
"groupId": "application",
"systemId": "platform"
},
{
"id": "backend-service-1-database",
"name": "database",
"groupId": "application",
"systemId": "platform"
},
{
"id": "backend-service-2",
"name": "Backend Service #2",
"groupId": "application",
"systemId": "platform"
},
{
"id": "external-service-1",
"name": "External Service #1",
"systemId": "platform"
},
{
"id": "external-service-2",
"name": "External Service #2",
"systemId": "platform"
},
{
"id": "external-service-3",
"name": "External Service #3",
"systemId": "other-project"
}
],
"groups": [
{
"id": "application",
"name": "Application"
}
],
"systems": [
{
"id": "platform",
"name": "Platform"
},
{
"id": "other-project",
"name": "Other Project"
}
]
}

0 comments on commit 473703c

Please sign in to comment.