Skip to content

Generate Source Code Default Rules

Introduction

When creating a project and generating source code, you can customize AI rule files and choose to customize the content of generated source code files. If none are selected, the default rules will be used to generate the relevant source code.

The default rules are as follows:

During development, please strictly follow these principles:

  • SOLID, DRY, KISS, YAGNI: Ensure code maintainability, simplicity, and efficiency.
  • OWASP security best practices: Including input validation, SQL injection protection, etc.

I. Technology Stack Specifications

Technology stack requirements

  • Framework: Spring Boot 3.x + Java 17
  • Dependencies: Spring Web, Spring Data JPA, Lombok, Swagger (SpringDoc), Spring Security (if permission control is required)

II. Application Logic Design Guidelines

  1. Layered Architecture Principles

    LayerResponsibilitiesConstraints
    ControllerHandle HTTP requests/responses, define API interfaces1. Must not directly operate the database; 2. Must call through Service layer
    ServiceImplement business logic, manage transactions, validate data1. Must access database through Repository; 2. Return DTO instead of entity classes (unless necessary)
    RepositoryDefine database query logic, persist data1. Must inherit JpaRepository; 2. Use @EntityGraph to avoid N+1 query problems
    EntityDatabase table structure mapping objects1. Only for database interaction; 2. Must not be returned directly to frontend (requires DTO conversion), package name unified as entity
  2. Implementation classes of interfaces should be placed in the impl package under the interface package path

III. Security and Performance Guidelines

  1. Input Validation

    • Use @Valid annotation with JSR-303 validation annotations (such as @NotBlank, @Size). Note: Validation annotations for Spring Boot 3.x and above versions are located in the jakarta package, not javax.
    • Prohibit direct concatenation of SQL to prevent injection attacks.
  2. Transaction Management

    • @Transactional annotation only used for Service methods.
    • Avoid frequent transaction commits within loops.
  3. Performance Optimization

    • Use @EntityGraph for pre-loading associations.
    • Avoid executing database queries within loops, prioritize bulk operations.

IV. Code Style Guidelines

  1. Naming Conventions

    • Class names: UpperCamelCase (e.g., UserServiceImpl)
    • Method/variable names: lowerCamelCase (e.g., saveUser)
    • Constants: UPPER_SNAKE_CASE (e.g., MAX_LOGIN_ATTEMPTS)
  2. Commenting Standards

    • Classes, methods, and properties need Javadoc-style comments.
    • Planned tasks need to be marked as // TODO.
    • Logic with potential defects need to be marked as // FIXME.
  3. Code Formatting

    • Use IntelliJ IDEA's default Spring Boot style.
    • Prohibit manual adjustment of code indentation, rely on IDE auto-formatting.
  4. Class Name Standards Comply with Alibaba naming conventions, such as entity classes ending with specific characters based on functionality (DTO, DO, BO, VO, Query).

    • DTO (Data Transfer Object): Used for transferring data between different systems or services.
    • DO (Data Object): Represents entity data in the database.
    • BO (Business Object): Encapsulates business logic.
    • VO (View Object): Displays data to users.
    • Query: Represents query conditions or parameters.

V. Extensibility Design Guidelines

  1. Interface-First Approach

    • Separate service layer interfaces (such as UserService) from implementations (such as UserServiceImpl).
  2. Extension Point Reservations

    • Key business logic needs to support Strategy or Template pattern extensions.
  3. Logging Standards

    • Use SLF4J for logging (prohibited to use System.out.println).
    • Core operations need to record INFO level logs, exceptions record ERROR level.

邮箱:chendw@feisuanyz.com 邮编:518000 地址:深圳市前海深港合作区前湾一路1号A栋201室