{"record":{"id":"cae729e729e22f82","repo":"mermaid-js/mermaid","slug":"the-group-id-cannot-be-placed-within-itself","errorCode":null,"errorMessage":"The group [${id}] cannot be placed within itself","messagePattern":"The group \\[(.+?)\\] cannot be placed within itself","errorType":"validation","errorClass":null,"httpStatus":null,"severity":"error","filePath":"packages/mermaid/src/diagrams/architecture/architectureDb.ts","lineNumber":168,"sourceCode":"  }\n\n  public getNodes(): ArchitectureNode[] {\n    return [...this.nodes.values()];\n  }\n\n  public getNode(id: string): ArchitectureNode | null {\n    return this.nodes.get(id) ?? null;\n  }\n\n  public addGroup({ id, icon, in: parent, title }: ArchitectureGroup): void {\n    if (this.registeredIds.has(id)) {\n      throw new Error(\n        `The group 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 group [${id}] cannot be placed within itself`);\n      }\n      if (!this.registeredIds.has(parent)) {\n        throw new Error(\n          `The group [${id}]'s parent does not exist. Please make sure the parent is created before this group`\n        );\n      }\n      if (this.registeredIds.get(parent) === 'node') {\n        throw new Error(`The group [${id}]'s parent is not a group`);\n      }\n    }\n\n    this.registeredIds.set(id, 'group');\n\n    this.groups.set(id, {\n      id,\n      icon,\n      title,\n      in: parent,","sourceCodeStart":150,"sourceCodeEnd":186,"githubUrl":"https://github.com/mermaid-js/mermaid/blob/d93e9c88c01a599c062ee6a3f1462e3558ac6b90/packages/mermaid/src/diagrams/architecture/architectureDb.ts#L150-L186","documentation":"Thrown by ArchitectureDB.addGroup when a group is declared with its `in` (parent) field equal to its own `id`. Architecture groups form a strict containment tree, so a group cannot be its own ancestor. The check fires before the group is registered, so no partial state is left behind.","triggerScenarios":"Calling db.addGroup({ id: 'api', in: 'api' }) — the `in` value matches `id`. In DSL terms, writing `group api in api`.","commonSituations":"Copy-paste of a group block where the parent name was not changed from the id; auto-generated diagrams that derive `in` from the current group's id; refactoring a group id without updating the self-referential `in`.","solutions":["Remove the `in` field entirely if the group should be top-level.","Set `in` to the id of a different, already-declared group."],"exampleFix":"// before\ndb.addGroup({ id: 'api', in: 'api' });\n// after\ndb.addGroup({ id: 'api' });\n//   or, nest under an existing group\ndb.addGroup({ id: 'backend' });\ndb.addGroup({ id: 'api', in: 'backend' });","handlingStrategy":"validation","validationCode":"function addGroupSafe(db, g) {\n  if (g.in !== undefined && g.in === g.id) {\n    throw new Error(`Refusing to add group: 'in' equals 'id' (${g.id})`);\n  }\n  db.addGroup(g);\n}","typeGuard":"const isSelfParent = (g) => g.in !== undefined && g.in === g.id;","tryCatchPattern":null,"preventionTips":["Validate id !== parent before calling addGroup.","Omit the `in` field for top-level groups rather than echoing the id."],"tags":["architecture","hierarchy","validation","group"],"backgroundTag":null,"analyzedSha":"d93e9c88c01a599c062ee6a3f1462e3558ac6b90","analyzedAt":"2026-08-12T06:23:11.304Z","schemaVersion":2},"datasetVersion":"2026-08-12T18:17:37.767Z"}