Skip to content

Conversation

@vnikolova
Copy link
Collaborator

@vnikolova vnikolova commented Dec 5, 2025

KTOR-9115

  • Rename existing Application structure topic to Routing organization
  • Create a new Application structure topic
  • Add a Module dependencies section in Modules

@coderabbitai
Copy link

coderabbitai bot commented Dec 5, 2025

Walkthrough

Adds a "Related topics" category entry; introduces a new routing-organization doc and updates navigation/tree entries to reference it; rewrites and expands server application structure and server modules documentation (architecture, DI, module loading/config); small edits to routing docs to point to the new routing file.

Changes

Cohort / File(s) Summary
Navigation & manifest
c.list, ktor.tree, topics/welcome.topic
Inserted category id="related" name="Related topics" order="1" in c.list; added a toc-element under "Developing applications" for server-application-structure.md and renamed the Routing toc-element topic to server-routing-organization.md in ktor.tree; updated Routing link in topics/welcome.topic.
New routing guidance
topics/server-routing-organization.md
Added new document describing routing organization patterns (group by file, package, nested paths, feature/domain) with Kotlin examples.
Application structure (large rewrite)
topics/server-application-structure.md
Replaced framing with focused guidance on maintainability/modularity/DI; added show-structure directive, multiple architectural patterns (default, layered, modular, feature-based, DDD, microservice), module wiring examples, folder layouts, and module loading/deployment guidance.
Server modules (expanded)
topics/server-modules.md
Reframed modules as Application extensions; added "Loading modules" (including embedded server), expanded configuration examples (HOCON/YAML), module dependency patterns (params/attributes/DI), concurrent loading guidance, and adjusted startup timeout default.
Routing doc updates
topics/server-routing.md
Updated two references from server-application-structure.md to server-routing-organization.md and formatted the notes as blockquotes.

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~25 minutes

Suggested reviewers

  • osipxd
  • marychatte
🚥 Pre-merge checks | ✅ 3
✅ Passed checks (3 passed)
Check name Status Explanation
Title check ✅ Passed The title 'KTOR-9115 Re-work the Application structure topic' clearly summarizes the main changes: restructuring application/routing documentation and creating new topics.
Description check ✅ Passed The description directly relates to the changeset by specifying the three main modifications: renaming topic to Routing organization, creating new Application structure topic, and adding Module dependencies section.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.


Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

@vnikolova vnikolova changed the title WIP: KTOR-9115 Re-work the Application structure topic KTOR-9115 Re-work the Application structure topic Dec 18, 2025
@vnikolova vnikolova requested a review from bjhham December 18, 2025 14:38
@vnikolova vnikolova marked this pull request as ready for review January 20, 2026 15:48
@vnikolova vnikolova requested a review from e5l January 20, 2026 15:48
Copy link

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 2

🤖 Fix all issues with AI agents
In `@topics/server-application-structure.md`:
- Around line 192-212: The diagram and example incorrectly place the
Ktor-specific CustomerRoutes.kt inside the domain layer; move CustomerRoutes.kt
out of domain into an application/presentation layer (e.g., application/ or
presentation/ package) and update the diagram so routes live under that layer,
not domain; also update the code example that references CustomerRoutes.kt (and
any imports) so it uses the new application/presentation package and ensure
domain files like Customer.kt and CustomerService.kt contain no Ktor imports or
route code.

In `@topics/server-routing-organization.md`:
- Around line 24-64: Add two aggregator extension functions named
customerRoutes() and orderRoutes() that group the existing route handlers:
implement Route.customerRoutes() to call customerByIdRoute() and
createCustomerRoute(), and implement Route.orderRoutes() to call getOrderRoute()
and totalizeOrderRoute(); ensure these aggregators are declared as Route
extension functions so the routing { customerRoutes(); orderRoutes() }
registration compiles and the individual handlers (customerByIdRoute,
createCustomerRoute, getOrderRoute, totalizeOrderRoute) are invoked inside each
aggregator.

Comment on lines +24 to +64
```kotlin
fun Route.customerByIdRoute() {
get("/customer/{id}") {

}
}

fun Route.createCustomerRoute() {
post("/customer") {

}
}
```
</tab>
<tab title="OrderRoutes.kt">

