.cursorrules 5.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168
  1. # DataOps Platform - Cursor Editor Rules
  2. ## Project Overview
  3. This is a Flask-based DataOps platform for data management, processing, and analytics.
  4. The platform integrates with Neo4j graph database for relationship management and supports n8n workflow automation.
  5. ---
  6. # Python 编码规范
  7. ## 代码风格
  8. - 使用 Ruff 进行代码检查和格式化(替代 Black + Flake8 + isort)
  9. - 使用 Pyright 进行类型检查(替代 MyPy)
  10. - 行长度限制:88 字符
  11. - 使用双引号作为字符串默认引号
  12. - 使用 4 空格缩进,不使用制表符
  13. ## 类型注解
  14. - 所有函数必须包含类型注解(参数和返回值)
  15. - 使用 Python 3.8+ 兼容的类型语法
  16. - 对于 Python 3.9+ 的特性(如 `list[str]`),需要 `from __future__ import annotations`
  17. - 复杂类型使用 `typing` 模块
  18. ## 导入规范
  19. - 按照标准库、第三方库、本地导入的顺序组织
  20. - 使用绝对导入,避免相对导入
  21. - 每个导入单独一行
  22. - 常用工具函数(如 `create_or_get_talent_node`)应在文件顶部导入
  23. ## 命名规范
  24. - 类名使用 PascalCase
  25. - 函数和变量使用 snake_case
  26. - 常量使用 UPPER_SNAKE_CASE
  27. - 私有成员使用单下划线前缀
  28. ## 文档字符串
  29. - 所有公共函数、类和模块必须包含 docstring
  30. - 使用 Google 风格的 docstring
  31. - 包含参数说明、返回值说明和异常说明(如适用)
  32. ## 错误处理
  33. - 使用具体的异常类型,避免裸露的 `except:`
  34. - 优先使用上下文管理器(`with` 语句)
  35. - 使用 Loguru 记录异常信息用于调试
  36. ## 日志规范
  37. - 使用 Loguru 进行日志记录
  38. - 日志级别:DEBUG(调试)、INFO(信息)、WARNING(警告)、ERROR(错误)
  39. - 避免在生产环境使用 print() 语句
  40. ## 代码质量
  41. - 避免使用 `type: ignore`,除非绝对必要并添加说明
  42. - 函数保持简短(建议不超过 50 行)
  43. - 避免深层嵌套(最多 3 层)
  44. - 使用列表推导式和生成器表达式(但保持可读性)
  45. ## 示例
  46. ```python
  47. from __future__ import annotations
  48. from typing import Optional
  49. from loguru import logger
  50. def process_data(
  51. items: list[str],
  52. max_length: int = 100,
  53. strict: bool = False,
  54. ) -> dict[str, int]:
  55. """
  56. Process a list of items and return statistics.
  57. Args:
  58. items: List of strings to process.
  59. max_length: Maximum allowed length for items.
  60. strict: Whether to raise error on invalid items.
  61. Returns:
  62. Dictionary containing processing statistics.
  63. Raises:
  64. ValueError: If strict mode and invalid item found.
  65. """
  66. result: dict[str, int] = {}
  67. try:
  68. # Implementation here
  69. logger.info(f"Processing {len(items)} items")
  70. except ValueError as e:
  71. logger.error(f"Processing failed: {e}")
  72. raise
  73. return result
  74. ```
  75. ---
  76. ## Architecture
  77. - Flask application with modular structure
  78. - SQLAlchemy for PostgreSQL database operations
  79. - Neo4j for graph database and relationship management
  80. - RESTful API design with Blueprint-based routing
  81. - Configuration-based environment management
  82. - n8n workflow integration via MCP servers
  83. ## File Organization
  84. - `app/` - Main application code
  85. - `app/api/` - API endpoints and routes (Blueprint-based)
  86. - `app/core/` - Core business logic and domain services
  87. - `app/models/` - SQLAlchemy database models
  88. - `app/services/` - Shared services (Neo4j driver, utilities)
  89. - `app/config/` - Configuration files
  90. - `app/scripts/` - Database initialization scripts
  91. - `database/` - SQL scripts and migrations
  92. - `docs/` - Documentation
  93. - `tests/` - Test files
  94. - `scripts/` - Automation scripts
  95. - `mcp-servers/` - MCP server implementations (e.g., task-manager)
  96. - `logs/` - Application logs
  97. ## Dependencies
  98. - Python >= 3.8
  99. - Flask >= 2.3.0
  100. - Flask-SQLAlchemy >= 3.1.0
  101. - SQLAlchemy >= 2.0.0
  102. - Neo4j Python Driver (for graph database)
  103. - PostgreSQL (via psycopg2-binary)
  104. - Loguru (for logging)
  105. - Pandas & NumPy (for data processing)
  106. ## Development Tools
  107. - Ruff (linting & formatting, replaces Black + Flake8 + isort)
  108. - Pyright (type checking, replaces MyPy)
  109. - Pytest (testing)
  110. ## Development Guidelines
  111. - Always use virtual environment
  112. - Test API endpoints before committing
  113. - Update documentation for API changes
  114. - Use Loguru for logging, avoid print() statements
  115. - Handle errors gracefully with proper logging
  116. ## API Conventions
  117. - Use snake_case for Python functions and variables
  118. - Use kebab-case for API endpoints
  119. - Return consistent JSON responses with `code`, `message`, `data` structure
  120. - Include proper HTTP status codes
  121. - Validate input data
  122. ## Database
  123. - PostgreSQL for relational data
  124. - Neo4j for graph data and relationships
  125. - Use Flask-Migrate/Alembic for schema migrations
  126. - Follow naming conventions for tables and columns
  127. - Implement proper indexing
  128. - Use transactions for data consistency
  129. ## Neo4j Graph Database
  130. - Use `Neo4jDriverSingleton` for connection management
  131. - Follow Cypher query best practices
  132. - Use parameterized queries to prevent injection
  133. - Close sessions properly after use
  134. ## Security
  135. - Validate all user inputs
  136. - Use environment variables for sensitive data (see `env.example`)
  137. - Implement proper authentication
  138. - Use parameterized queries for both SQL and Cypher