Skip to content

Conversation

@AghastyGD
Copy link
Owner

@AghastyGD AghastyGD commented Jun 17, 2025

The previous register_model_routes_internal() function had grown to over 600 lines, combining sync/async routing. This made the codebase hard to maintain, extend, and test.

This PR addresses that by extracting each responsibility into its own module and introducing a clear router class hierarchy. The new structure improves separation of concerns, testability, extensibility, and overall readability.

Key Changes

Router Refactor:
Introduced a BaseModelRouter class in router/base.py for shared configuration and route wiring.
Added AsyncModelRouter and SyncModelRouter subclasses in router/async_router.py and router/sync_router.py, each handling their respective route registration logic.

Handlers & Utilities:
Moved response serialization logic to handlers/response.py.
Centralized file upload extraction and relation logic in handlers/file_handler.py.
Moved foreign key conversion and related utilities to utils/model.py.
Moved hook execution logic to utils/hooks.py.
Kept file_upload.py and pagination.py focused and minimal.

Benefits

Separation of Concerns:
Each module now handles a single responsibility (routing, file handling, hooks, etc.), making the codebase easier to understand and maintain.

Testability:
Smaller, focused functions and classes are easier to unit-test and debug.

Extensibility:
Adding new features (e.g., custom pagination strategies, new hook types) is now straightforward and does not require editing a monolithic function.

Readability & Onboarding:
New contributors can easily find code by topic, rather than scrolling through a massive function.

Migration Notes

No breaking changes to the public API.
All existing features (sync/async routing, file uploads, hooks, pagination, filtering, FK conversion) are preserved and now easier to extend.
This refactor lays the foundation for a more maintainable and scalable Lazy Ninja. Feedback and suggestions are welcome!

closes #29

…dularity

- Refactored core utilities for model operations, including foreign key conversion and serialization, to support both sync and async contexts.
- Improved separation of concerns by introducing handler classes for sync and async responses.
- Enhanced hook execution logic for pre/post-processing in both sync and async flows.
- Modularized schema generation utilities for creating Pydantic models from Django models.
- Improved code readability, maintainability, and testability across the codebase.
… instructions; refactor file_upload.py to comment out unused code
@AghastyGD AghastyGD self-assigned this Jun 17, 2025
@AghastyGD AghastyGD added the enhancement New feature or request label Jun 17, 2025
@AghastyGD AghastyGD marked this pull request as ready for review June 20, 2025 12:40
@AghastyGD AghastyGD merged commit 23d8d66 into dev Jun 20, 2025
3 checks passed
@AghastyGD AghastyGD deleted the refactor-into-modular-architecture branch August 11, 2025 14:48
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

enhancement New feature or request

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant