{"record":{"id":"4cc7f141a0125515","repo":"mermaid-js/mermaid","slug":"the-service-id-cannot-be-placed-within-itself","errorCode":null,"errorMessage":"The service [${id}] cannot be placed within itself","messagePattern":"The service \\[(.+?)\\] cannot be placed within itself","errorType":"validation","errorClass":null,"httpStatus":null,"severity":"error","filePath":"packages/mermaid/src/diagrams/architecture/architectureDb.ts","lineNumber":89,"sourceCode":"    this.diagramId = '';\n    commonClear();\n  }\n\n  public addService({\n    id,\n    icon,\n    in: parent,\n    title,\n    iconText,\n  }: Omit<ArchitectureService, 'edges'>): void {\n    if (this.registeredIds.has(id)) {\n      throw new Error(\n        `The service id [${id}] is already in use by another ${this.registeredIds.get(id)}`\n      );\n    }\n    if (parent !== undefined) {\n      if (id === parent) {\n        throw new Error(`The service [${id}] cannot be placed within itself`);\n      }\n      if (!this.registeredIds.has(parent)) {\n        throw new Error(\n          `The service [${id}]'s parent does not exist. Please make sure the parent is created before this service`\n        );\n      }\n      if (this.registeredIds.get(parent) === 'node') {\n        throw new Error(`The service [${id}]'s parent is not a group`);\n      }\n    }\n\n    this.registeredIds.set(id, 'node');\n\n    this.nodes.set(id, {\n      id,\n      type: 'service',\n      icon,\n      iconText,","sourceCodeStart":71,"sourceCodeEnd":107,"githubUrl":"https://github.com/mermaid-js/mermaid/blob/d93e9c88c01a599c062ee6a3f1462e3558ac6b90/packages/mermaid/src/diagrams/architecture/architectureDb.ts#L71-L107","documentation":"Thrown by addService when the service's parent ('in' field) equals its own id. Placing a service inside itself would create a self-referential containment cycle, so the db rejects it explicitly before any structural work.","triggerScenarios":"addService({ id: 'X', in: 'X' }); or user text like 'service: X { ... } in X'.","commonSituations":"Auto-generated architecture specs where a node is mistakenly listed as its own parent, or a templating bug copies a node id into its parent slot.","solutions":["Ensure the parent id differs from the service id.","Omit the 'in' field when the service is top-level.","Validate id !== parent before calling addService."],"exampleFix":"// before\ndb.addService({ id: 'svc', in: 'svc' });\n\n// after\ndb.addService({ id: 'svc' }); // top-level\n// or\ndb.addService({ id: 'svc', in: 'groupA' });","handlingStrategy":"validation","validationCode":"if (id === parent) {\n  throw new Error(`Service '${id}' cannot be its own parent`);\n}\ndb.addService({ id, in: parent });","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Always derive parent from a separate source than the node id.","Omit 'in' for top-level services."],"tags":["architecture","mermaid","validation","cycle","parent"],"backgroundTag":null,"analyzedSha":"d93e9c88c01a599c062ee6a3f1462e3558ac6b90","analyzedAt":"2026-08-12T06:23:11.304Z","schemaVersion":2},"datasetVersion":"2026-08-12T13:17:24.610Z"}