- Home
- Skills
- APIs & Backend
- APIFactory — Auto-Register Routes Without Import Hell
Works with the AI Agents you already use
APIFactory — Auto-Register Routes Without Import Hell
Kill manual import hell and merge conflicts forever. Forces your AI agent to implement dynamic route auto-registration factories that scan package directories at runtime.
$5
APIFactory — Auto-Register Routes Without Import Hell
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.
About this skill
Manual route registration is a critical maintenance bottleneck that consistently introduces annoying merge conflicts, messy git histories, and forgotten endpoints. As your system expands, forcing developers or AI to constantly touch a central dispatcher file for every new feature creates an unnecessary regression risk. APIFactory completely overrides this brittle workflow, mandating your AI coding agent to construct bulletproof, dynamic router factories that scan your package directories natively at runtime. Core Benefits & Capabilities
- Automated Package Discovery: Leverages runtime package scanning to immediately locate, map, and mount new route modules as soon as the files are created.
- Complete Boilerplate Elimination: Replaces fragile, endlessly growing lists of manual imports in your core layout configuration file with a single, elegant factory call.
- Strict Architectural Isolation: Guarantees that route modules remain cleanly decoupled from the main app dispatcher and entirely independent of each other.
- Collision & Namespace Prevention: Automatically validates directory structures and monitors for namespace conflicts before dynamically mounting discovered routers into the master application tree.
- Seamless Scalability: Provides a highly pluggable pattern where simply dropping a new handler file into a directory is the only step required for full deployment.
Technical Execution Workflow
- Package Tree Mapping: The AI agent analyzes your project directory architecture to isolate the subpackages where endpoints, handlers, or routes reside.
- Factory Generation: The agent structures a central init.py or factory utility leveraging standard Python architecture (pkgutil or importlib) to programmatically walk the target package.
- Dynamic Module Mounting: The factory dynamically imports each module on app initialization, validates the presence of the router instance, and cleanly registers it with the master dispatcher.
Supported Frameworks & Standard Library Stack Optimized out-of-the-box for high-performance Python-based web and bot ecosystems, including FastAPI and aiogram, as well as modular Express layouts. Built entirely on top of robust standard library components (pkgutil and importlib) for native, dependency-free module discovery. Why This Beats Manual Prompting Standard AI prompts usually settle for manual imports because hardcoding lines is the "path of least resistance" for an LLM. APIFactory strictly blocks this behavior, enforcing a professional-grade decoupled architecture that completely protects your main configuration file from turning into an unmaintainable, conflict-prone monolith.
How to use
- 1
Connect your agent to the Agensi MCP
Copy the prompt and paste it into Claude, ChatGPT, Cursor or any agent that supports MCP. It sets up the connection for you. Manual setup
- 2
Sign in to Agensi
Your agent shows a sign-in link. Sign in and click Allow.
- 3
Ask for what you need
Your agent loads this skill and uses it on your task. It always asks before any payment.
Reviews
No reviews yet
Be one of the first to try it. Every listed skill goes through the trust checks below.
Security scanned
Checked by our 8-point scan before listing
Fresh listing
Recently published to Agensi
Money-back guarantee
Doesn't do what its page promises? You get your money back.
Trust & safety
Security scan
Security scan passed with 1 warning 3 days ago
Requires