Skip to content

refactor: adopt Bulletproof React architecture and reorganize frontend into feature-based modules#433

Merged
amit0539 merged 12 commits into
devfrom
arch/restructure
Jul 2, 2026
Merged

refactor: adopt Bulletproof React architecture and reorganize frontend into feature-based modules#433
amit0539 merged 12 commits into
devfrom
arch/restructure

Conversation

@UdayRajSahai2

Copy link
Copy Markdown
Contributor

Summary

This PR restructures the ParakhAI frontend around a Bulletproof React-style architecture to improve maintainability, discoverability, and long-term scalability. The work moves domain logic out of route files and monolithic components into feature modules, shared layers, and focused hooks—without changing product behavior.

Architecture

  • Feature modules under features/:
    • features/ai-maker — evaluation flows, manual evaluation, org context, and AI-maker API hooks
    • features/auditor — auditor assignments and evaluation APIs
    • features/dashboard — shared dashboard UI (EvaluationDetail, filters, audit views, guards)
    • features/home — landing page sections
  • Shared UI layers:
    • components/common — reusable primitives (Pagination, ProgressBar, SessionGuard, RichTextRenderer, etc.)
    • components/layout — MainNav, Sidebar, MainFooter, MobileNav
  • Cross-cutting infrastructure:
    • providers/ — app-level providers (React Query, session, tooltip)
    • lib/ — GraphQL/REST clients, auth helpers
    • utils/, constants/, types/, stores/ — centralized shared utilities and types

Key refactors

  • Split the monolithic EvaluationDetail (~1,600 lines) into composable pieces:
    • EvaluationHeader, EvaluationSummaryCard, EvaluationActions, EvaluationProgressSection, etc.
    • Focused hooks: use-audit-data, use-audit-polling, use-audit-actions, use-evaluation-detail
  • Migrated evaluation creation/manual-test flows into features/ai-maker/components/evaluations/
  • Removed transitional shims and updated all consumers to import directly from features/ and shared modules
  • Updated App Router pages/layouts to use the new module paths

Developer experience

  • Added Prettier, Husky, lint-staged, and commitlint for consistent formatting and commit hygiene
  • Added Vitest + React Testing Library setup with initial utility tests
  • Introduced feature-scoped API hooks (e.g. use-evaluations, use-ai-models, use-organizations) to separate data fetching from presentation

Bug fixes included in this branch

  • Restore single-row layout for EvaluationHeader and EvaluationSummaryCard
  • Derive CivicDataSpace origin from NEXT_PUBLIC_AI_MAKER_URL to prevent incorrect redirect paths

UdayRajSahai2 and others added 12 commits June 30, 2026 13:53
Introduce a self-contained features/ layer for ai-maker, auditor,
dashboard, and home domains with api/, components/, context/, types/,
and utils/ sub-directories.

- features/ai-maker: React Query hooks, OrganizationContext, bulk-evaluation queries
- features/auditor: React Query hooks for assignments and evaluations
- features/dashboard/components: shared dashboard UI components
- features/home/components: landing-page sections
- components/layout/: MainNav, MainFooter, Sidebar, MobileNav
- components/common/: Breadcrumbs, Pagination, Loading, SessionGuard, ProfileMenu
- lib/: slimmed to third-party wrappers (graphql-client, rest-client, auth)
- utils/: pure utility functions extracted from lib/
- stores/: Zustand stores moved from config/store.tsx
- providers/: React providers moved from app/providers.tsx
- hooks/use-app-session.ts: moved from lib/session.ts
- constants/index.ts: route paths, status enums, pagination defaults
- types/index.ts: shared domain types

Co-authored-by: Cursor <cursoragent@cursor.com>
Update every page, layout, and component in app/ and shared components
to import from the new feature-based and shared module paths.

- app/[locale]/ pages: import dynamic sections from features/home/
- app/[locale]/dashboard/: import layout components from components/layout/
- app/[locale]/dashboard/ai-maker/: use features/ai-maker/* imports
- app/[locale]/dashboard/auditor/: use features/auditor/* imports
- components/ProfileMenu, SessionGuard: updated to new lib/auth path
- hooks/use-session-error: import logout from lib/auth
- lib/api-client, lib/session: updated cross-module references
- lib/bulkEvaluation/mapAuditResults: import from features/ai-maker/utils
- config/codegen.ts: scan features/** for GraphQL documents
- .gitignore: add /generated/ for codegen output

Co-authored-by: Cursor <cursoragent@cursor.com>
Set up code quality and Git hook tooling for the project.

- .prettierrc.json: formatting rules with @trivago/prettier-plugin-sort-imports
  and prettier-plugin-tailwindcss
- .lintstagedrc.json: run eslint --fix and prettier --write on staged files
- .husky/pre-commit: run lint-staged before every commit
- .husky/commit-msg: enforce conventional commit format via commitlint
- commitlint.config.ts: conventional-commits rule set
- package.json: add postinstall (husky), test, and test:coverage scripts

Co-authored-by: Cursor <cursoragent@cursor.com>
Introduce testing infrastructure and initial smoke tests.

- vitest.config.ts: Vitest config with jsdom environment and path aliases
- testing/setup.ts: global test setup (jest-dom matchers, fetch mock)
- testing/utils.tsx: custom renderWithProviders() wrapping QueryClient,
  SessionProvider, and NextIntlClientProvider
- utils/index.test.ts: smoke tests for buildUrl, formatDate, formatNumber,
  truncateText, cn, and getInitials utilities
- utils/lifecycle.test.ts: smoke tests for formatLifecycle and lifecycle
  label/color helpers

Co-authored-by: Cursor <cursoragent@cursor.com>
Split the 1,656-line EvaluationDetail.tsx into focused modules with
reusability as the first-class concern, fixing existing duplication
between EvaluationDetail and AuditResultsList in the process.

Shared layers (importable by anything in the codebase):
- features/dashboard/types/audit.ts: single source of truth for Audit,
  TestCase, RiskDistribution, EvaluationDetailProps types
- features/dashboard/utils/evaluation.ts: 15+ pure helpers — status guards,
  formatModuleName, getSeverityTagColors, risk distribution logic
- features/dashboard/api/evaluation-queries.ts: all 4 GraphQL strings +
  re-exports of bulk-eval queries as a single barrel

Reusable display components:
- EvaluationSummaryCard: pass rate, test counts, risk distribution grid
- EvaluationProgressSection: in-progress bar
- EvaluationFailedBanner: failure state with error details

EvaluationDetail-specific folder:
- use-evaluation-detail.ts: all state, fetching, polling, handlers in one hook
- EvaluationHeader.tsx: editable name input + status tags + back button
- EvaluationActions.tsx: submit / generate report / download buttons
- EvaluationDetail.tsx: ~200-line orchestration component
- index.ts: barrel export

Duplication fixed:
- AuditResultsList.tsx: removed local getRiskTagColors and
  formatModuleDisplayName; now imports from shared utils

Backward compatibility:
- features/dashboard/components/EvaluationDetail.tsx: shim
- app/[locale]/dashboard/components/EvaluationDetail.tsx: shim
  (all consuming pages need zero changes)

Co-authored-by: Cursor <cursoragent@cursor.com>
Delete the two backward-compat shims and point consumer pages straight
at the canonical implementation.

- Delete app/[locale]/dashboard/components/EvaluationDetail.tsx (shim)
- Delete features/dashboard/components/EvaluationDetail.tsx (shim)
- Update auditor evaluationId page to import from @/features/dashboard/components/EvaluationDetail
- Update ai-maker evaluationId page to import from @/features/dashboard/components/EvaluationDetail
- Update features/dashboard/components/index.ts barrel to point at EvaluationDetail/index
- Fix UseEvaluationDetailReturn type: add passRate and passRateColor to computed; remove as any cast

Co-authored-by: Cursor <cursoragent@cursor.com>
The component breakdown (EvaluationSummaryCard, EvaluationHeader,
EvaluationActions, EvaluationProgressSection, EvaluationFailedBanner,
use-evaluation-detail sub-hooks) caused layout regressions in the
Evaluation Summary section. Reverting to the original single-file
implementation until the breakdown can be done without UI side-effects.

- Restore features/dashboard/components/EvaluationDetail.tsx (1655 lines)
- Delete features/dashboard/components/EvaluationDetail/ folder and all
  its contents (EvaluationDetail.tsx, EvaluationHeader, EvaluationActions,
  use-evaluation-detail.ts, index.ts)
- Delete standalone EvaluationSummaryCard, EvaluationProgressSection,
  EvaluationFailedBanner components
- Restore AuditResultsList.tsx to its original local helpers
- Restore features/dashboard/components/index.ts barrel

Consumer pages retain the @/features/dashboard/components/EvaluationDetail
import from the previous commit (still resolves correctly).

Co-authored-by: Cursor <cursoragent@cursor.com>
Co-authored-by: Cursor <cursoragent@cursor.com>
…maryCard

Co-authored-by: Cursor <cursoragent@cursor.com>
…oid wrong redirect path

Co-authored-by: Cursor <cursoragent@cursor.com>
@UdayRajSahai2 UdayRajSahai2 requested a review from amit0539 July 2, 2026 07:29
@UdayRajSahai2 UdayRajSahai2 self-assigned this Jul 2, 2026
@amit0539 amit0539 merged commit 573f9cd into dev Jul 2, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants