- Home
- Skills
- APIs & Backend
- APIFactory: Dynamic Router Auto Registration
Works with the AI tools you already use
APIFactory: Dynamic Router Auto Registration
Automate API route and bot handler registration using dynamic package scanning instead of manual imports.
$9.99
APIFactory: Dynamic Router Auto Registration
Example session with this skill installed
I have 8 new handler files in my bot/handlers folder. How do I register them in the main dispatcher without writing 8 import lines?
- Read your context and instructions
- Compiled the apifactory
⚙️ ROUTER-FACTORY CONVEYOR: ENFORCING DYNAMIC ASSEMBLY LINE
Manual routing entries scale poorly and introduce regression faults.
Not generating manual registration rows. Injecting an automated route factory
that uses dynamic module scanning to link all checkout components at startup.
Generated a dynamic router factory for your aiogram bot. This replaces manual registration with automated package scanning.
Dynamic Router Factory Implementation
# bot/handlers/__init__.py
import importlib
import pkgutil
from aiogram import Router
def create_router_factory(package_name: str = __name__) -> Router:
"""
Scans the package for modules containing a 'router' object
and mounts them to a single master router.
"""
main_router = Router(name="auto_factory_router")
package = importlib.import_module(package_name)
for _, module_name, is_pkg in pkgutil.walk_packages(
package.__path__, package.__name__ + "."
):
if not is_pkg:
module = importlib.import_module(module_name)
if hasattr(module, "router") and isinstance(module.router, Router):
# Ensure we don't double-register
if module.router not in main_router.sub_routers:
main_router.include_router(module.router)
return main_router
# Singleton instance for the dispatcher
main_router = create_router_factory()
# bot/main.py
from aiogram import Dispatcher, Bot
from bot.handlers import main_router
async def main():
dp = Dispatcher()
dp.include_router(main_router)
# ... rest of startup logic
Next steps
- Ensure each of your 8 files in
bot/handlers/defines a variable namedrouter = Router(). - Delete any existing manual handler imports from your
main.pyto prevent duplicate execution. - Restart the bot; the factory will now pick up any new
.pyfiles added to that folder automatically.
Connects securely to your tools. The creator never sees your data.
What you get
About this skill
Manual route registration is a maintenance bottleneck that causes merge conflicts and forgotten endpoints. As your codebase grows, updating a central dispatcher file for every new feature becomes a regression risk. This skill forces your AI coding agent to implement dynamic router factories that scan your package directories at runtime.
What it does
- Automates discovery by using package scanning to find and register new route modules automatically.
- Eliminates boilerplate by replacing long lists of manual imports in your main application file with a single factory call.
- Enforces isolation by ensuring route modules remain decoupled from the dispatcher and from each other.
- Prevents collisions by checking for namespace conflicts before mounting discovered routers into the master tree.
- Scales architecture by providing a pluggable pattern where adding a new file is the only step required for deployment.
How it works
- Package Mapping involves the agent inspecting your directory tree to locate the subpackages where handlers or routes reside.
- Factory Generation creates a central
__init__.pyor factory utility usingpkgutilorimportlibto walk the package. - Module Mounting dynamically imports each module, validates the presence of a router object, and includes it in the master router.
Frameworks & tools
Works with Python-based web and bot frameworks including FastAPI, aiogram, and Express. Uses standard library modules like pkgutil and importlib for module discovery.
Why this beats prompting it yourself
Generic prompts often result in the AI suggesting manual imports because it is the "path of least resistance." This skill overrides that behavior, mandating a professional-grade architecture that prevents the dispatcher file from becoming a massive, conflict-prone monolith.
Use cases
- Refactoring a large FastAPI monolith into a modular, package-based architecture.
- Building complex Telegram bots with aiogram where handlers are spread across dozens of files.
- Setting up a collaborative backend where multiple developers need to add endpoints without touching core config files.
Known limitations
Not recommended for single-file scripts or small projects with fewer than three endpoints. Requires the runtime environment to allow dynamic file system discovery and imports.
How to install
Works the same in every agent - Claude, Cursor, Codex, Copilot and 20+ more.
- 1
Download the ZIP
Free skills download straight away. Paid skills unlock right after purchase.
- 2
Unzip into your skills folder
Every agent reads skills from one folder on your machine. Drop the unzipped folder in there.
- 3
Ask your agent to use it
Restart the agent if it was already running. It picks the skill up automatically - no config needed.
Skills folder by agent
Click the path to copy it. Create the folder if it does not exist yet.
Reviews
No reviews yet
Be one of the first to try it. Every listed skill passes our trust checks below.
Security scanned
Passed our 8-point scan before listing
Fresh listing
Recently published to Agensi
30-day refund
Not a fit? Get your money back
Trust & safety
Security scanned
Verified clean today
- Passed all security checks, Safe to install