- Remove nested git repository from bugulma/frontend/.git - Add all frontend files to main repository tracking - Convert from separate frontend/backend repos to unified monorepo - Preserve all frontend code and development history as tracked files - Eliminate nested repository complexity for simpler development workflow This creates a proper monorepo structure with frontend and backend coexisting in the same repository for easier development and deployment.
4.2 KiB
Refactoring Progress and To-Do List
This document tracks the ongoing effort to refactor the codebase to improve its quality, maintainability, and adherence to modern best practices like the Single Responsibility Principle (SRP) and DRY (Don't Repeat Yourself).
Progress
1. Separation of Data and UI Logic
We have established a clear architectural pattern for separating data-fetching and state management from UI rendering logic. This makes components cleaner, easier to test, and more maintainable.
-
OrganizationPageRefactor:- Created
useOrganizationDatahook to handle all data fetching and Zod validation for a single organization. - Simplified the
useOrganizationPagehook to focus exclusively on UI state and user interaction logic. - Broke down the main component into smaller, focused components like
OrganizationContent.
- Created
-
MapViewRefactor:- Created
useMapDatahook to centralize fetching, filtering, and Zod validation of map-related data (organizations and landmarks). - Refactored the monolithic
MapViewContextinto several smaller, more focused contexts (MapViewportContext,MapInteractionContext, etc.) for better state management.
- Created
2. Component Decomposition and Reusability
PartnershipHubDecomposition: ThePartnershipHubcomponent was broken down into smaller sub-components (AIAnalysisTab,WebIntelTab), each responsible for a single tab's content.MapSidebarDecomposition: TheMapSidebar's content rendering logic was extracted into a dedicatedSidebarContentcomponent.AddOrganizationWizardDecomposition: TheAddOrganizationWizardcomponent was refactored to delegate its rendering logic to newWizardContentandWizardFootercomponents, improving SRP.- Reusable
IconButton: A newIconButtoncomponent was created to standardize the look and feel of icon-only buttons, reducing code duplication.
3. Added Critical Unit Tests
To improve the reliability of our business logic, we have added Vitest unit tests for the following critical functions:
calculateSymbioticConnectionsinlib/analytics.tsfindSimilarOrgsinlib/organizationUtils.ts
To-Do List
-
Refactor
AddOrganizationWizard:- This is a large, multi-step component that manages a lot of state. It should be broken down into smaller sub-components for each step of the wizard.
- The state management for the wizard should be extracted into a dedicated
useAddOrganizationWizardhook to simplify the main component.
-
Refactor
useAppContext:- The
useAppContexthook was refactored to only contain navigation logic and was renamed touseNavigation.
- The
-
Add more unit tests:
- Identify other critical business logic in the
libdirectory and add unit tests for it. - Consider adding tests for the data transformation and filtering logic in the
useMapDataanduseOrganizationDatahooks.
- Identify other critical business logic in the
-
Create a reusable
FormFieldcomponent:- The forms in the
AddOrganizationWizardhave a lot of repeated code for rendering labels, inputs, and error messages. - Create a generic
FormFieldcomponent to encapsulate this logic and reduce duplication.
- The forms in the
-
Refactor
Chatbotcomponent:- The
Chatbotcomponent has a lot of state and logic. - Extract the state management into a
useChatbothook and break down the component into smaller pieces.
- The
-
Create a
Cardcomponent with variants:- The
Cardcomponent is used in many places with slightly different styles. - Add variants to the
Cardcomponent to handle these different styles and reduce the need for custom CSS.
- The
-
Refactor
OrganizationTable:- The
OrganizationTablecomponent has a lot of logic for filtering and sorting. - Extract this logic into a
useOrganizationTablehook.
- The
-
Create a
PageHeadercomponent:- The
AdminPageandOrganizationPagehave similar page headers. - Create a reusable
PageHeadercomponent to reduce duplication.
- The
-
Add tests for
useOrganizationFilterhook:- The
useOrganizationFilterhook contains critical filtering logic that should be tested.
- The
-
Refactor
LiveActivitycomponent:- The
LiveActivitycomponent has some data transformation logic that could be extracted into a hook.
- The