Simplify the current somewhat over-engineered (FSD/DDD-like) directory structure (src/domains, src/features, src/core, src/shared) into a flatter, more standard Next.js application structure. This will reduce cognitive load, make it easier to locate files, and improve maintainability for a personal blog project.
- Reorganize directories inside
src/to follow a standard Next.js pattern (app,components,lib,hooks,types). - Migrate existing UI components from
src/features/*/ui,src/shared/ui,src/shared/layouttosrc/components/*. - Migrate business logic, API clients, and utilities from
src/features/*/services,src/shared/analytics,src/shared/integrationstosrc/lib/*. - Migrate types and models from
src/domains/*/model,src/features/*/modelto a top-levelsrc/typesor colocated with features inlib. - Migrate configurations and providers from
src/core,src/shared/providerstosrc/components/providersorsrc/lib/config. - Update all internal import paths to reflect the new structure.
- Update
ARCHITECTURE.mdto document the new, simplified structure. - Run tests and linters to ensure nothing is broken.
- The Next.js
approuter structure (src/app/**) itself remains mostly unchanged, except for import updates. - The
posts/directory and its content pipeline remain unchanged. - The styling approach (Tailwind + CSS variables in
src/styles) remains unchanged. - No new features or bug fixes should be introduced during this refactoring. It is a pure structural change.
- Phase 1: Preparation:
- Create the new base directories (
src/components,src/lib,src/types,src/hooks).
- Create the new base directories (
- Phase 2: Types & Models Migration:
- Move files from
src/domains/*/model/*andsrc/features/*/model/*tosrc/types/*orsrc/lib/*. - Fix import paths for these types.
- Move files from
- Phase 3: Lib & Utilities Migration:
- Move files from
src/features/*/services/*tosrc/lib/content/(or similar). - Move files from
src/shared/integrations/*,src/shared/analytics/*,src/shared/seo/*tosrc/lib/*. - Move utility functions to
src/lib/utils.ts.
- Move files from
- Phase 4: Component Migration:
- Move common UI components from
src/shared/ui/*tosrc/components/ui/. - Move layout components from
src/shared/layout/*tosrc/components/layout/. - Move feature-specific UI from
src/features/*/ui/*tosrc/components/[feature]/. - Move
src/core/providers,src/shared/providerstosrc/components/providers/.
- Move common UI components from
- Phase 5: Cleanup & Update Documentation:
- Delete empty old directories (
src/domains,src/features,src/shared,src/core). - Update
ARCHITECTURE.mdto reflect the new structure.
- Delete empty old directories (
- Phase 6: Verification:
- Run all tests (
npm run test:ci). - Verify local build (
npm run build).
- Run all tests (
- All TypeScript compiler checks must pass (
npm run lint). - All unit and E2E tests must pass (
npm run test:ci). - The development server must start without errors (
npm run dev). - A production build must succeed (
npm run build). - The application (both UI and functionality like view counts) must work identically to before.
- Since the project is managed by Git, if any issues arise or the refactoring becomes too complex, the rollback strategy is to hard reset to the commit prior to starting this execution plan (
git reset --hard HEAD).