Files
ai_agent/.claude/rules/code-style.md
T
furyhawk 8351e73d39 feat: add Zustand stores for conversation, file preview, sidebar, theme, and knowledge base selection
- Implemented `conversation-store` for managing conversations and messages.
- Created `file-preview-store` to handle file preview state.
- Added `sidebar-store` for sidebar visibility management.
- Developed `theme-store` for theme persistence and management.
- Introduced `kb-selection-store` for managing active knowledge base selections with persistence.

chore: define API and chat types

- Added types for API responses, authentication, chat messages, conversations, and projects.
- Defined interfaces for various entities including users, sessions, and message ratings.

build: configure TypeScript and testing setup

- Set up `tsconfig.json` for TypeScript configuration.
- Created `vitest.config.ts` for testing configuration with Vitest.
- Added `vitest.setup.ts` for global test setup including mocks for Next.js router and media queries.
- Configured Vercel deployment settings in `vercel.json`.
2026-06-11 16:54:43 +08:00

2.1 KiB

description, globs
description globs
Code style, formatting, naming, imports, and type hints
backend/**/*.py
*.py

Code Style

Formatting

  • Use ruff for linting and formatting: ruff check . --fix && ruff format .
  • Line length: 120 characters

Type Hints

  • Type hints on ALL function signatures — parameters and return types
  • Use modern syntax: str | None not Optional[str], list[User] not List[User]
  • Use Annotated[Type, Depends(...)] for DI (defined as aliases in deps.py)
  • Use dict[str, Any] for generic dicts
  • Use Literal["value1", "value2"] for string enums in schemas
  • Use TYPE_CHECKING block for circular import resolution:
    from typing import TYPE_CHECKING
    if TYPE_CHECKING:
        from app.db.models.session import Session
    

Naming

Element Convention Example
Files snake_case user_repo.py, conversation_service.py
Classes PascalCase UserService, ConversationRead
Functions/variables snake_case get_by_id, user_service
Constants UPPER_CASE DEFAULT_SYSTEM_PROMPT
Private _leading_underscore _create_agent
DB tables snake_case plural users, conversations
API URLs kebab-case /api/v1/conversations

Imports — strictly ordered, separated by blank lines

# 1. Standard library
import logging
from collections.abc import AsyncGenerator
from datetime import UTC, datetime
from typing import Annotated, Any
from uuid import UUID

# 2. Third-party
from fastapi import APIRouter, Depends, Query, status
from pydantic import BaseModel, ConfigDict, Field
from sqlalchemy import select
from sqlalchemy.ext.asyncio import AsyncSession

# 3. Local application
from app.api.deps import CurrentUser, UserSvc
from app.core.exceptions import NotFoundError
from app.schemas.user import UserCreate, UserRead

Other Conventions

  • datetime.now(UTC) not datetime.utcnow()
  • secrets.compare_digest() for constant-time comparisons
  • __repr__ on all DB models
  • Async for PostgreSQL/MongoDB I/O, sync for SQLite
  • Keyword-only args in repo functions after db parameter