This document outlines the design decisions and architectural approach for the Number to Words Converter web application. The solution implements a clean, maintainable architecture using ASP.NET Core Web API with a responsive web interface.
Reasons for Selection:
- Performance: ASP.NET Core is one of the fastest web frameworks with excellent throughput
- Cross-platform: Runs on Windows, Linux, and macOS
- Modern Framework: Latest .NET 8.0 provides current language features and optimizations
- Dependency Injection: Built-in DI container for clean separation of concerns
- Developer Productivity: Strong typing, IntelliSense, and comprehensive tooling
Alternatives Considered:
- Java Spring Boot: Excellent option but requires more boilerplate code
- Node.js: Good for simple APIs but lacks strong typing without TypeScript
- Python Flask/Django: Good options but performance is lower than .NET Core
Reasons for Selection:
-
Simplicity: No build process required for a simple conversion tool
-
Performance: No framework overhead for a single-page application
-
Browser Compatibility: Works in all modern browsers without transpilation
-
Maintainability: Easy to understand and modify without framework knowledge
-
Alternatives Considered:
-
React: Overkill for a single-form application
-
Angular: Too heavy for simple requirements
-
Vue.js: Good option but adds unnecessary complexity
Implementation:
POST /api/conversion/convert
{
"value": "123.45"
}
Response:
{
"success": true,
"words": "ONE HUNDRED AND TWENTY-THREE DOLLARS AND FORTY-FIVE CENTS",
"originalValue": "123.45"
}
Reasons:
- Standard HTTP Methods: Uses POST for conversion operation
- JSON Format: Universal data format for web APIs
- Clear Response Structure: Includes success flag and error messages
- Stateless: Each request is independent
Implementation:
INumberToWordsServiceinterface for abstractionNumberToWordsServiceconcrete implementation- Registered as Scoped in DI container
Benefits:
- Testability: Easy to mock for unit testing
- Flexibility: Can swap implementations
- Separation of Concerns: Business logic separated from controllers
Approach:
- Input Validation: Regex pattern for currency format validation
- Number Parsing: Convert string to decimal with proper culture handling
- Range Checking: Ensure number is within supported range
- Dollar/Cents Separation: Split decimal into whole and fractional parts
- Recursive Conversion: Break down numbers into groups of thousands
- Text Assembly: Build final string with proper formatting
Key Features:
- Handles numbers up to 999,999,999.99
- Supports negative numbers
- Proper singular/plural handling (DOLLAR vs DOLLARS)
- Groups of three digits (thousands, millions)
Algorithm Complexity:
- Time: O(log n) where n is the number value
- Space: O(1) constant space for conversion arrays
- Client-Side: Basic validation for empty input
- Controller Level: Format validation using regex
- Service Level: Business rule validation
- Global Exception Handling: Catch-all for unexpected errors
Error Response Format:
{
"success": false,
"error": "Descriptive error message"
}- Regex Pattern:
^-?\d{1,9}(\.\d{0,2})?$ - Prevents SQL injection by not using database
- Prevents XSS by validating input format
- Limited input size to prevent DoS attacks
- Input sanitization before processing
- Proper HTTP status codes for errors
- No sensitive data in responses
- Simplicity: Single-purpose interface
- Responsiveness: Works on all device sizes
- Accessibility: Proper labels and ARIA attributes
- Feedback: Clear success/error messages
- Auto-focus on input field
- Enter key submission
- Loading state during conversion
- Animated result display
- Example conversions shown
- Minimal Dependencies: Only Swashbuckle for API documentation
- Efficient Algorithm: No recursive string concatenation
- Client-Side Caching: Browser caches static assets
- Async Operations: Non-blocking API calls
Rejected Because:
- No requirement for persistence
- Adds complexity without value
- Performance overhead for simple calculations
Rejected Because:
- Over-engineering for single functionality
- Deployment complexity
- Network latency between services
Rejected Because:
- Business logic exposure in browser
- Limited programming capabilities
- Harder to maintain complex conversion logic
- Internationalization: Support for other currencies and languages
- Caching: Redis cache for common conversions
- Batch Processing: Convert multiple numbers at once
- API Rate Limiting: Prevent abuse
- Analytics: Track usage patterns
- Unit Testing: Comprehensive test suite
The chosen approach balances simplicity with functionality, providing a clean, maintainable solution that meets all requirements while remaining extensible for future enhancements. The architecture follows SOLID principles and industry best practices for web application development.