Feat: Composable Subrouters and Routers#41
Merged
Conversation
Track number of routes explicitly instead of relying on NULL-terminated array iteration. Prepares for dynamic array migration. - Add route_count field to Router struct - Initialize to 0 in router creation - Increment when adding routes - Update loops to use route_count instead of NULL checks - Extract route matching into router_match function - Introduce Route struct
Add pluggable dispatcher interface for routing strategies: - Define Dispatcher with match, add_route, mount, free operations - Implement RegexRouterData with dynamic arrays - Create regex dispatcher with route flattening on mount - Add router_create_regex factory function - Add wrapper functions: router_add, router_mount, router_free - Migrate main.c to use dispatcher-based routing - Maintain backward compatibility with old router_match for now Enables composable routing and future dispatcher implementations.
- Fix regex_mount to properly handle regex patterns when mounting sub-routers. - Previously concatenated "/tests" + "^/test$" = "/tests^/test$" (invalid). - Now transforms "^/test$" with prefix "/tests" to "^/tests/test$". - Strip ^ and $ from child patterns before concatenation - Enables correct route flattening for composable routing
- created app/blog directory and initialized a router - the router was then mounted onto the main app It isnow possible to create many composable applications
- Add comprehensive routing system guide (docs/ROUTING.md) - Rename and update template system documentation - Remove template compiler (thc.c) in favor of external zc compiler - Clean up unused handlers and blog module - Update main.c to reflect routing changes
- Adds GitHub Actions workflow to auto-format C files on push/PR - Uses pre-commit with clang-format configured for Google style + custom rules - Removes need for developers to install LLVM or clang-format locally - Ensures consistent code style across the repository automatically
koutoftimer
reviewed
Feb 13, 2026
koutoftimer
reviewed
Feb 13, 2026
koutoftimer
reviewed
Feb 13, 2026
koutoftimer
reviewed
Feb 13, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Implements a composable, Express-style router with pluggable dispatch strategies. Uses dispatcher interface to separate routing logic from router API, enabling different implementations without changing user-facing code.
Key Changes
New Dispatcher Interface
Can match a route, add a route, mount a subrouter, free routes
Regex dispatcher with dynamic arrays and route flattening
Factory function to create the regex dispatcher router_create_regex()