You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
description: Component layer rules for reusable and feature-specific UI components
4
4
---
5
5
6
6
### Purpose and Scope
7
7
8
-
- Component layer contains reusable UI components for `frontend/components/**/*.tsx`
8
+
- Component layer contains reusable UI components for `frontend/components/**/*.tsx` and feature-specific components under `frontend/app/**/components/**/*.tsx`
9
9
- Responsibilities: Create reusable components, implement business logic, handle interactions, provide consistent UI
10
10
- **MANDATORY**: All components must use TypeScript and functional components
11
11
12
+
### UI Library and Icons
13
+
14
+
- **Ant Design first**: Use Ant Design for forms, data display, modals, buttons, layouts. See [ui_standards_rules.mdc](mdc:frontend/ui_standards_rules.mdc).
15
+
- **Icons**: Lucide icons primary (`lucide-react`), `@ant-design/icons` as fallback when Lucide lacks the icon.
16
+
17
+
```tsx
18
+
// Prefer Lucide
19
+
import { Search, RefreshCw, Edit } from "lucide-react";
20
+
21
+
// Fallback when Lucide has no equivalent (e.g. ExclamationCircleFilled for modal)
22
+
import { ExclamationCircleFilled, InfoCircleFilled } from "@ant-design/icons";
23
+
```
24
+
12
25
### Component Organization
13
26
14
-
- **`components/ui/`** - Base UI components (buttons, inputs, dialogs, etc.)
- **Single component file should not exceed ~1000 lines**: Split into subcomponents or extract logic to hooks/utils when a file grows. keep files digestible.
- **Avoid Prop Drilling**: When a component receives more than ~7–10 props, or props are passed through multiple layers only to reach a deep child, prefer:
47
+
- **Context** for cross-cutting state (auth, theme, feature flags)
48
+
- **Composition** (children, render props) instead of passing many callbacks
49
+
- **Custom hooks** to encapsulate shared logic; let children use the hook instead of receiving props from parent
34
50
- **CRITICAL**: All logging must use [logger.ts](mdc:frontend/lib/logger.ts) - never use console.log
35
51
36
52
### Styling and Design
37
53
38
-
- Use Tailwind CSS classes for styling
54
+
- Use Ant Design components + Tailwind for spacing and simple styling
39
55
- Follow design system patterns and spacing
40
56
- Ensure responsive design with mobile-first approach
- **Colocate subcomponents**: When a component file grows, extract logically distinct subcomponents into separate files in the same folder. Avoid putting many unrelated components in one file.
77
+
- **Lean interfaces**: Group related props into objects when they form a cohesive concern (e.g. `user: { email, avatarUrl, role }`) instead of passing many flat props.
| `components/` | Shared UI across features | Ant Design first; Lucide icons primary, `@ant-design/icons` fallback |
45
+
| `hooks/` | State and side-effects | Shared API data: use TanStack React Query (`useQuery`); client-side filter/sort: `useMemo` on query data; mutations: `useMutation` + `queryClient.invalidateQueries` |
46
+
| `services/` | API calls | — |
47
+
| `lib/` | Pure utilities | — |
48
+
| `types/` | Type definitions only | `interface`, `type` only; do not store constants |
49
+
| `const/` | Runtime constants | Literals, enums, config objects, status codes; do not store `interface`/`type` |
50
+
| `styles/` | Global styles | Theme vars, reset, AntD overrides only; component-specific CSS: colocate in component (e.g. `*.module.css`) |
51
+
52
+
## General Principles
53
+
54
+
- **Avoid over-engineering**: Before abstracting code (extracting hooks, components, utils), confirm there is a concrete need (reuse, testability, or complexity). Prefer simple, inline solutions until the need is clear.
55
+
56
+
## Dependency Rules
57
+
58
+
- **No cross-feature imports**: Feature-level code (`components/` under a feature) must not import from other features. Use shared `components/` for cross-feature reuse.
59
+
- **Infrastructure does not depend on UI**: `services/`, `lib/`, `types/` must not import from `app/` or `components/`.
60
+
- **Minimize CSS**: Prefer Tailwind + Ant Design. Use CSS only when necessary; keep component-specific styles colocated (e.g. `*.module.css` next to the component).
61
+
62
+
## Path Aliases
63
+
64
+
- `@/*` → `frontend/*`
65
+
- `@/app/*` → `frontend/app/[locale]/*` (import without `[locale]` segment)
66
+
67
+
Example: `import { ChatInterface } from "@/app/chat/internal/chatInterface"`
68
+
69
+
## Where to Put New Code
70
+
71
+
| If you are adding... | Put it in |
72
+
|----------------------|-----------|
73
+
| A new route | `app/[locale]/{feature}/page.tsx` |
0 commit comments