Skip to content

Commit

Permalink
clearer model class names
Browse files Browse the repository at this point in the history
  • Loading branch information
slu-it committed Sep 26, 2024
1 parent 795f42b commit e3b6e3c
Show file tree
Hide file tree
Showing 11 changed files with 75 additions and 76 deletions.
Original file line number Diff line number Diff line change
@@ -1,16 +1,16 @@
package documentation.generators.asciidoc

import documentation.model.Application
import documentation.model.ApplicationComponent
import documentation.model.Database
import documentation.model.Database.Table
import documentation.model.Distance.OWNED

class DatabasesOverviewGenerator(applications: List<Application>) {
class DatabasesOverviewGenerator(applicationComponents: List<ApplicationComponent>) {

private val keyEmoji = "\uD83D\uDD11"
private val ourDatabases = applications
private val ourDatabases = applicationComponents
.filter { it.distanceFromUs == OWNED }
.flatMap(Application::databases)
.flatMap(ApplicationComponent::databases)
.sortedBy(Database::name)

fun asciiDocSource(): String =
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
package documentation.generators.asciidoc

import documentation.model.Application
import documentation.model.ApplicationComponent
import documentation.model.ComponentType.BACKEND
import documentation.model.Dependency
import documentation.model.Distance.CLOSE
Expand All @@ -9,18 +9,18 @@ import documentation.model.Distance.OWNED
import documentation.model.HttpEndpoint
import documentation.model.componentName

class EndpointsOverviewGenerator(applications: List<Application>) {
class EndpointsOverviewGenerator(applicationComponents: List<ApplicationComponent>) {

private val relevantComponentTypes = setOf(BACKEND)

private val ourApplicationsAndTheirDependencies = applications
private val ourComponentsAndTheirDependencies = applicationComponents
.filter { it.distanceFromUs == OWNED }
.map { application -> application to application.dependencies }

fun asciiDocSource(): String =
buildString {

val allCalledComponents = ourApplicationsAndTheirDependencies
val allCalledComponents = ourComponentsAndTheirDependencies
.flatMap { (_, dependencies) -> dependencies }
.filter { dependency -> dependency.type in relevantComponentTypes }
.filter { dependency -> dependency.httpEndpoints.isNotEmpty() }
Expand Down Expand Up @@ -96,7 +96,7 @@ class EndpointsOverviewGenerator(applications: List<Application>) {
}

private fun findOurCallingApplicationIds(dependencyId: String, endpoint: HttpEndpoint): List<String> =
ourApplicationsAndTheirDependencies
ourComponentsAndTheirDependencies
.filter { (_, dependencies) -> dependencies.any { it.id == dependencyId } }
.filter { (_, dependencies) -> dependencies.flatMap { it.httpEndpoints }.contains(endpoint) }
.map { (application, _) -> application.id }
Expand Down
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
package documentation.generators.asciidoc

import documentation.model.Application
import documentation.model.ApplicationComponent
import documentation.model.Distance.OWNED
import documentation.model.componentName

class EventsOverviewGenerator(applications: List<Application>) {
class EventsOverviewGenerator(applicationComponents: List<ApplicationComponent>) {

private val ourApplicationsWithEvents = applications
private val ourComponentsWithEvents = applicationComponents
.filter { it.distanceFromUs == OWNED }
.filter { it.events.isNotEmpty() }
.sortedBy { componentName(it.id) }
Expand All @@ -18,7 +18,7 @@ class EventsOverviewGenerator(applications: List<Application>) {
appendLine()
appendLine("= Events")
appendLine()
ourApplicationsWithEvents
ourComponentsWithEvents
.forEach { application ->
appendLine("== ${componentName(application.id)}")
appendLine()
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
package documentation.generators.plantuml

import documentation.model.Application
import documentation.model.ApplicationComponent
import documentation.model.Component
import documentation.model.ComponentType
import documentation.model.Dependency
Expand Down Expand Up @@ -41,11 +41,11 @@ abstract class AbstractDiagramGenerator(
appendLine()
}

protected fun StringBuilder.appendLegend(application: Application) =
appendLegend(listOf(application))
protected fun StringBuilder.appendLegend(component: ApplicationComponent) =
appendLegend(listOf(component))

protected fun StringBuilder.appendLegend(applications: Iterable<Application>) {
val distances = applications.asSequence()
protected fun StringBuilder.appendLegend(components: Iterable<ApplicationComponent>) {
val distances = components.asSequence()
.flatMap { it.dependencies.map(Dependency::distanceFromUs) + it.distanceFromUs }
.distinct()
.filterNotNull()
Expand Down
Original file line number Diff line number Diff line change
@@ -1,12 +1,11 @@
package documentation.generators.plantuml

import documentation.generators.plantuml.DiagramDirection.LEFT_TO_RIGHT
import documentation.model.Application
import documentation.model.ApplicationComponent
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
Expand All @@ -15,7 +14,7 @@ import kotlin.contracts.contract

@OptIn(ExperimentalContracts::class)
class ApplicationContextDiagramGenerator(
private val application: Application,
private val applicationComponent: ApplicationComponent,
private val options: Options = Options(),
) : AbstractDiagramGenerator(options) {

Expand All @@ -36,21 +35,21 @@ class ApplicationContextDiagramGenerator(
private val systemsAndGroups: List<Pair<String?, String?>>

init {
val dependents = application.dependents.filter(::typeIsIncluded)
val dependencies = application.dependencies.filter(::typeIsIncluded)
val dependents = applicationComponent.dependents.filter(::typeIsIncluded)
val dependencies = applicationComponent.dependencies.filter(::typeIsIncluded)

components = buildList {
addAll(dependents)
add(application)
add(applicationComponent)
addAll(dependencies)
}

relationships = buildList {
dependents
.map { source -> diagramRelationship(source, application) }
.map { source -> diagramRelationship(source, applicationComponent) }
.forEach(::add)
dependencies
.map { target -> diagramRelationship(application, target) }
.map { target -> diagramRelationship(applicationComponent, target) }
.forEach(::add)
}

Expand Down Expand Up @@ -114,7 +113,7 @@ class ApplicationContextDiagramGenerator(
appendRelationshipLine(relationship)
}
appendLine()
appendLegend(application)
appendLegend(applicationComponent)
appendLine()
appendLine("@enduml")
}
Expand All @@ -133,7 +132,7 @@ class ApplicationContextDiagramGenerator(

override fun style(component: Component): String =
when {
component is Application -> "#skyblue;line.bold"
component is ApplicationComponent -> "#skyblue;line.bold"
component.type == DATABASE -> ""
else -> super.style(component)
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
package documentation.generators.plantuml

import documentation.model.Application
import documentation.model.ApplicationComponent
import documentation.model.ComponentType
import documentation.model.ComponentType.BACKEND
import documentation.model.Messaging.Binding
Expand All @@ -9,7 +9,7 @@ import documentation.model.Messaging.PublishedMessage
import documentation.model.componentName

class MessagingDiagramGenerator(
private val applications: List<Application>,
private val components: List<ApplicationComponent>,
private val options: Options = Options(),
) : AbstractDiagramGenerator(options) {

Expand Down Expand Up @@ -91,7 +91,7 @@ class MessagingDiagramGenerator(
private fun diagramQueueComponent(it: String) =
DiagramComponent(id = diagramQueueId(it), type = "queue", name = it, style = null)

private fun publisherToExchangeRelationship(publisher: Application, exchange: String) =
private fun publisherToExchangeRelationship(publisher: ApplicationComponent, exchange: String) =
DiagramRelationship(
source = diagramComponentId(publisher, "producer"),
target = diagramExchangeId(exchange),
Expand All @@ -106,22 +106,22 @@ class MessagingDiagramGenerator(
label = routingKeyPattern
)

private fun queueToConsumerRelationship(queue: String, consumer: Application) =
private fun queueToConsumerRelationship(queue: String, consumer: ApplicationComponent) =
DiagramRelationship(
source = diagramQueueId(queue),
target = diagramComponentId(consumer, "consumer"),
link = "-->",
)

private fun publishingNote(application: Application) = DiagramNote(
target = diagramComponentId(application, "producer"),
text = publishingNoteText(application).trim(),
private fun publishingNote(component: ApplicationComponent) = DiagramNote(
target = diagramComponentId(component, "producer"),
text = publishingNoteText(component).trim(),
position = "left"
)

private fun publishingNoteText(application: Application) =
private fun publishingNoteText(component: ApplicationComponent) =
buildString {
application.messaging.publishedMessages
component.messaging.publishedMessages
.forEach { (exchange, routingKeys) ->
appendLine("**$exchange**:")
routingKeys.forEach { routingKey ->
Expand All @@ -135,25 +135,25 @@ class MessagingDiagramGenerator(
(getPublishingExchangeNames() + getConsumingExchangeNames()).distinct()

private fun getPublishingExchangeNames(): List<String> =
applications
components
.flatMap { application -> application.messaging.publishedMessages.map(PublishedMessage::exchange) }
.distinct()

private fun getConsumingExchangeNames(): List<String> =
applications
components
.flatMap { application -> application.messaging.consumedQueues.flatMap { it.bindings.map(Binding::exchange) } }
.distinct()

private fun getAllQueueNames(): List<String> =
applications
components
.flatMap { application -> application.messaging.consumedQueues.map(ConsumedQueue::name) }
.distinct()

private fun publishingApplications() = applications
private fun publishingApplications() = components
.filter { it.messaging.publishedMessages.isNotEmpty() }
.sortedBy { componentName(it.id) }

private fun consumingApplications() = applications
private fun consumingApplications() = components
.filter { it.messaging.consumedQueues.isNotEmpty() }
.sortedBy { componentName(it.id) }

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

import documentation.generators.plantuml.DiagramDirection.TOP_TO_BOTTOM
import documentation.model.Application
import documentation.model.ApplicationComponent
import documentation.model.ComponentType
import documentation.model.ComponentType.BACKEND
import documentation.model.ComponentType.FRONTEND

class MultipleApplicationsDiagramGenerator(
private val applications: List<Application>,
private val applicationComponents: List<ApplicationComponent>,
private val options: Options = Options(),
) : AbstractDiagramGenerator(options) {

Expand All @@ -22,21 +22,21 @@ class MultipleApplicationsDiagramGenerator(
private val relationships: List<DiagramRelationship>

init {
val applicationIds = applications.map(Application::id).toSet()
val applicationComponentIds = applicationComponents.map(ApplicationComponent::id).toSet()

components = buildList {
applications
applicationComponents
.map(::diagramComponent)
.forEach(::add)
applications.asSequence()
applicationComponents.asSequence()
.flatMap { it.dependencies }
.filter { it.type in options.includedComponentTypes }
.filter { it.id !in applicationIds }
.filter { it.id !in applicationComponentIds }
.distinctBy { it.id }
.map(::diagramComponent)
.forEach(::add)
}
relationships = applications
relationships = applicationComponents
.filter { it.type in options.includedComponentTypes }
.flatMap { application ->
application.dependencies
Expand All @@ -61,7 +61,7 @@ class MultipleApplicationsDiagramGenerator(
appendLine()
relationships.forEach { appendRelationshipLine(it) }
appendLine()
appendLegend(applications)
appendLegend(applicationComponents)
appendLine()
appendLine("@enduml")
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ internal val loadingObjectMapper = jacksonObjectMapper()
.disable(FAIL_ON_UNKNOWN_PROPERTIES)
.enable(READ_UNKNOWN_ENUM_VALUES_AS_NULL)

fun loadApplications(sourceFolder: File): List<Application> {
fun loadApplications(sourceFolder: File): List<ApplicationComponent> {
check(sourceFolder.isDirectory)
return sourceFolder.listFiles()!!
.filter { file -> file.extension == "json" }
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ sealed interface Component {
get() = systemIdOfComponent(id)
}

data class Application(
data class ApplicationComponent(
override val id: String,
override val type: ComponentType?,
override val distanceFromUs: Distance?,
Expand Down
Loading

0 comments on commit e3b6e3c

Please sign in to comment.