```kotlin
fun Route.getOrderRoute() {
get("/order/{id}") {

}
}

fun Route.totalizeOrderRoute() {
get("/order/{id}/total") {

}
}
```
</tab>
</tabs>

Each file groups route handlers that belong to the same domain area. Then, you can register each group in your
routing block:

```kotlin
routing {
customerRoutes()
orderRoutes()
}
```
Copy link

Choose a reason for hiding this comment

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

⚠️ Potential issue | 🟡 Minor

🧩 Analysis chain

🏁 Script executed:

# First, let's find and examine the file
fd topics/server-routing-organization.md

Repository: ktorio/ktor-documentation

Length of output: 51


🏁 Script executed:

# Check if the file exists and view lines 24-64
if [ -f "topics/server-routing-organization.md" ]; then
  echo "=== File exists, showing lines 24-80 for context ==="
  sed -n '24,80p' topics/server-routing-organization.md | cat -n
else
  echo "File not found at topics/server-routing-organization.md"
  # Try searching for similar files
  find . -name "*server*routing*" -o -name "*routing*organization*" 2>/dev/null | head -20
fi

Repository: ktorio/ktor-documentation

Length of output: 1531


🏁 Script executed:

# Let me check the full file to see if aggregators are defined elsewhere
wc -l topics/server-routing-organization.md

Repository: ktorio/ktor-documentation

Length of output: 110


🏁 Script executed:

# Check the beginning of the file and context around line 24
head -40 topics/server-routing-organization.md | cat -n

Repository: ktorio/ktor-documentation

Length of output: 1449


🏁 Script executed:

# Check lines 36-70 to see if aggregators are defined after the individual route functions
sed -n '36,70p' topics/server-routing-organization.md | cat -n

Repository: ktorio/ktor-documentation

Length of output: 1000


🏁 Script executed:

# Search the entire file for customerRoutes or orderRoutes definitions
grep -n "fun.*customerRoutes\|fun.*orderRoutes" topics/server-routing-organization.md

Repository: ktorio/ktor-documentation

Length of output: 154


🏁 Script executed:

# Let's examine the definitions of customerRoutes and orderRoutes at those lines
sed -n '95,115p' topics/server-routing-organization.md | cat -n

Repository: ktorio/ktor-documentation

Length of output: 916


🏁 Script executed:

# Also check for orderRoutes definition
grep -n "fun.*orderRoutes" topics/server-routing-organization.md

Repository: ktorio/ktor-documentation

Length of output: 51


🏁 Script executed:

# Let me search for orderRoutes in the entire file
grep -n "orderRoutes" topics/server-routing-organization.md

Repository: ktorio/ktor-documentation

Length of output: 89


🏁 Script executed:

# Let's look at the full context around the "Group by file" section to understand what's shown
sed -n '13,65p' topics/server-routing-organization.md | cat -n

Repository: ktorio/ktor-documentation

Length of output: 1372


🏁 Script executed:

# Let's confirm the full extent of the "Group by file" section to be thorough
sed -n '13,80p' topics/server-routing-organization.md | cat -n

Repository: ktorio/ktor-documentation

Length of output: 1939


Add aggregator functions to complete the "Group by file" example.

The example defines individual route handlers but the registration code calls customerRoutes() and orderRoutes() which aren't shown. The example needs these aggregators to be complete and compilable.

✏️ Proposed fix (add aggregators)
 fun Route.createCustomerRoute() {
     post("/customer") {
 
     }
 }
+
+fun Route.customerRoutes() {
+    customerByIdRoute()
+    createCustomerRoute()
+}
 fun Route.totalizeOrderRoute() {
     get("/order/{id}/total") {
 
     }
 }
+
+fun Route.orderRoutes() {
+    getOrderRoute()
+    totalizeOrderRoute()
+}
🤖 Prompt for AI Agents
In `@topics/server-routing-organization.md` around lines 24 - 64, Add two
aggregator extension functions named customerRoutes() and orderRoutes() that
group the existing route handlers: implement Route.customerRoutes() to call
customerByIdRoute() and createCustomerRoute(), and implement Route.orderRoutes()
to call getOrderRoute() and totalizeOrderRoute(); ensure these aggregators are
declared as Route extension functions so the routing { customerRoutes();
orderRoutes() } registration compiles and the individual handlers
(customerByIdRoute, createCustomerRoute, getOrderRoute, totalizeOrderRoute) are
invoked inside each aggregator.

