-
-
Notifications
You must be signed in to change notification settings - Fork 257
feat(core): add LikeC4 integration for interactive C4 diagrams #2059
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
boyney123
wants to merge
1
commit into
main
Choose a base branch
from
feat/likec4-integration
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,5 @@ | ||
| --- | ||
| "@eventcatalog/core": patch | ||
| --- | ||
|
|
||
| Add LikeC4 integration for interactive C4 architecture diagrams in EventCatalog |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
13 changes: 13 additions & 0 deletions
13
eventcatalog/src/components/MDX/LikeC4View/LikeC4View.astro
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,13 @@ | ||
| --- | ||
| import LikeC4ViewWrapper from './LikeC4ViewWrapper'; | ||
|
|
||
| interface Props { | ||
| viewId: string; | ||
| project?: string; | ||
| height?: string; | ||
| } | ||
|
|
||
| const { viewId, project, height } = Astro.props; | ||
| --- | ||
|
|
||
| <LikeC4ViewWrapper viewId={viewId} project={project} height={height} client:only="react" /> |
53 changes: 53 additions & 0 deletions
53
eventcatalog/src/components/MDX/LikeC4View/LikeC4ViewWrapper.tsx
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,53 @@ | ||
| import React, { Suspense, lazy, useMemo, type ComponentType } from 'react'; | ||
| import { getProjectLoader } from 'virtual:likec4-projects'; | ||
|
|
||
| interface LikeC4ViewWrapperProps { | ||
| viewId: string; | ||
| project?: string; | ||
| height?: string; | ||
| } | ||
|
|
||
| interface LikeC4ViewProps { | ||
| viewId: string; | ||
| controls?: boolean; | ||
| browser?: { | ||
| enableFocusMode?: boolean; | ||
| enableSearch?: boolean; | ||
| }; | ||
| } | ||
|
|
||
| // Cache for lazy components to avoid recreating them | ||
| const lazyComponentCache = new Map<string, ComponentType<LikeC4ViewProps>>(); | ||
|
|
||
| function getLazyComponent(project: string): ComponentType<LikeC4ViewProps> { | ||
| const key = project || 'default'; | ||
|
|
||
| if (!lazyComponentCache.has(key)) { | ||
| const loader = getProjectLoader(key); | ||
| const LazyComponent = lazy(() => loader().then((mod: any) => ({ default: mod.LikeC4View }))); | ||
| lazyComponentCache.set(key, LazyComponent); | ||
| } | ||
|
|
||
| return lazyComponentCache.get(key)!; | ||
| } | ||
|
|
||
| export default function LikeC4ViewWrapper({ viewId, project, height = '600px' }: LikeC4ViewWrapperProps) { | ||
| const LikeC4ViewComponent = useMemo(() => getLazyComponent(project || 'default'), [project]); | ||
|
|
||
| return ( | ||
| <div style={{ height, maxHeight: height }} className="w-full overflow-hidden rounded-lg border border-gray-200"> | ||
| <Suspense | ||
| fallback={<div className="h-full flex items-center justify-center bg-gray-100 rounded-lg">Loading diagram...</div>} | ||
| > | ||
| <LikeC4ViewComponent | ||
| viewId={viewId as any} | ||
| controls={false} | ||
| browser={{ | ||
| enableFocusMode: false, | ||
| enableSearch: false, | ||
| }} | ||
| /> | ||
| </Suspense> | ||
| </div> | ||
| ); | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,91 @@ | ||
| import type { Plugin } from 'vite'; | ||
| import { glob } from 'glob'; | ||
| import { readFileSync } from 'node:fs'; | ||
| import { join, dirname } from 'node:path'; | ||
|
|
||
| interface LikeC4Config { | ||
| name: string; | ||
| } | ||
|
|
||
| /** | ||
| * Vite plugin that auto-discovers LikeC4 projects and generates a registry | ||
| * Scans for likec4.config.json files and creates static imports for each project | ||
| */ | ||
| export function likeC4ProjectRegistry(workspaceDir: string): Plugin { | ||
| const virtualModuleId = 'virtual:likec4-projects'; | ||
| const resolvedVirtualModuleId = '\0' + virtualModuleId; | ||
|
|
||
| let discoveredProjects: string[] = []; | ||
|
|
||
| return { | ||
| name: 'likec4-project-registry', | ||
|
|
||
| async buildStart() { | ||
| // Find all likec4.config.json files | ||
| const configFiles = await glob('**/likec4.config.json', { | ||
| cwd: workspaceDir, | ||
| ignore: ['**/node_modules/**'], | ||
| absolute: true, | ||
| }); | ||
|
|
||
| discoveredProjects = []; | ||
|
|
||
| for (const configPath of configFiles) { | ||
| try { | ||
| const content = readFileSync(configPath, 'utf-8'); | ||
| const config: LikeC4Config = JSON.parse(content); | ||
| if (config.name) { | ||
| discoveredProjects.push(config.name); | ||
| } | ||
| } catch (e) { | ||
| console.warn(`[likec4-registry] Failed to parse ${configPath}:`, e); | ||
| } | ||
| } | ||
|
|
||
| if (discoveredProjects.length > 0) { | ||
| console.log(`[likec4-registry] Discovered projects: ${discoveredProjects.join(', ')}`); | ||
| } | ||
| }, | ||
|
|
||
| resolveId(id) { | ||
| if (id === virtualModuleId) { | ||
| return resolvedVirtualModuleId; | ||
| } | ||
| }, | ||
|
|
||
| load(id) { | ||
| if (id === resolvedVirtualModuleId) { | ||
| // Generate the registry module with static imports | ||
| const imports = discoveredProjects.map((name, i) => `import * as project_${i} from 'likec4:react/${name}';`).join('\n'); | ||
|
|
||
| const registryEntries = discoveredProjects | ||
| .map((name, i) => ` '${name}': () => Promise.resolve(project_${i}),`) | ||
| .join('\n'); | ||
|
|
||
| return ` | ||
| // Auto-generated LikeC4 project registry | ||
| // Discovered ${discoveredProjects.length} project(s) | ||
|
|
||
| ${imports} | ||
| import * as defaultProject from 'likec4:react'; | ||
|
|
||
| export const projectRegistry = { | ||
| 'default': () => Promise.resolve(defaultProject), | ||
| ${registryEntries} | ||
| }; | ||
|
|
||
| export const discoveredProjects = ${JSON.stringify(discoveredProjects)}; | ||
|
|
||
| export function getProjectLoader(projectName) { | ||
| return projectRegistry[projectName] || projectRegistry['default']; | ||
| } | ||
| `; | ||
| } | ||
| }, | ||
|
|
||
| // Watch for changes to likec4.config.json files | ||
| configureServer(server) { | ||
| server.watcher.add(join(workspaceDir, '**/likec4.config.json')); | ||
| }, | ||
| }; | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
likec4is imported at runtime ineventcatalog/astro.config.mjs(likec4/vite-plugin), but this commit adds it underdevDependencies; consumers installing@eventcatalog/corefrom npm do not get dev dependencies, soeventcatalogstartup/build will fail with module resolution errors before any pages render. Movelikec4(and any directly imported LikeC4 package) intodependenciesso published installs can load the config.Useful? React with 👍 / 👎.