Skip to content

Commit 6c41297

Browse files
authored
Release/v1.8.0.2
Release/v1.8.0.2
2 parents 203be5d + 9ad5a72 commit 6c41297

File tree

121 files changed

+9611
-1905
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

121 files changed

+9611
-1905
lines changed
Lines changed: 58 additions & 46 deletions
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,31 @@
11
---
2-
globs: frontend/components/**/*.tsx
3-
description: Component layer rules for reusable UI components
2+
globs: frontend/components/**/*.tsx,frontend/app/**/components/**/*.tsx
3+
description: Component layer rules for reusable and feature-specific UI components
44
---
55

66
### Purpose and Scope
77

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`
99
- Responsibilities: Create reusable components, implement business logic, handle interactions, provide consistent UI
1010
- **MANDATORY**: All components must use TypeScript and functional components
1111

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+
1225
### Component Organization
1326

14-
- **`components/ui/`** - Base UI components (buttons, inputs, dialogs, etc.)
1527
- **`components/auth/`** - Authentication-related components
1628
- **`components/providers/`** - Context providers and global state management
17-
- Use index files for clean imports: `export { Button } from './button'`
1829

1930
### Component Structure
2031

@@ -23,6 +34,7 @@ description: Component layer rules for reusable UI components
2334
- Use React hooks for state management
2435
- Implement proper error boundaries where needed
2536
- Follow single responsibility principle
37+
- **Single component file should not exceed ~1000 lines**: Split into subcomponents or extract logic to hooks/utils when a file grows. keep files digestible.
2638

2739
### Props and State Management
2840

@@ -31,11 +43,15 @@ description: Component layer rules for reusable UI components
3143
- Prefer controlled components over uncontrolled
3244
- Use local state for component-specific data
3345
- Use context for shared state across components
46+
- **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
3450
- **CRITICAL**: All logging must use [logger.ts](mdc:frontend/lib/logger.ts) - never use console.log
3551

3652
### Styling and Design
3753

38-
- Use Tailwind CSS classes for styling
54+
- Use Ant Design components + Tailwind for spacing and simple styling
3955
- Follow design system patterns and spacing
4056
- Ensure responsive design with mobile-first approach
4157
- Use CSS variables for theme colors
@@ -55,52 +71,48 @@ description: Component layer rules for reusable UI components
5571
- Provide meaningful error messages to users
5672
- Log errors appropriately for debugging
5773

74+
### Other Considerations
75+
76+
- **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.
78+
5879
### Example
5980
```tsx
60-
// frontend/components/ui/button.tsx
61-
import React from 'react';
62-
import { useTranslation } from 'react-i18next';
63-
import { cn } from '@/lib/utils';
64-
65-
interface ButtonProps {
66-
children: React.ReactNode;
67-
variant?: 'primary' | 'secondary' | 'outline';
68-
size?: 'sm' | 'md' | 'lg';
69-
disabled?: boolean;
70-
loading?: boolean;
71-
onClick?: () => void;
72-
className?: string;
81+
// frontend/components/example-modal.tsx
82+
import React from "react";
83+
import { useTranslation } from "react-i18next";
84+
import { Modal } from "antd";
85+
import { AlertTriangle } from "lucide-react";
86+
87+
interface ExampleModalProps {
88+
open: boolean;
89+
onClose: () => void;
90+
onConfirm: () => void;
7391
}
7492

75-
export function Button({
76-
children,
77-
variant = 'primary',
78-
size = 'md',
79-
disabled = false,
80-
loading = false,
81-
onClick,
82-
className,
83-
}: ButtonProps) {
84-
const { t } = useTranslation('common');
85-
93+
export function ExampleModal({
94+
open,
95+
onClose,
96+
onConfirm,
97+
}: ExampleModalProps) {
98+
const { t } = useTranslation("common");
99+
86100
return (
87-
<button
88-
className={cn(
89-
'inline-flex items-center justify-center rounded-md font-medium transition-colors',
90-
variant === 'primary' && 'bg-primary text-primary-foreground hover:bg-primary/90',
91-
variant === 'secondary' && 'bg-secondary text-secondary-foreground hover:bg-secondary/80',
92-
variant === 'outline' && 'border border-input bg-background hover:bg-accent',
93-
size === 'sm' && 'h-9 px-3 text-sm',
94-
size === 'md' && 'h-10 px-4 py-2',
95-
size === 'lg' && 'h-11 px-8 text-lg',
96-
className
97-
)}
98-
disabled={disabled || loading}
99-
onClick={onClick}
101+
<Modal
102+
open={open}
103+
onCancel={onClose}
104+
centered
105+
okText={t("common.confirm")}
106+
cancelText={t("common.cancel")}
107+
onOk={onConfirm}
100108
>
101-
{loading && <div className="mr-2 h-4 w-4 animate-spin rounded-full border-2 border-current border-t-transparent" />}
102-
{children}
103-
</button>
109+
<div className="flex items-center gap-3">
110+
<AlertTriangle className="h-5 w-5 text-amber-500" />
111+
<span>{t("modal.exampleMessage")}</span>
112+
</div>
113+
</Modal>
114+
115+
104116
);
105117
}
106118
```
Lines changed: 82 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,82 @@
1+
---
2+
globs: frontend/**/*.{ts,tsx}
3+
description: Frontend overview - directory structure, layer responsibilities, and dependency rules
4+
alwaysApply: false
5+
---
6+
7+
# Frontend Overview
8+
9+
## Directory Structure
10+
11+
```
12+
frontend/
13+
├── app/[locale]/ # Routes with i18n (Next.js App Router)
14+
│ ├── layout.tsx, page.tsx # Root layout and home
15+
│ ├── i18n.tsx # i18n config
16+
│ └── {feature}/ # e.g. chat, agents, knowledges, models
17+
│ ├── page.tsx # Page entry (thin wrapper)
18+
│ ├── components/ # Feature-specific components
19+
│ └── {submodule}/ # e.g. versions/
20+
├── components/ # Cross-feature reusable components
21+
│ ├── auth/ # Auth-related UI
22+
│ ├── providers/ # Global context providers
23+
│ └── ... # Base UI: use Ant Design; avoid custom wrappers
24+
├── hooks/ # Custom hooks (organized by domain)
25+
│ ├── auth/ # useSessionManager, useAuthentication, etc.
26+
│ ├── agent/ # useAgentList, useAgentInfo, etc.
27+
│ ├── chat/ # useConversationManagement, etc.
28+
│ └── ...
29+
├── services/ # API calls (api.ts, *Service.ts)
30+
├── lib/ # Utilities (logger, session, utils, etc.)
31+
├── types/ # Shared type definitions
32+
├── const/ # Constants and config
33+
├── stores/ # Global state stores (if any)
34+
├── styles/ # Global styles (theme, reset, AntD overrides)
35+
└── public/ # Static assets
36+
```
37+
38+
## Layer Responsibilities
39+
40+
| Directory | Purpose | Notes |
41+
|-----------|---------|-------|
42+
| `app/[locale]/{feature}/page.tsx` | Route entry, auth guard, config load | Thin wrapper; delegate UI to internal/components |
43+
| `app/.../components/` | Feature-only UI pieces | Ant Design first; Lucide icons primary, `@ant-design/icons` fallback |
44+
| `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` |
74+
| Core feature logic | `app/[locale]/{feature}/internal/` |
75+
| UI used only by one feature | `app/[locale]/{feature}/components/` |
76+
| UI used by multiple features | `components/` (auth/, providers/, etc.); base UI from Ant Design |
77+
| State/effect logic | `hooks/{domain}/` |
78+
| API call | `services/` |
79+
| Pure helper | `lib/` |
80+
| Shared type | `types/` |
81+
| Shared constant value | `const/` |
82+
| Global styles (theme, reset) | `styles/` |

backend/apps/app_factory.py

Lines changed: 108 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,108 @@
1+
"""
2+
FastAPI application factory with common configurations and exception handlers.
3+
"""
4+
import logging
5+
6+
from fastapi import FastAPI, HTTPException
7+
from fastapi.middleware.cors import CORSMiddleware
8+
from fastapi.responses import JSONResponse
9+
10+
from consts.exceptions import AppException
11+
12+
13+
logger = logging.getLogger(__name__)
14+
15+
16+
def create_app(
17+
title: str = "Nexent API",
18+
description: str = "",
19+
version: str = "1.0.0",
20+
root_path: str = "/api",
21+
cors_origins: list = None,
22+
cors_methods: list = None,
23+
enable_monitoring: bool = True,
24+
) -> FastAPI:
25+
"""
26+
Create a FastAPI application with common configurations.
27+
28+
Args:
29+
title: API title
30+
description: API description
31+
version: API version
32+
root_path: Root path for the API
33+
cors_origins: List of allowed CORS origins (default: ["*"])
34+
cors_methods: List of allowed CORS methods (default: ["*"])
35+
enable_monitoring: Whether to enable monitoring
36+
37+
Returns:
38+
Configured FastAPI application
39+
"""
40+
app = FastAPI(
41+
title=title,
42+
description=description,
43+
version=version,
44+
root_path=root_path
45+
)
46+
47+
# Add CORS middleware
48+
app.add_middleware(
49+
CORSMiddleware,
50+
allow_origins=cors_origins or ["*"],
51+
allow_credentials=True,
52+
allow_methods=cors_methods or ["*"],
53+
allow_headers=["*"],
54+
)
55+
56+
# Register exception handlers
57+
register_exception_handlers(app)
58+
59+
# Initialize monitoring if enabled
60+
if enable_monitoring:
61+
try:
62+
from utils.monitoring import monitoring_manager
63+
monitoring_manager.setup_fastapi_app(app)
64+
except ImportError:
65+
logger.warning("Monitoring utilities not available")
66+
67+
return app
68+
69+
70+
def register_exception_handlers(app: FastAPI) -> None:
71+
"""
72+
Register common exception handlers for the FastAPI application.
73+
74+
Args:
75+
app: FastAPI application instance
76+
"""
77+
78+
@app.exception_handler(HTTPException)
79+
async def http_exception_handler(request, exc):
80+
logger.error(f"HTTPException: {exc.detail}")
81+
return JSONResponse(
82+
status_code=exc.status_code,
83+
content={"message": exc.detail},
84+
)
85+
86+
@app.exception_handler(AppException)
87+
async def app_exception_handler(request, exc):
88+
logger.error(f"AppException: {exc.error_code.value} - {exc.message}")
89+
return JSONResponse(
90+
status_code=exc.http_status,
91+
content={
92+
"code": exc.error_code.value,
93+
"message": exc.message,
94+
"details": exc.details if exc.details else None
95+
},
96+
)
97+
98+
@app.exception_handler(Exception)
99+
async def generic_exception_handler(request, exc):
100+
# Don't catch AppException - it has its own handler
101+
if isinstance(exc, AppException):
102+
return await app_exception_handler(request, exc)
103+
104+
logger.error(f"Generic Exception: {exc}")
105+
return JSONResponse(
106+
status_code=500,
107+
content={"message": "Internal server error, please try again later."},
108+
)

0 commit comments

Comments
 (0)