8.1 KiB
8.1 KiB
Route Package Gap Analysis
Overview
This document analyzes the gaps between our Route package's actual implementation and Laravel's routing functionality, identifying areas that need implementation or documentation updates.
Related Documentation
- See Route Package Specification for current implementation
- See Laravel Compatibility Roadmap for overall status
- See Foundation Integration Guide for integration patterns
- See Testing Guide for testing approaches
- See Getting Started Guide for development setup
- See Pipeline Package Specification for middleware pipeline
- See Container Package Specification for dependency injection
Implementation Gaps
1. Missing Laravel Features
// Documented but not implemented:
// 1. Route Model Binding
class RouteModelBinding {
// Need to implement:
void bind(String key, Type type);
void bindWhere(String key, Type type, Function where);
void bindCallback(String key, Function callback);
void scopeBindings();
}
// 2. Route Caching
class RouteCache {
// Need to implement:
Future<void> cache();
Future<void> clear();
bool isEnabled();
Future<void> reload();
Future<void> compile();
}
// 3. Route Fallbacks
class RouteFallback {
// Need to implement:
void fallback(dynamic action);
void missing(Function callback);
void methodNotAllowed(Function callback);
void notFound(Function callback);
}
2. Missing Route Features
// Need to implement:
// 1. Route Constraints
class RouteConstraints {
// Need to implement:
void pattern(String name, String pattern);
void patterns(Map<String, String> patterns);
bool matches(String name, String value);
void whereNumber(List<String> parameters);
void whereAlpha(List<String> parameters);
void whereAlphaNumeric(List<String> parameters);
void whereUuid(List<String> parameters);
}
// 2. Route Substitutions
class RouteSubstitution {
// Need to implement:
void substitute(String key, dynamic value);
void substituteBindings(Map<String, dynamic> bindings);
void substituteImplicit(Map<String, Type> bindings);
String resolveBinding(String key);
}
// 3. Route Rate Limiting
class RouteRateLimiting {
// Need to implement:
void throttle(String name, int maxAttempts, Duration decay);
void rateLimit(String name, int maxAttempts, Duration decay);
void forUser(String name, int maxAttempts, Duration decay);
void exempt(List<String> routes);
}
3. Missing Group Features
// Need to implement:
// 1. Group Attributes
class RouteGroupAttributes {
// Need to implement:
void controller(Type controller);
void namespace(String namespace);
void name(String name);
void domain(String domain);
void where(Map<String, String> patterns);
}
// 2. Group Middleware
class RouteGroupMiddleware {
// Need to implement:
void aliasMiddleware(String name, Type middleware);
void middlewarePriority(List<String> middleware);
void pushMiddlewareToGroup(String group, String middleware);
List<String> getMiddlewareGroups();
}
// 3. Group Resources
class RouteGroupResources {
// Need to implement:
void resources(Map<String, Type> resources);
void apiResources(Map<String, Type> resources);
void singleton(String name, Type controller);
void apiSingleton(String name, Type controller);
}
Documentation Gaps
1. Missing API Documentation
// Need to document:
/// Binds route model.
///
/// Example:
/// ```dart
/// router.bind('user', User, (value) async {
/// return await User.find(value);
/// });
/// ```
void bind(String key, Type type, [Function? callback]);
/// Defines route pattern.
///
/// Example:
/// ```dart
/// router.pattern('id', '[0-9]+');
/// router.get('users/{id}', UsersController)
/// .where('id', '[0-9]+');
/// ```
void pattern(String name, String pattern);
2. Missing Integration Examples
// Need examples for:
// 1. Route Model Binding
router.bind('user', User);
router.get('users/{user}', (User user) {
return user; // Auto-resolved from ID
});
// 2. Route Rate Limiting
router.middleware(['throttle:60,1'])
.group(() {
router.get('api/users', UsersController);
});
// 3. Route Resources
router.resources({
'photos': PhotoController,
'posts': PostController
});
3. Missing Test Coverage
// Need tests for:
void main() {
group('Route Model Binding', () {
test('resolves bound models', () async {
router.bind('user', User);
var response = await router.dispatch(
Request('GET', '/users/1')
);
expect(response.data, isA<User>());
expect(response.data.id, equals('1'));
});
});
group('Route Caching', () {
test('caches compiled routes', () async {
await router.cache();
var route = router.match(
Request('GET', '/users/1')
);
expect(route, isNotNull);
expect(route!.compiled, isTrue);
});
});
}
Implementation Priority
-
High Priority
- Route model binding (Laravel compatibility)
- Route caching (Laravel compatibility)
- Route constraints
-
Medium Priority
- Route substitutions
- Route rate limiting
- Group resources
-
Low Priority
- Route fallbacks
- Additional constraints
- Performance optimizations
Next Steps
-
Implementation Tasks
- Add route model binding
- Add route caching
- Add route constraints
- Add group resources
-
Documentation Tasks
- Document model binding
- Document caching
- Document constraints
- Add integration examples
-
Testing Tasks
- Add binding tests
- Add caching tests
- Add constraint tests
- Add resource tests
Development Guidelines
1. Getting Started
Before implementing routing features:
- Review Getting Started Guide
- Check Laravel Compatibility Roadmap
- Follow Testing Guide
- Use Foundation Integration Guide
- Review Route Package Specification
- Review Pipeline Package Specification
- Review Container Package Specification
2. Implementation Process
For each routing feature:
- Write tests following Testing Guide
- Implement following Laravel patterns
- Document following Getting Started Guide
- Integrate following Foundation Integration Guide
3. Quality Requirements
All implementations must:
- Pass all tests (see Testing Guide)
- Meet Laravel compatibility requirements
- Follow integration patterns (see Foundation Integration Guide)
- Match specifications in Route Package Specification
4. Integration Considerations
When implementing routing features:
- Follow patterns in Foundation Integration Guide
- Ensure Laravel compatibility per Laravel Compatibility Roadmap
- Use testing approaches from Testing Guide
- Follow development setup in Getting Started Guide
5. Performance Guidelines
Routing system must:
- Match routes efficiently
- Handle complex patterns
- Support caching
- Scale with route count
- Meet performance targets in Laravel Compatibility Roadmap
6. Testing Requirements
Route tests must:
- Cover all route types
- Test pattern matching
- Verify middleware
- Check parameter binding
- Follow patterns in Testing Guide
7. Documentation Requirements
Route documentation must:
- Explain routing patterns
- Show group examples
- Cover parameter binding
- Include performance tips
- Follow standards in Getting Started Guide