{"record":{"id":"d2f527cd24d5faec","repo":"mermaid-js/mermaid","slug":"the-service-id-id-is-already-in-use-by-anothe","errorCode":null,"errorMessage":"The service id [${id}] is already in use by another ${this.registeredIds.get(id)}","messagePattern":"The service id \\[(.+?)\\] is already in use by another (.+?)","errorType":"validation","errorClass":null,"httpStatus":null,"severity":"error","filePath":"packages/mermaid/src/diagrams/architecture/architectureDb.ts","lineNumber":83,"sourceCode":"    this.groups = new Map();\n    this.edges = [];\n    this.layoutHints = [];\n    this.registeredIds = new Map();\n    this.dataStructures = undefined;\n    this.elements = new Map();\n    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');","sourceCodeStart":65,"sourceCodeEnd":101,"githubUrl":"https://github.com/mermaid-js/mermaid/blob/d93e9c88c01a599c062ee6a3f1462e3558ac6b90/packages/mermaid/src/diagrams/architecture/architectureDb.ts#L65-L101","documentation":"Thrown by ArchitectureDB.addService when the service id already exists in registeredIds. The map stores every node/group id shared across services, junctions, and groups, so a collision with any prior entity (service, junction, or group) trips this. The suffix in the message ('node' or 'group') tells you which kind of entity already owns the id.","triggerScenarios":"Defining two services with the same id; reusing a junction or group id as a service id; calling addService twice in a loop without unique ids.","commonSituations":"Generator producing duplicate ids, copy-pasted architecture blocks, or parsing user text where the same label maps to the same id twice.","solutions":["Give each service a unique id; namespace ids if labels repeat.","Check db.getNode(id) / registeredIds before adding.","If the duplicate is intentional, alias via a different id and a title."],"exampleFix":"// before\ndb.addService({ id: 'api', icon: 'foo' });\ndb.addService({ id: 'api', icon: 'bar' }); // throws\n\n// after\ndb.addService({ id: 'api', icon: 'foo' });\ndb.addService({ id: 'api2', title: 'api', icon: 'bar' });","handlingStrategy":"validation","validationCode":"function assertUnique(db: ArchitectureDB, id: string) {\n  if (db.getNode(id)) throw new Error(`id '${id}' already exists`);\n}\nassertUnique(db, 'api');\ndb.addService({ id: 'api', icon: 'foo' });","typeGuard":"function isIdFree(db: ArchitectureDB, id: string): boolean {\n  return db.getNode(id) === null;\n}","tryCatchPattern":null,"preventionTips":["Namespace ids (e.g. 'svc_', 'j_', 'grp_') to avoid cross-type collisions.","Generate ids deterministically and dedupe before insertion.","Check db.getNode(id) before every add* call."],"tags":["architecture","mermaid","validation","duplicate-id","service"],"backgroundTag":null,"analyzedSha":"d93e9c88c01a599c062ee6a3f1462e3558ac6b90","analyzedAt":"2026-08-12T06:23:11.304Z","schemaVersion":2},"datasetVersion":"2026-08-12T13:17:24.610Z"}