---
# System prepended metadata

title: Server Circular Dependencies
tags: [Circular Dependency]

---

#    Server Circular Dependencies

## Overview / Current contex

Alkemio Server is built with nodeJS and nestJS. Nest is angular-based server-side framework that has a set of well-known issues with its dependency graph. NodeJS also has a known set of issues, especially around using barrel (index) files, in the framework. We have installed a tool called [Madge](https://github.com/pahen/madge)to help us track issues with the latter. 


## Running madge

To run madge, checkout `dependency-tracker` branch on the server, run `npm install` and run `npx madge --circular src/`.
Currently, there are 68 pending issues.

```bash
1) domain/agent/credential/credential.entity.ts > domain/agent/agent/agent.entity.ts
2) domain/collaboration/aspect/aspect.entity.ts > domain/collaboration/callout/callout.entity.ts
3) domain/collaboration/callout/callout.entity.ts > domain/collaboration/callout/callout.interface.ts > domain/common/canvas/index.ts > domain/common/canvas/canvas.entity.ts
4) domain/common/visual/visual.entity.ts > domain/context/context/context.entity.ts > domain/common/reference/reference.entity.ts > domain/collaboration/aspect/aspect.entity.ts > domain/collaboration/callout/callout.entity.ts > domain/collaboration/callout/callout.interface.ts > domain/common/canvas/index.ts > domain/common/canvas/canvas.entity.ts
5) domain/common/interfaces/groupable.interface.ts > domain/community/community/community.interface.ts
6) domain/communication/communication/communication.entity.ts > domain/communication/discussion/discussion.entity.ts
7) domain/community/community/community.interface.ts > domain/community/application/application.interface.ts
8) domain/common/index.ts > domain/common/interfaces/index.ts > domain/common/interfaces/groupable.interface.ts > domain/community/community/community.interface.ts > domain/community/application/application.interface.ts > domain/community/user/user.interface.ts > domain/common/preference-set/index.ts > domain/common/preference-set/preference.set.entity.ts > domain/common/preference-set/preference.set.interface.ts > domain/common/preference/preference.interface.ts > domain/common/preference/preference.definition.interface.ts
9) domain/common/preference-set/index.ts > domain/common/preference-set/preference.set.entity.ts > domain/common/preference/preference.entity.ts
10) domain/common/preference/preference.entity.ts > domain/common/preference/preference.definition.entity.ts
11) domain/community/profile/profile.interface.ts > domain/common/visual/index.ts > domain/common/visual/visual.entity.ts > domain/context/context/context.entity.ts > domain/common/reference/reference.entity.ts > domain/collaboration/aspect/aspect.entity.ts > domain/collaboration/callout/callout.entity.ts > domain/collaboration/callout/callout.interface.ts > domain/template/aspect-template/aspect.template.interface.ts > domain/template/template-base/template.base.interface.ts > domain/template/template-info/template.info.interface.ts > domain/common/index.ts > domain/common/interfaces/index.ts > domain/common/interfaces/groupable.interface.ts > domain/community/community/community.interface.ts > domain/community/application/application.interface.ts > domain/community/user/user.interface.ts > domain/community/contributor/contributor.interface.ts
12) domain/community/user-group/user-group.interface.ts > domain/community/profile/profile.interface.ts > domain/common/visual/index.ts > domain/common/visual/visual.entity.ts > domain/context/context/context.entity.ts > domain/common/reference/reference.entity.ts > domain/collaboration/aspect/aspect.entity.ts > domain/collaboration/callout/callout.entity.ts > domain/collaboration/callout/callout.interface.ts > domain/template/aspect-template/aspect.template.interface.ts > domain/template/template-base/template.base.interface.ts > domain/template/template-info/template.info.interface.ts > domain/common/index.ts > domain/common/interfaces/index.ts > domain/common/interfaces/groupable.interface.ts > domain/community/community/community.interface.ts
13) domain/common/interfaces/groupable.interface.ts > domain/community/organization/organization.interface.ts
14) domain/community/user-group/user-group.interface.ts > domain/community/profile/profile.interface.ts > domain/common/visual/index.ts > domain/common/visual/visual.entity.ts > domain/context/context/context.entity.ts > domain/common/reference/reference.entity.ts > domain/collaboration/aspect/aspect.entity.ts > domain/collaboration/callout/callout.entity.ts > domain/collaboration/callout/callout.interface.ts > domain/template/aspect-template/aspect.template.interface.ts > domain/template/template-base/template.base.interface.ts > domain/template/template-info/template.info.interface.ts > domain/common/index.ts > domain/common/interfaces/index.ts > domain/common/interfaces/groupable.interface.ts > domain/community/organization/organization.interface.ts
15) domain/community/user-group/user-group.interface.ts > domain/community/profile/profile.interface.ts > domain/common/visual/index.ts > domain/common/visual/visual.entity.ts > domain/context/context/context.entity.ts > domain/common/reference/reference.entity.ts > domain/collaboration/aspect/aspect.entity.ts > domain/collaboration/callout/callout.entity.ts > domain/collaboration/callout/callout.interface.ts > domain/template/aspect-template/aspect.template.interface.ts > domain/template/template-base/template.base.interface.ts > domain/template/template-info/template.info.interface.ts > domain/common/index.ts > domain/common/interfaces/index.ts > domain/common/interfaces/groupable.interface.ts
16) domain/common/reference/reference.entity.ts > domain/collaboration/aspect/aspect.entity.ts > domain/collaboration/callout/callout.entity.ts > domain/collaboration/callout/callout.interface.ts > domain/template/aspect-template/aspect.template.interface.ts > domain/template/template-base/template.base.interface.ts > domain/template/template-info/template.info.interface.ts > domain/common/index.ts > domain/common/reference/index.ts
17) domain/common/reference/reference.entity.ts > domain/collaboration/aspect/aspect.entity.ts > domain/collaboration/callout/callout.entity.ts > domain/collaboration/callout/callout.interface.ts > domain/template/aspect-template/aspect.template.interface.ts > domain/template/template-base/template.base.interface.ts > domain/template/template-info/template.info.interface.ts > domain/common/index.ts > domain/common/tagset/index.ts > domain/common/tagset/tagset.entity.ts > domain/community/profile/profile.entity.ts
18) domain/common/tagset/tagset.entity.ts > domain/community/profile/profile.entity.ts
19) domain/common/visual/visual.entity.ts > domain/context/context/context.entity.ts > domain/common/reference/reference.entity.ts > domain/collaboration/aspect/aspect.entity.ts > domain/collaboration/callout/callout.entity.ts > domain/collaboration/callout/callout.interface.ts > domain/template/aspect-template/aspect.template.interface.ts > domain/template/template-base/template.base.interface.ts > domain/template/template-info/template.info.interface.ts > domain/common/index.ts > domain/common/tagset/index.ts > domain/common/tagset/tagset.entity.ts > domain/community/profile/profile.entity.ts
20) domain/community/profile/profile.interface.ts > domain/common/visual/index.ts > domain/common/visual/visual.entity.ts > domain/context/context/context.entity.ts > domain/common/reference/reference.entity.ts > domain/collaboration/aspect/aspect.entity.ts > domain/collaboration/callout/callout.entity.ts > domain/collaboration/callout/callout.interface.ts > domain/template/aspect-template/aspect.template.interface.ts > domain/template/template-base/template.base.interface.ts > domain/template/template-info/template.info.interface.ts > domain/common/index.ts > domain/common/tagset/index.ts > domain/common/tagset/tagset.entity.ts > domain/community/profile/profile.entity.ts
21) domain/common/visual/index.ts > domain/common/visual/visual.entity.ts > domain/context/context/context.entity.ts > domain/common/reference/reference.entity.ts > domain/collaboration/aspect/aspect.entity.ts > domain/collaboration/callout/callout.entity.ts > domain/collaboration/callout/callout.interface.ts > domain/template/aspect-template/aspect.template.interface.ts > domain/template/template-base/template.base.interface.ts > domain/template/template-info/template.info.interface.ts > domain/common/index.ts
22) domain/collaboration/callout/callout.entity.ts > domain/collaboration/collaboration/collaboration.entity.ts
23) domain/collaboration/collaboration/collaboration.entity.ts > domain/collaboration/relation/relation.entity.ts
24) domain/common/visual/visual.entity.ts > domain/context/context/context.entity.ts > domain/common/reference/reference.entity.ts > domain/collaboration/aspect/aspect.entity.ts > domain/collaboration/callout/callout.entity.ts > domain/template/aspect-template/aspect.template.entity.ts > domain/template/template-base/template.base.entity.ts > domain/template/template-info/template.info.entity.ts
25) domain/template/aspect-template/aspect.template.entity.ts > domain/template/templates-set/templates.set.entity.ts
26) domain/template/templates-set/templates.set.entity.ts > domain/template/canvas-template/canvas.template.entity.ts
27) domain/template/templates-set/templates.set.entity.ts > domain/template/lifecycle-template/lifecycle.template.entity.ts
28) domain/common/reference/reference.entity.ts > domain/collaboration/aspect/aspect.entity.ts
29) domain/common/visual/visual.entity.ts > domain/context/context/context.entity.ts > domain/common/reference/reference.entity.ts > domain/collaboration/aspect/aspect.entity.ts
30) domain/context/context/context.entity.ts > domain/common/reference/reference.entity.ts
31) domain/common/visual/visual.entity.ts > domain/context/context/context.entity.ts
32) domain/context/actor-group/actor-group.entity.ts > domain/context/actor/actor.entity.ts
33) domain/context/ecosystem-model/ecosystem-model.entity.ts > domain/context/actor-group/actor-group.entity.ts
34) domain/collaboration/project/project.entity.ts > domain/collaboration/agreement/agreement.entity.ts
35) domain/community/community/community.entity.ts > domain/community/application/application.entity.ts
36) domain/community/application/application.entity.ts > domain/community/user/user.entity.ts
37) domain/community/community/community.entity.ts > domain/community/user-group/user-group.entity.ts
38) domain/community/user-group/user-group.entity.ts > domain/community/organization/organization.entity.ts
39) domain/challenge/challenge/challenge.interface.ts > domain/collaboration/opportunity/opportunity.interface.ts
40) domain/challenge/challenge/challenge.entity.ts > domain/challenge/hub/hub.entity.ts
41) domain/collaboration/opportunity/opportunity.entity.ts > domain/challenge/challenge/challenge.entity.ts
42) domain/collaboration/project/project.entity.ts > domain/collaboration/opportunity/opportunity.entity.ts
43) common/index.ts > common/pipes/index.ts > common/pipes/validation.pipe.ts > core/validation/handlers/base/base.handler.ts > domain/community/organization/index.ts > domain/community/organization/dto/organization.dto.update.ts
44) domain/challenge/challenge/challenge.service.ts > core/index.ts > core/bootstrap/index.ts > core/bootstrap/bootstrap.service.ts > domain/challenge/hub/hub.service.authorization.ts > domain/challenge/challenge/challenge.service.authorization.ts
45) core/index.ts > core/bootstrap/index.ts > core/bootstrap/bootstrap.service.ts > domain/challenge/hub/hub.service.authorization.ts > domain/challenge/hub/hub.service.ts
46) domain/challenge/challenge/challenge.service.ts > core/index.ts > core/bootstrap/index.ts > core/bootstrap/bootstrap.service.ts > domain/challenge/hub/hub.service.authorization.ts > domain/challenge/hub/hub.service.ts
47) core/index.ts > core/bootstrap/index.ts > core/bootstrap/bootstrap.service.ts > domain/challenge/hub/hub.service.authorization.ts > domain/challenge/hub/hub.service.ts > domain/collaboration/opportunity/opportunity.service.ts
48) services/api/activity-log/dto/activity.log.dto.entry.callout.canvas.created.ts > services/api/activity-log/dto/activity.log.dto.entry.base.interface.ts > services/api/activity-log/dto/activity.log.entry.interface.ts
49) services/api/activity-log/dto/activity.log.dto.entry.base.interface.ts > services/api/activity-log/dto/activity.log.entry.interface.ts > services/api/activity-log/dto/activity.log.dto.entry.callout.card.comment.ts
50) services/api/activity-log/dto/activity.log.entry.interface.ts > services/api/activity-log/dto/activity.log.dto.entry.callout.card.comment.ts
51) services/api/activity-log/dto/activity.log.dto.entry.base.interface.ts > services/api/activity-log/dto/activity.log.entry.interface.ts > services/api/activity-log/dto/activity.log.dto.entry.callout.card.created.ts
52) services/api/activity-log/dto/activity.log.entry.interface.ts > services/api/activity-log/dto/activity.log.dto.entry.callout.card.created.ts
53) services/api/activity-log/dto/activity.log.dto.entry.base.interface.ts > services/api/activity-log/dto/activity.log.entry.interface.ts > services/api/activity-log/dto/activity.log.dto.entry.callout.discussion.comment.ts
54) services/api/activity-log/dto/activity.log.entry.interface.ts > services/api/activity-log/dto/activity.log.dto.entry.callout.discussion.comment.ts
55) services/api/activity-log/dto/activity.log.dto.entry.base.interface.ts > services/api/activity-log/dto/activity.log.entry.interface.ts > services/api/activity-log/dto/activity.log.dto.entry.callout.published.ts
56) services/api/activity-log/dto/activity.log.entry.interface.ts > services/api/activity-log/dto/activity.log.dto.entry.callout.published.ts
57) services/api/activity-log/dto/activity.log.dto.entry.base.interface.ts > services/api/activity-log/dto/activity.log.entry.interface.ts > services/api/activity-log/dto/activity.log.dto.entry.challenge.created.ts
58) services/api/activity-log/dto/activity.log.entry.interface.ts > services/api/activity-log/dto/activity.log.dto.entry.challenge.created.ts
59) services/api/activity-log/dto/activity.log.dto.entry.base.interface.ts > services/api/activity-log/dto/activity.log.entry.interface.ts > services/api/activity-log/dto/activity.log.dto.entry.member.joined.interface.ts
60) services/api/activity-log/dto/activity.log.entry.interface.ts > services/api/activity-log/dto/activity.log.dto.entry.member.joined.interface.ts
61) services/api/activity-log/dto/activity.log.dto.entry.base.interface.ts > services/api/activity-log/dto/activity.log.entry.interface.ts > services/api/activity-log/dto/activity.log.dto.entry.opportunity.created.ts
62) services/api/activity-log/dto/activity.log.entry.interface.ts > services/api/activity-log/dto/activity.log.dto.entry.opportunity.created.ts
63) services/api/search/dto/search.result.entry.interface.ts > services/api/search/dto/search.result.dto.entry.challenge.ts > services/api/search/dto/search.result.dto.entry.base.interface.ts
64) services/api/search/dto/search.result.entry.interface.ts > services/api/search/dto/search.result.dto.entry.challenge.ts
65) services/api/search/dto/search.result.entry.interface.ts > services/api/search/dto/search.result.dto.entry.hub.ts
66) services/api/search/dto/search.result.entry.interface.ts > services/api/search/dto/search.result.dto.entry.opportunity.ts
67) services/api/search/dto/search.result.entry.interface.ts > services/api/search/dto/search.result.dto.entry.organization.ts
68) services/api/search/dto/search.result.entry.interface.ts > services/api/search/dto/search.result.dto.entry.user.ts
```

## Grouping

We have grouped issues into 5 categories

1. Entity - entity type relationships - when we have an `Entity A` that has a relationship to `Entity B` and we want to have typeORM let us traverse the tree both ways, we integrate it `Entity A` --> `Entity B` and `Entity B` --> `Entity A`. That creates a cirular file dependency, but this is **NOT** an issue as the dependency is between **types** and not **instances**. E.g. `services/api/search/dto/search.result.entry.interface.ts > services/api/search/dto/search.result.dto.entry.user.ts`
2. Barrel file (index file) dependencies, e.g. `domain/common/preference-set/index.ts > domain/common/preference-set/preference.set.entity.ts > domain/common/preference/preference.entity.ts`
3. Structural issues, e.g. around the `ActivityLog` where we have an Abstract Class `IActivityLogEntry` presented as an interface and another Abstract Class `IActivityLogEntryBase` exactly the same that implements `IActivityLogEntry`.
4. Unknown
## Progress

- Barrel
    - [ ] 3) Valentin
    - [ ] 4) Valentin
    - [ ] 8) Valentin
    - [ ] 9) Valentin
    - [ ] 11) Valentin
    - [ ] 12) Valentin
    - [x] 14) Svetlio
    - [x] 15) Svetlio
    - [ ] 16) Svetlio
    - [ ] 17) Svetlio
    - [x] 20) Svetlio
    - [x] 21) Svetlio
    - [ ] 43) Aleks
    - [x] 44) Aleks
    - [x] 45) Aleks
    - [x] 46) Aleks
    - [x] 47) Aleks
###### tags: `Circular Dependency`, 'Issue', 'Server'