Skip to content

Feat: Composable Subrouters and Routers#41

Merged
oduortoni merged 14 commits intomainfrom
feat/composable-subrouters-and-routers
Feb 13, 2026
Merged

Feat: Composable Subrouters and Routers#41
oduortoni merged 14 commits intomainfrom
feat/composable-subrouters-and-routers

Conversation

@oduortoni
Copy link
Owner

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()

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
@oduortoni oduortoni linked an issue Feb 12, 2026 that may be closed by this pull request
oduortoni and others added 10 commits February 12, 2026 17:38
- 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
@oduortoni oduortoni marked this pull request as ready for review February 13, 2026 08:27
@oduortoni oduortoni merged commit d87e3ac into main Feb 13, 2026
1 check passed
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.

Composable subrouters and routers

2 participants