Multi-projects
Sometimes you may want to split your LikeC4 model into multiple ones, based on domains, teams, or any other criteria.
You can do this by creating multiple projects in your workspace and linking them together.
You can also use this feature to share your model with other teams or projects.
Create likec4.config.json files in the folders you want to be projects:
Directorycloud
- likec4.config.json
- service1.c4
- service2.c4
- …
Directoryexternals
- likec4.config.json
- amazon.c4
- …
LikeC4 finds projects by scanning the workspace (the folder open in the editor, or the path given to the CLI) for config files, skipping folders like node_modules and .git.
Each config file defines a project in its folder.
A source file belongs to the project with the closest folder.
Files outside of any project folder, and not included by any project, belong to the default project.
Projects can be nested.
In this case, files from the nested project are not part of the parent project.
Directorycloud
- likec4.config.json
- service1.c4
- service2.c4
Directorynested
- likec4.config.json
- service3.c4 // this will be part of the ‘nested’ project, not the ‘cloud’ project
Import elements
Section titled “Import elements”You can import elements from other projects by using the import keyword.
import { serviceA } from 'projectA'
model { serviceB = service { -> serviceA.api 'calls serviceA' }}Share specification
Section titled “Share specification”You can share specification files (or any other LikeC4 sources) across multiple projects using the include configuration option.
Using include paths
Section titled “Using include paths”Add an include configuration to your project to include files from directories outside the project folder:
Directoryshared
- specs.c4
- common-styles.c4
Directorycloud
- likec4.config.json
- services.c4
- …
Directoryexternals
- likec4.config.json
- amazon.c4
- …
Both cloud and externals projects can include the shared specification:
{ "$schema": "https://likec4.dev/schemas/config.json", "name": "cloud", "include": { "paths": ["../shared"] }}{ "$schema": "https://likec4.dev/schemas/config.json", "name": "externals", "include": { "paths": ["../shared"] }}Paths are relative to the project folder.
For maxDepth, fileThreshold and the rules for paths, see Include additional directories.
Using symlinks (alternative)
Section titled “Using symlinks (alternative)”Alternatively, you can use symlinks to share files:
Directoryshared
- specs.c4
Directorycloud
- specs.c4 // -> ../shared/specs.c4
- likec4.config.json
- …
Directoryexternals
- specs.c4 // -> ../shared/specs.c4
- likec4.config.json
- …