How naomis/router works
Main Components
• Core Module: Under src/core, you have components such as MetadataStorage.ts, MethodDecoratorFactory.ts, and RouterRegistry.ts. This module is responsible for handling metadata extraction from decorator usage, constructing the route mappings, and registering them with the Express application.
• Decorators: The module under src/decorators contains individual decorators like Controller.ts, Get.ts, Post.ts, Delete.ts, and Put.ts. These encapsulate the logic for annotating classes and methods.
• Utilities: The src/utils folder (with, for instance, types.ts) holds utility functions or type definitions used across the library.
• Examples: The examples folder provides a sample Usage scenario, including a sample controller and server setup, which illustrates how a consumer would integrate the library with Express.
• Tests: The tests folder includes unit/integration tests that validate the functionality of the API, especially regarding how routes are set up.
Relationships and Interactions
• The decorators (from src/decorators) are applied to user-defined classes and methods to capture necessary metadata.
• Metadata Storage in the Core module collects this data.
• The Router Registry then reads this metadata and dynamically registers the routes with an Express application.
• The examples simulate how these components interact, while tests ensure expected interactions and behavior.
Important Architectural Patterns
• Separation of Concerns: The design clearly separates route annotation (decorators) from route registration (RouterRegistry) and metadata handling (MetadataStorage).
• Decorator Pattern: Utilization of TypeScript decorators abstracts routing logic from business logic.
• Configuration-driven Registration: Passing options (like API prefixes and middlewares) to the RouterRegistry to integrate routes into Express.
Relevant Technologies and Frameworks
• Node.js as the runtime environment.
• Express.js for HTTP server functionalities.
• TypeScript for type safety and use of decorators.
• Testing with Jest.
• GitHub Actions for CI/CD support (as seen in the .github/workflows directory).