Features & Implementation Roadmap
TDI2 follows Spring Boot conventions for familiar enterprise patterns. This guide covers implemented features, roadmap items, and production readiness assessment.
📋 Architecture Context: See ADR-005: Spring Boot Conventions for why TDI2 adopts Spring Boot patterns.
Design Motivation
Section titled “Design Motivation”TDI2 addresses fundamental scalability issues in React’s original architecture. React was designed as a declarative UI library for small to medium applications. However, as complexity and size increase, different requirements emerge: modularity, exchangeability, testing, and environment-based configuration gain importance. The idiomatic React model (Props, Context, Hooks) no longer scales systematically in these scenarios.
Enterprise React Architecture Problems
Section titled “Enterprise React Architecture Problems”Hard Coupling Through Direct Imports: Components reference services directly via import, eliminating exchangeability.
Props Drilling and Manual Composition: Data and function passing across multiple component levels creates structural dependencies and redundancy.
No Central Lifecycle or Dependency Management: React offers no native way to centrally register, profile, or scope services.
Testing and Mocking Fragmentation: Mocks must be manually injected or replaced through global store adjustments.
No Environment or Profile Concept: React lacks service-based environment configuration (Test vs Prod) at the architecture level.
TDI2’s Enterprise Solution
Section titled “TDI2’s Enterprise Solution”- Compile-Time Resolver for dependencies
- TypeScript Metadata utilization for automatic injection
- Hooks as Injectable Interface (
useService) - Profile and Scoping Support for environment configuration
- OpenTelemetry, Logging, Linting and Debugging support (planned)
- Build-Time Resolution instead of runtime for maximum performance
TDI2 Architecture Model
Section titled “TDI2 Architecture Model”Application Layer├── Controller Components│ └── useService(InvoiceService)├── UI Components│ └── Presentational onlyDomain Layer├── Interfaces (e.g. InvoiceService)├── Logic (e.g. DefaultInvoiceService)Infrastructure Layer├── HttpAdapters├── Mock ImplementationsTarget Audience
Section titled “Target Audience”- Enterprise React Applications with high complexity
- Teams requiring exchangeable infrastructure
- Projects with multiple environments and profiles
- Applications with strict testing and logging requirements
Current Implementation Status
Section titled “Current Implementation Status”✅ Core Features (Production Ready)
Section titled “✅ Core Features (Production Ready)”| Feature | Description | Implementation Status | Spring Boot Equivalent |
|---|---|---|---|
| @Service | Service registration decorator | ✅ Complete | @Service, @Component |
| @Inject | Dependency injection decorator | ✅ Complete | @Autowired |
| Compile-Time DI Resolver | Build-time dependency resolution | ✅ Complete | N/A (TDI2 innovation) |
| TypeScript Metadata | Automatic injection via TS types | ✅ Complete | N/A (TDI2 innovation) |
| useService Hook | Injectable service interface for React | ✅ Complete | N/A (React-specific) |
| Interface Resolution | Automatic interface → implementation mapping | ✅ Complete | Type-based autowiring |
| Container | DI container with lifecycle management | ✅ Complete | ApplicationContext |
✅ Recently Completed (Production Ready)
Section titled “✅ Recently Completed (Production Ready)”These features were recently completed and are now production ready:
| Feature | Description | Implementation Status | Spring Boot Equivalent |
|---|---|---|---|
| @PostConstruct | Post-construction lifecycle hook via onInit | ✅ Complete | @PostConstruct |
| @PreDestroy | Pre-destruction lifecycle hook via onDestroy | ✅ Complete | @PreDestroy |
| @Profile | Environment/profile-based service activation | ✅ Complete | @Profile |
| @Configuration | Configuration class decorator | ✅ Complete | @Configuration |
| @Bean | Bean definition decorator | ✅ Complete | @Bean |
| Lifecycle Hooks | onMount/onUnmount for component lifecycle | ✅ Complete | N/A (React-specific) |
🧪 Testing Framework (Production Ready)
Section titled “🧪 Testing Framework (Production Ready)”| Feature | Description | Implementation Status | Spring Boot Equivalent |
|---|---|---|---|
| @DiTest | DI testing framework equivalent | ✅ Complete | @ExtendWith(SpringExtension.class) |
| @MockBean | Mock bean for testing | ✅ Complete | @MockBean |
| Testing Utilities | Advanced mock and test container utilities | ✅ Complete | @TestConfiguration |
📋 Future Enhancements (Future Releases)
Section titled “📋 Future Enhancements (Future Releases)”| Feature | Description | Implementation Status | Priority | ETA |
|---|---|---|---|---|
| ESLint Plugin | Rule verification for DI patterns | ❌ Research phase | Low | Q1 2025 |
| OpenTelemetry Integration | Distributed tracing support | ❌ Research phase | Low | Q1 2025 |
| DevTools Integration | Browser debugging interface | ❌ Research phase | Medium | Q1 2025 |
| SSR Compatibility | Server-side rendering support | ❌ Research phase | High | Q2 2025 |
| Hot Module Replacement | HMR support for services | ❌ Research phase | Medium | Q2 2025 |
Feature Deep Dive
Section titled “Feature Deep Dive”Core Features (Available Now)
Section titled “Core Features (Available Now)”@Service Decorator
Section titled “@Service Decorator”// Basic service registration@Service()export class ProductService implements ProductServiceInterface { state = { products: [] as Product[] };}
// With explicit scope@Service()@Scope("singleton") // Default behaviorexport class ConfigService { // Single instance across application}
@Service()@Scope("transient") // New instance each injectionexport class RequestLogger { // Fresh instance for each component}Advanced @Inject Patterns
Section titled “Advanced @Inject Patterns”// Interface-based injection (recommended)@Service()export class OrderService { constructor( @Inject() private paymentService: PaymentServiceInterface, @Inject() private emailService: EmailServiceInterface, @Inject() private logger?: LoggerServiceInterface // Optional dependency ) {}}
// Functional component injectionfunction CheckoutFlow({ orderService, paymentService}: { orderService: Inject<OrderServiceInterface>; paymentService: Inject<PaymentServiceInterface>;}) { // Services automatically injected via build-time transformation}Lifecycle Features (Production Ready)
Section titled “Lifecycle Features (Production Ready)”@PostConstruct Implementation
Section titled “@PostConstruct Implementation”Current Status: ✅ Complete - Implemented via onInit interface
@Service()export class DatabaseService { private connection: Connection | null = null;
@PostConstruct async initialize(): Promise<void> { // Called after all dependencies injected this.connection = await createConnection(this.config); console.log('Database connection established'); }
constructor( @Inject() private config: DatabaseConfig ) {}}Implementation Plan:
- Phase 1: Container calls
@PostConstructmethods after instantiation - Phase 2: Support async initialization with dependency ordering
- Phase 3: Error handling and initialization retry logic
@PreDestroy Implementation
Section titled “@PreDestroy Implementation”Current Status: ✅ Complete - Implemented via onDestroy interface
@Service()export class CacheService { private cache = new Map();
@PreDestroy async cleanup(): Promise<void> { // Called before service destruction this.cache.clear(); await this.flushPendingWrites(); console.log('Cache service cleaned up'); }}Implementation Plan:
- Phase 1: Container calls
@PreDestroyon application shutdown - Phase 2: React component unmount cleanup integration
- Phase 3: Graceful shutdown with timeout handling
@Profile Implementation
Section titled “@Profile Implementation”Current Status: ✅ Complete - Full profile filtering and environment-based activation
@Service()@Profile("development")export class MockEmailService implements EmailServiceInterface { sendEmail(to: string, message: string): Promise<void> { console.log(`Mock email to ${to}: ${message}`); return Promise.resolve(); }}
@Service()@Profile("production")export class SmtpEmailService implements EmailServiceInterface { sendEmail(to: string, message: string): Promise<void> { return this.smtpClient.send({ to, body: message }); }}
// Multiple profile support@Service()@Profile(["staging", "production"])export class RedisCache implements CacheServiceInterface { // Only active in staging or production}Implementation Plan:
- Phase 1: Environment-based profile activation (NODE_ENV)
- Phase 2: Custom profile configuration and runtime switching
- Phase 3: Conditional profiles with expressions
Configuration Features (Production Ready)
Section titled “Configuration Features (Production Ready)”@Configuration Classes
Section titled “@Configuration Classes”Current Implementation:
@Configuration()export class DatabaseConfiguration {
@Bean() @Profile("development") createDevDatabase(): DatabaseConnection { return new SqliteConnection('dev.db'); }
@Bean() @Profile("production") createProdDatabase( @Inject() config: EnvironmentConfig ): DatabaseConnection { return new PostgresConnection({ host: config.DB_HOST, port: config.DB_PORT, database: config.DB_NAME }); }
@Bean() createConnectionPool( @Inject() database: DatabaseConnection ): ConnectionPool { return new ConnectionPool(database, { maxConnections: 20 }); }}Benefits:
- External library integration without wrapping
- Environment-specific bean creation
- Method-level dependency injection
- Factory pattern support
Production Readiness Assessment
Section titled “Production Readiness Assessment”✅ Production Ready (Can Use Today)
Section titled “✅ Production Ready (Can Use Today)”Core DI Functionality:
- Service registration and dependency injection
- Interface-based resolution
- Singleton and transient scopes
- Type-safe container operations
- React component transformation
- Testing framework integration
Code Reduction Impact:
- 90-95% reduction in AST transformation boilerplate
- 80-85% reduction in manual dependency wiring
- 70-75% reduction in prop drilling code
Performance Characteristics:
- O(1) service lookup via compile-time resolution
- Zero runtime reflection overhead
- Tree-shakable service registration
- Memory efficient singleton management
🚧 Production Blockers (Address Before Enterprise Use)
Section titled “🚧 Production Blockers (Address Before Enterprise Use)”Recently Resolved Production Blockers:
-
Lifecycle Management ✅ Complete
- Resolution: @PostConstruct/@PreDestroy implemented via onInit/onDestroy interfaces
- Status: Production ready with full async support
-
Configuration Management ✅ Complete
- Resolution: @Configuration and @Bean decorators fully implemented
- Status: Factory patterns and method-level injection working
-
Testing Framework ✅ Complete
- Resolution: Full testing utilities with @DiTest and @MockBean equivalents
- Status: Production ready testing infrastructure
🔬 Advanced Features (Post-MVP)
Section titled “🔬 Advanced Features (Post-MVP)”Nice-to-Have Enhancements:
- Enhanced debugging and introspection tools
- React DevTools integration
- Advanced scoping models (request, tree, component)
- Server-side rendering support
- Automatic code-splitting integration
Implementation Priority Roadmap
Section titled “Implementation Priority Roadmap”✅ Completed Milestones
Section titled “✅ Completed Milestones”Production MVP ✅ COMPLETE
Section titled “Production MVP ✅ COMPLETE”-
@PostConstruct runtime support ✅ Complete
- Container calls lifecycle methods after instantiation
- Async initialization support
- Error handling for initialization failures
-
@PreDestroy runtime support ✅ Complete
- Application shutdown lifecycle
- Component unmount cleanup integration
- Graceful shutdown with timeout
-
@Configuration and @Bean support ✅ Complete
- Configuration class processing
- Method-level dependency injection
- Factory pattern support
Developer Experience ✅ COMPLETE
Section titled “Developer Experience ✅ COMPLETE”-
@Profile runtime implementation ✅ Complete
- Environment-based activation
- Multi-profile support
- Runtime profile switching
-
Testing framework ✅ Complete
- @DiTest equivalent functionality
- @MockBean implementation
- Advanced mocking utilities
- Integration test helpers
Next Sprint (Advanced Features - 2-3 weeks)
Section titled “Next Sprint (Advanced Features - 2-3 weeks)”-
Tree-scoped providers
- React tree integration
- Provider boundary management
- Multi-tenant service isolation
-
SSR preparation
- Request-scoped containers
- Server/client state synchronization
- Hydration safety measures
Technical Implementation Notes
Section titled “Technical Implementation Notes”AST Transformation Pipeline
Section titled “AST Transformation Pipeline”Current codebase uses sophisticated TypeScript AST manipulation:
- 800+ lines reduced to 50-100 lines with optimized libraries
- ts-query + ts-morph recommended for 90% code reduction
- jscodeshift as fallback for complex transformations
Container Architecture
Section titled “Container Architecture”- Singleton management with lazy instantiation
- Circular dependency detection with clear error messages
- Interface-based tokens prevent naming collisions
- Compile-time validation catches configuration errors
React Integration
Section titled “React Integration”- Functional component transformation at build time
- useSnapshot integration for reactive state updates
- StrictMode compatibility with idempotent factories
- Hot reload support with development mode optimization
Migration Strategy
Section titled “Migration Strategy”For Existing React Applications
Section titled “For Existing React Applications”Phase 1: Start with new features using TDI2 patterns
// New feature uses TDI2@Service()export class NewFeatureService { // Implementation with DI patterns}
// Existing components unchangedfunction ExistingComponent() { // Keep current patterns during transition}Phase 2: Gradually refactor complex components
// Before: Complex component with multiple concernsfunction ComplexComponent() { const [users, setUsers] = useState([]); const [loading, setLoading] = useState(false); // ... 50+ lines of state management}
// After: Simple template with service injectionfunction ComplexComponent({ userService }: { userService: Inject<UserServiceInterface> }) { const { users, loading } = userService.state; return <UserList users={users} loading={loading} />;}Phase 3: Enterprise-wide adoption with team training and guidelines
Best Practices for Production Deployment
Section titled “Best Practices for Production Deployment”- Start Small: Begin with isolated features or new components
- Team Training: Ensure developers understand DI patterns and service design
- Testing Strategy: Implement comprehensive service and integration testing
- Performance Monitoring: Track bundle size and runtime performance impacts
- Gradual Rollout: Phase adoption across team and application areas
- Documentation: Maintain clear service interfaces and usage examples
The current implementation provides a solid foundation for enterprise React applications, with the lifecycle management features completing the production readiness requirements.
Conclusion
Section titled “Conclusion”TDI2 aims for the structural reorganization of reactive architectures, without undermining React’s declarative foundation. The approach is deliberately systematic, not idiomatic – as a bridge between conventional frontend and architecture-driven software development.
This systematic approach addresses the gap between React’s component-centric model and enterprise-scale application requirements, providing a foundation for scalable, testable, and maintainable React applications that align with established software engineering principles.