Implementing AI in Real Projects: Establish Entry Points and Rules Before Writing Code

    When discussing how to integrate AI into actual scenarios, many articles directly showcase specific features like generating pages, completing APIs, modifying styles, or writing scripts. However, they often sidestep a more fundamental question: when AI enters a real, long-term evolving codebase, what exactly should the first step be? This article concludes that the first step is not to let AI write code, but to establish repository entry points, domain rules, and execution boundaries. Otherwise, the more "capable" the AI is, the more likely the project will spiral out of control as complexity rises. It covers a three-tier entry model, execution boundaries, prompt templates, implementation workflows, and governance metrics to transform AI from an advanced auto-complete tool into a controllable engineering collaborator.

    Introduction

    When discussing how to integrate AI into actual scenarios, many articles directly showcase specific features: generating pages, completing APIs, modifying styles, or writing scripts. While these demonstrations hold value, they often sidestep a more fundamental question: when AI enters a real, long-term evolving codebase, what exactly should the first step be? My conclusion is that the first step is not to let AI write code, but to establish repository entry points, domain rules, and execution boundaries first. Otherwise, the more “capable” the AI is, the more likely the project will spiral out of control as complexity rises.

    1. The Core Issue: AI is Not Just an Advanced Auto-Complete Tool

    Treating AI as an “advanced auto-complete tool” typically involves immediately issuing commands like “build a list page,” “complete this API,” or “change the style to this.” In the short term, output is fast. However, as soon as the project gets slightly complex, four types of problems emerge quickly.

    First, inconsistent modifications. The AI might follow Plan A this time and Plan B next time, resulting in multiple interaction and code styles within the same module. Second, boundary confusion. The responsibilities of the frontend, admin dashboard, and backend services get mixed up; logic that should belong to business modules is stuffed into common modules, and frontend pages are written in the admin dashboard style. Third, fluctuating API fields. Callers, callees, and data transfer contracts lack unified constraints, causing field names and types to change repeatedly. Fourth, context loss. When resuming work two weeks later, the AI acts as if it has entered a new project, requiring you to re-explain the directory, standards, and restricted areas.

    The root cause of these issues is not that the model isn’t strong enough, but rather that the AI lacks stable repository entry points and long-term rules. The complexity of a real project comes from module maps, historical conventions, cross-platform consistency, and API contracts. If this information only exists in human minds, every AI session relies on guesswork, leading to unstable output.

    2. Why Entry Points Take Priority Over Code

    A repository entry point is not just a sentence saying “This is Project X.” It is a set of readable, maintainable, and routable files and directories. It must answer at least three questions: What modules exist in the repository? What boundaries cannot be touched? What process should this type of task follow?

    The value of prioritizing entry points is that it transforms “temporary prompts” into “long-term context.” By reading the entry point before starting a task, the AI knows which directory the business logic should fall into, where common capabilities should be placed, and what standards the frontend and admin dashboard should follow respectively. Rules consolidate team consensus, reducing the need for repeated explanations. Execution boundaries further constrain what the AI can and cannot do, and to what extent, preventing it from expanding its impact under the guise of “completing the task.”

    3. Three-Tier Entry Model: Instructions, Rules, and Skills

    A robust approach is to split the entry points into three tiers: root-level collaboration instructions, a domain rules directory, and a skills/scripts directory. Working together, these let the AI understand the module map, boundaries, and processes.

    1. <repo-root>/
    2. collaboration-instructions.md
    3. domain-rules/
    4. general-rules.md
    5. backend-rules.md
    6. frontend-rules.md
    7. admin-dashboard-rules.md
    8. skill-scripts/
    9. change-check/
    10. api-contract-check/
    11. pre-release-check/
    12. <api-contracts>/
    13. <common>/
    14. <gateway>/
    15. <auth>/
    16. <business-modules>/
    17. <web-front>/
    18. <web-admin>/

    The root-level collaboration instructions only hold stable information: project positioning, module map, tech stack, common commands, untouchable boundaries, and task routing. Domain rules are split by task type—for example, backend tasks read backend rules, frontend tasks read frontend rules, and admin dashboard tasks read admin dashboard rules. The skills/scripts directory encapsulates repeatable processes, such as change checks, API contract checks, and pre-release checks. Do not cram all rules into a single giant file; otherwise, it becomes difficult for the AI to load rules based on the task, and maintenance costs will skyrocket.

    4. Execution Boundaries: Telling AI “How Far to Go”

    Execution boundaries should cover at least five categories:

    Boundary Type Rule Example Acceptance Criteria
    Directory Boundary Business logic goes into business modules; common modules only hold shared capabilities Check change file paths and dependency directions
    API Contract Boundary Modify the contract first for field changes, then the caller and implementation Contract review and full-link verification
    Dependency Boundary Do not introduce heavy dependencies for small features; explain new dependencies Dependency list and review records
    Change Granularity One task, one goal; plan first, then code Change plan and impact list
    Verification Boundary Each task must run checks, unit tests, builds, or static scans Verification results delivered with the task

    Boundaries should not be mere slogans; they must be written as executable items. For example: “The frontend must not reuse the interaction component standards of the admin dashboard,” “Cross-service field adjustments must complete contract changes first,” or “Adding new capabilities to common modules must specify the reuse scope.” Each rule should come with acceptance criteria; otherwise, the AI cannot determine if it has finished.

    5. Prompt Template: From “Build a Feature” to “Execute by Repo Rules”

    Stop saying “build a feature” and start giving the AI a project-level prompt:

    1. You are working in a real code repository. Before starting, please execute:
    2. 1. Read the root-level collaboration instructions, list the module map, the impact of this task, and untouchable boundaries;
    3. 2. Read the corresponding domain rules based on task type: backend, frontend, admin dashboard, or general rules;
    4. 3. Read the check processes in the skills/scripts directory related to the task;
    5. 4. Output a change plan first: affected files, API contract changes, risk points, and verification methods;
    6. 5. Modify code only after the plan is confirmed; crossing directory boundaries and contract boundaries is prohibited;
    7. 6. After completion, output a change summary, verification results, legacy risks, and rules that need to be fed back.
    8. Task goal: ...
    9. Acceptance criteria: ...

    This template forces a workflow of “read before write, plan before modify, verify before deliver.” It also makes the task process auditable: if the AI outputs the module map and impact area first, humans can judge whether it understood correctly; if the AI provides a plan first, humans can correct deviations before code is written; when the AI delivers verification results, the team can feed rework points back into the rules.

    6. Implementation Workflow: From Repo Audit to Task Closure

    Step 1: Repo Audit. Have the AI generate a module map, dependency relationships, an API contract list, build commands, test entry points, and a risk directory.
    Step 2: Establish Entry Points. Write the root-level collaboration instructions, domain rules, and skill scripts. Specify the owner and update conditions for each file.
    Step 3: Small Task Pilot. Choose low-risk tasks, such as copy adjustments, style fixes, simple queries, or logging improvements. Do not hand over the core transaction chain to the AI right away.
    Step 4: Review and Consolidate. Write the rework points from this iteration back into the rules, and script the repetitive checks.
    Step 5: Expand Scope. Gradually open access by domain and set up review gates. When running in the cloud, you can combine general categories provided by Baidu AI Cloud (such as log services, monitoring and alerting, object storage, and container platforms) to record changes and rollbacks, but these infrastructure components cannot replace the repository entry points and rules layer.

    7. Typical Scenarios

    Admin Dashboard List Page: Read the admin dashboard rules first; use unified standards for tables, pagination, permissions, and empty states; define the API contract before implementing the page; verify permissions and exception states during acceptance.
    Frontend Display Page: Read the frontend rules; focus on responsive design, accessibility, and content display standards; do not directly reuse backend interaction styles.
    Backend Business API: Read the backend rules; business logic goes into business modules, and common modules only hold shared capabilities; contract changes must analyze the impact area.
    Cross-Service Field Adjustment: Modify the contract first, then the caller, and finally the implementation, followed by full-link verification.
    Legacy Project Takeover: Have the AI generate a module map and risk list first; do not modify code directly.

    8. Governance and Metrics

    You can measure effectiveness using metrics like rework rate, cross-boundary modification count, API contract violation count, AI task first-time pass rate, verification coverage, rule hit rate, and review issue distribution. Mechanically, establish rule reviews, task templates, check scripts, change logs, and regular feedback loops. Rules must be executable and verifiable, not written as slogans. Only then will the AI evolve from an “advanced auto-complete tool” into a controllable engineering collaborator.

    The key to implementing AI in real scenarios is not making it write code faster, but making it work within the correct context and boundaries. Entry points first, then rules, then skills, and finally code—this is a much more stable sequence.