@e5l e5l requested a review from zibet27 January 21, 2026 05:16
Comment on lines 347 to 348
In this structure, each service owns an isolated domain slice and remains modular internally, integrating with service
discovery, metrics, and external configuration.
Copy link
Contributor

Choose a reason for hiding this comment

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

You could also indicate here that you can use the canned main functions (i.e., io.ktor.server.cio.EngineMain) instead of the entry points (Application.kt), and you can deploy multiple microservices in the same instance via configuration, which is commonly referred to as a "modulith" deployment these days.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Added 2 sub-sections mentioning these. Can you check if they are correct?

Copy link
Contributor

Choose a reason for hiding this comment

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

Oh, I meant like the gradle modules for the microservices can be packaged independently and deployed together in the same application. It's not very important, but this modulith approach is getting more popular for teams that want the independence but without the overhead of managing multiple services.

Copy link

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 2

🤖 Fix all issues with AI agents
In `@topics/server-application-structure.md`:
- Around line 52-53: The link target uses the fragment
`#microservice-oriented-structure` but the corresponding heading "Microservice
architectures" is missing an explicit id; update that heading by appending the
explicit id {`#microservice-oriented-structure`} to the "Microservice
architectures" heading so the link fragment resolves and MD051 is satisfied.
- Around line 26-38: The fenced directory-tree code blocks in
topics/server-application-structure.md are missing a language tag (triggering
MD040); update each triple-backtick fence that contains a project/ directory
tree to use a plain language like ```text so they are treated as text.
Specifically, change the fence around the shown tree (the block that starts with
"project/" and contains "src/ main/ kotlin/ Application.kt") and apply the same
replacement to the other directory-tree fences referenced (the blocks at the
other ranges listed) so every directory-tree fence uses ```text.

Copy link

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 1

🤖 Fix all issues with AI agents
In `@topics/server-application-structure.md`:
- Around line 246-256: The snippet's CustomerService lacks a findById used by
routes; add a public suspend fun findById(id: CustomerId): Customer? to
CustomerService that delegates to repository.find(id) (or return
repository.find(id)?.let { CustomerAggregate(it) } depending on intended
return), so callers to customerService.findById(...) compile; update both
occurrences (lines near addContact and the other instance) to use this new
method if needed.

Comment on lines +246 to +256
class CustomerService(
private val repository: CustomerRepository,
private val events: EventPublisher
) {
suspend fun addContact(id: CustomerId, contact: Contact): Customer? {
val customer = repository.find(id) ?: return null
val updated = CustomerAggregate(customer).addContact(contact)
repository.save(updated)
events.publish(CustomerContactAdded(id, contact))
return updated
}
Copy link

Choose a reason for hiding this comment

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

⚠️ Potential issue | 🟡 Minor

Keep the DDD snippets consistent (missing findById).
CustomerService only defines addContact, but the route calls customerService.findById(...). Add the method (or change the route) so the example compiles as written.

✅ Proposed fix (add method to the snippet)
 class CustomerService(
     private val repository: CustomerRepository,
     private val events: EventPublisher
 ) {
     suspend fun addContact(id: CustomerId, contact: Contact): Customer? {
         val customer = repository.find(id) ?: return null
         val updated = CustomerAggregate(customer).addContact(contact)
         repository.save(updated)
         events.publish(CustomerContactAdded(id, contact))
         return updated
     }
+
+    suspend fun findById(id: CustomerId): Customer? =
+        repository.find(id)
 }

Also applies to: 287-291

🤖 Prompt for AI Agents
In `@topics/server-application-structure.md` around lines 246 - 256, The snippet's
CustomerService lacks a findById used by routes; add a public suspend fun
findById(id: CustomerId): Customer? to CustomerService that delegates to
repository.find(id) (or return repository.find(id)?.let { CustomerAggregate(it)
} depending on intended return), so callers to customerService.findById(...)
compile; update both occurrences (lines near addContact and the other instance)
to use this new method if needed.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants