Skip to content

Delete Code

Method

REST method is adopted.

HTTP Method

DELETE: Delete code (soft delete)

Naming Convention

To unify the naming of query parameters and nodes and improve readability, snake_case is used for URIs and JSON nodes in requests.

Request and Response

Headers

Meta information is set in HTTP headers, not in the response body.

Request Headers

  • Authorization
  • Content-Type
  • Accept
  • Accept-language

Response Headers

  • Content-Type

Delete Code

URI

DELETE /v1/organizations/{organization_id}/projects/{project_id}/code/{code_id}

Path Parameters

Name Type Required Description
organization_id number Required Backend PostgreSQL organization ID
project_id number Required Backend PostgreSQL project ID
code_id string Required Code UUID

Response

The response is JSON.

{
  "id": "0192a3b4-c5d6-4e8f-9a0b-1c2d3e4f5a6b",
  "projectId": 42,
  "name": "Button",
  "s3Key": "code/0192a3b4-c5d6-4e8f-9a0b-1c2d3e4f5a6b.png",
  "sourceCode": "const Button = () => { ... }",
  "cssCode": ".button { ... }",
  "status": 1,
  "createdAt": 1234567890000,
  "updatedAt": 1234567899999,
  "deletedAt": 1234567899999,
  "createdBy": "user-id",
  "updatedBy": "updater-id",
  "deletedBy": "deleter-id"
}

Response Fields

Name Type Description
id string Code UUID
projectId number Backend PostgreSQL project ID
name string Code name
s3Key string S3 key for preview image
sourceCode string Source code
cssCode string | null CSS code
status number Processing status (0 processing, 1 completed, 2 failed)
createdAt number Creation timestamp (epoch milliseconds)
updatedAt number Update timestamp (epoch milliseconds)
deletedAt number Deletion timestamp (epoch milliseconds)
deletedBy string Deleter user ID

Authentication

Authentication is performed using JSON Web Tokens (JWT) issued by Amazon Cognito.

Error Handling

The status codes for error handling are as follows.

Description Status Code Status Name
Missing credentials 401 Unauthorized
Insufficient permissions 403 Forbidden
Code, project, or organization not found 404 Not Found
Codebase index is processing (CODEBASE_INDEX_PROCESSING) 409 Conflict
Internal server error 500 Internal Server Error

Processing Flow

  1. Extract the scoped code ID and verify project write access.
  2. Begin a PostgreSQL transaction and lock the project's dedicated codebase_index row. Reject the write with 409 CODEBASE_INDEX_PROCESSING when its status is processing.
  3. Verify the active code belongs to the project and soft-delete it by setting deleted_at, deleted_by, updated_at, and updated_by.
  4. In the same transaction, set codebase_index.status = 'pending' and clear token, indexed_at, and error, then commit.
  5. Return the deleted code information. Delete does not publish a fourth Code Import task.

Detailed Flowchart

flowchart TD
    Start([DELETE Request]) --> Route[Route Handler]
    Route --> Auth[Auth & Parameter Extraction]
    Auth --> Service[Service Layer]

    Service --> AccessCheck[Access Check]
    AccessCheck --> HasAccess{Write permission?}
    HasAccess -->|No| Err404[404 Not Found]
    HasAccess -->|Yes| Transaction

    Transaction[Begin Transaction] --> LockIndex[Lock dedicated codebase_index row]
    LockIndex --> IsProcessing{status=processing?}
    IsProcessing -->|Yes| Err409[409 CODEBASE_INDEX_PROCESSING]
    IsProcessing -->|No| CheckExist[Check existing<br/>WHERE deletedAt IS NULL]
    CheckExist --> Exists{Exists?}
    Exists -->|No| Rollback[Rollback]
    Exists -->|Yes| SoftDelete

    Rollback --> Err404

    SoftDelete[Soft-delete code row<br/>and update audit fields] --> Invalidate[Set codebase_index pending<br/>clear token/indexed_at/error]
    Invalidate --> Refetch[Fetch updated record]
    Refetch --> Commit[Commit]
    Commit --> Success[200 OK]

Notes

This endpoint performs a PostgreSQL soft delete. It creates no revision or history record. The invalidated project cannot run Design Import or Des2Code until a later explicit codebase-index build completes.

That build derives its authoritative manifest from active PostgreSQL rows. The manifest excludes the deleted code and its associated visual assets, and the build removes their current project-scoped code and code_visual_evidence projections before activating the replacement current bundle. No standalone code-delete SQS task exists.