Skip to the content
Krizaka TypeScript
Krizaka TypeScript

@krizaka/architecture

The C4 view of a repository generated from its code: containers, components, the imports between them and the external services, as JSON and text, on a local checkout.

Install

bashTerminal
npm install @krizaka/architecture

The C4 view of a repository, generated from its code (krizaka/.github#355, first slice; ADR-013: one source per rule set). Dependency-free (Node built-ins), it runs on a local checkout and gives the same output wherever it runs, so the docs, krizaka.com and the founder cockpit all show the architecture of the code, not of what is deployed.

npx krizaka-architecture ../my-repo --out c4.json                 # the three levels
npx krizaka-architecture ../my-repo --level containers            # one level, { level, nodes, edges }, on stdout
npx krizaka-architecture ../my-repo --out c4.json --text c4.md    # plus the text version
import { buildC4, toText } from "@krizaka/architecture";
const c4 = buildC4("/path/to/checkout"); // { schema: "krizaka.c4/1", repo, levels: { context, containers, components } }

What is read

LevelNodesEdges
contextthe system (the repo) and what it reaches: external services, Krizaka librariessystem reads an external service, uses the libraries
containersnpm/yarn workspaces and pnpm-workspace.yaml packages (app or library; a Next.js, Expo, Vite, Express, Fastify or Hono dependency, or apps/, makes an app), Maven <module>s, or the root package alonecontainer uses another (a declared dependency or an import) and reads an external service
componentsthe first folder under src/ (or the container root) of each container; root for loose filescomponent imports component (relative and @/ imports), uses a container, reads an external service

External services come from the env declarations (lib/env.ts, env.ts, .env.example) and process.env.X reads, by the org contexts (DATABASE_, AUTH_, MEDIA_, MAIL_, PUSH_, PAYMENTS_, REALTIME_, ABUSE_, OBSERVABILITY_, AI_): a vendor is a value, so it never appears (MAIL_PROVIDER=mailgun is « Mail provider »). APP_ and OPERATOR_ are the app's own settings, not external services.

Every node lists the files behind it (repo-relative, capped at 200, fileCount is the true number) and every edge the files that cause it (capped at 20). Tests, stories, node_modules, dist, .next, target are left out. The output is deterministic (sorted, no date): a diff of two runs is a diff of the architecture.

Calling it from the cockpit (local, private)

The founder cockpit runs it per repo on the Mac and reads { nodes, edges, level }:

import { execFileSync } from "node:child_process";
const level = JSON.parse(execFileSync("npx", ["--yes", "@krizaka/architecture", repoPath, "--level", "containers"], { encoding: "utf8" }));

Not in this package yet: SonarQube Architecture (intended architecture and deviations), and rendering on krizaka.com / the docs.

Exports

The 3 names the package exports, read from its types.

NameKindWhat it is
buildC4functionThe C4 view of a checkout: \{ schema, repo, levels: \{ context, containers, components \} \}, deterministic.
SCHEMAconstant
toTextfunction

Package

Version on npm0.1.0 (npm)
LicenceApache-2.0
Node.js>=22
Dependenciesnone
Sourcearchitecture

Changelog

0.1.0

Minor changes

  • New package: the C4 view of a repository generated from its code (containers from the workspaces or Maven modules, components from the folders, the imports between them, external services from the env declarations), as JSON and text, with a krizaka-architecture <repo> --out <file> CLI that runs on a local checkout (krizaka/.github#371).

On this page