Skip to main content

Session Database

Cave uses a lightweight file-based session store to persist analysis data between CLI commands. There is no external database — everything is written to a single JSON file in your operating system's temp directory.

How It Works

When Cave runs, it creates a session file at:

<os.tmpdir()>/clean-arch-cli-session.json

For example on macOS/Linux this is typically /tmp/clean-arch-cli-session.json, and on Windows C:\Users\<you>\AppData\Local\Temp\clean-arch-cli-session.json.

The SessionDB class is a generic key-value store that reads and writes this file synchronously. It is typed against SessionData, which defines the full shape of everything Cave tracks about your project.

note

Always call .load() before any read operation — the in-memory state is not automatically synced from disk. Whenever an instance of the SessionDBAccess is created .load() is run.

SessionData Structure

This is the top-level type stored in the session file:

FieldTypeDescription
projectNamestringName of the project being analyzed
numUseCasesnumberTotal number of use cases found
numViolationsnumberTotal number of clean architecture violations
useCasesUseCaseEntry[]Per-use-case breakdown (see below)
filesFileStorage[]All scanned files and their classifications
edgesEdgeStorage[]Dependency edges between nodes
nodesNodeStorage[]All nodes discovered in the project

Use Case Entry

Each entry in the useCases array contains:

FieldTypeDescription
idstringUnique identifier
namestringUse case name
outNeighboursneighbourMapAdjacency map of node dependencies
fileKeysstring[]References into the files array
violationEdges[cleanNode, cleanNode][]Edges that violate clean architecture
missingNodescleanNode[]Expected nodes that were not found

Storage Types

FileStorage

Represents a single scanned file:

FieldTypeDescription
filePathstringAbsolute path to the file
fileType"java" | "python" | "javascript" | "typescript" | "unknown"The programming language of the source file
layercleanLayerWhich clean architecture layer it belongs to
nodecleanNodeThe node type it represents

EdgeStorage

Represents a dependency between two nodes:

FieldTypeDescription
idstringUnique edge identifier
sourcestringSource node name
targetstringTarget node name
type"DEPENDENCY"Always DEPENDENCY
status"VALID" | "INCORRECT_DEPENDENCY"Whether the dependency is allowed

NodeStorage

Represents a single node in the architecture graph:

FieldTypeDescription
idstringUnique node identifier
namestring?Display name
filePathstring?Path to the corresponding file
typecleanNodeNode type classification
layercleanLayerClean architecture layer
status"VALID" | "MISSING" | "VIOLATION"Health status of the node

Clean Architecture Layers

Cave maps every file to one of four clean architecture layers:

ValueLayer
enterpriseBusinessRulesEntities
applicationBusinessRulesUse Cases
interfaceAdaptersControllers, Presenters, ViewModels
frameworksAndDriversViews, Databases, Data Access

Node Types

Cave recognises the following node types across all layers:

NodeLayer
entitiesEnterprise Business Rules
inputBoundary inputData outputBoundary outputData useCaseInteractorApplication Business Rules
controller presenter viewModelInterface Adapters
view dataAccess dataAccessInterface databaseFrameworks & Drivers

neighbourMap

The neighbourMap type describes which node types each node is allowed (or found) to depend on:

type neighbourMap = Record<cleanNode, cleanNode[]>;

For example, a controller entry in the map would list all the node types it has outgoing dependencies to. This is used to detect violations — if a dependency points inward past the allowed boundary, it is flagged as INCORRECT_DEPENDENCY.