Rename Project to Diagram throughout the app

Per organized-ideas.md §8: the storage layer (DiagramRepository etc.) was
already renamed in an earlier phase; this finishes it everywhere else.

- domain/types.ts: Project -> Diagram. domain/project.ts -> domain/diagram.ts
  (createEmptyProject -> createEmptyDiagram, default name "Untitled Diagram").
- domain/compatibility.ts, domain/bom.ts: Project param/type -> Diagram.
- data/exportImport.ts: ProjectImportError -> DiagramImportError,
  projectToJson/downloadProjectFile/readProjectFile/normalizeProject -> their
  Diagram equivalents.
- state/projectStore.ts -> state/diagramStore.ts: useProjectStore ->
  useDiagramStore, the `project` field -> `diagram`, newProject/renameProject/
  importProject/applyRestoredProject -> *Diagram, restoredProjectUpdatedAt ->
  restoredDiagramUpdatedAt.
- Every component updated to match, compiler-guided (tsc -b enumerated each
  remaining call site after the core rename, the same approach used for the
  earlier catalog-parameter refactor).
- README updated for the terminology, and to match the repository class
  names (which had already been renamed but the README hadn't caught up).

No backend/schema changes: the JSON shape stored in diagrams.data never
changed, only TypeScript-side identifiers, so existing diagrams are
unaffected. One SQL comment fixed for accuracy (no migration needed).

Verified: tsc -b and oxlint clean; grepped src/ for any remaining
Project/project reference (none) after the sweep.
This commit is contained in:
2026-09-11 12:10:11 -05:00
parent cbbe96f575
commit 26f41b3d4a
34 changed files with 292 additions and 293 deletions
+5 -5
View File
@@ -1,5 +1,5 @@
import { allCableTypes } from './project'
import type { CableType, Catalog, Connection, Device, Project } from './types'
import { allCableTypes } from './diagram'
import type { CableType, Catalog, Connection, Device, Diagram } from './types'
/** One length within a cable type's group — e.g. "3 × 10ft". `distance`
* is undefined for the bucket of connections that have no length entered
@@ -82,7 +82,7 @@ function connectionCost(connection: Connection, cableType: CableType | undefined
return undefined
}
export function computeBom(project: Project, catalog: Catalog): Bom {
export function computeBom(diagram: Diagram, catalog: Catalog): Bom {
const cableTypes = new Map(allCableTypes(catalog).map((ct) => [ct.id, ct]))
const cableLines = new Map<string, BomCableLine>()
@@ -92,7 +92,7 @@ export function computeBom(project: Project, catalog: Catalog): Bom {
// addressable by (cableTypeId, distance) while building them up.
const lengthLines = new Map<string, Map<number | undefined, BomCableLengthLine>>()
for (const connection of project.connections) {
for (const connection of diagram.connections) {
const cableType = cableTypes.get(connection.cableTypeId)
const name = cableType?.name ?? 'Unknown Cable'
const unit = cableType?.unit ?? 'ft'
@@ -155,7 +155,7 @@ export function computeBom(project: Project, catalog: Catalog): Bom {
}
const deviceLines = new Map<string, BomDeviceLine>()
for (const device of project.devices) {
for (const device of diagram.devices) {
const key = deviceGroupKey(device)
const existing = deviceLines.get(key) ?? {
key,
+6 -6
View File
@@ -1,5 +1,5 @@
import { acceptedFamilies, getPortType, hasBridgingCableType } from './project'
import type { Catalog, Connection, Device, PortType, Project } from './types'
import { acceptedFamilies, getPortType, hasBridgingCableType } from './diagram'
import type { Catalog, Connection, Device, Diagram, PortType } from './types'
/**
* Two ports connect if the sets of families they each accept (their own
@@ -36,10 +36,10 @@ export interface ConnectionValidation {
* server-side later since it only depends on plain domain data.
*/
export function validateConnection(
project: Project,
diagram: Diagram,
catalog: Catalog,
candidate: ConnectionCandidate,
existingConnections: Connection[] = project.connections,
existingConnections: Connection[] = diagram.connections,
): ConnectionValidation {
const { sourceDeviceId, sourcePortId, targetDeviceId, targetPortId } = candidate
@@ -47,8 +47,8 @@ export function validateConnection(
return { valid: false, reason: 'A port cannot connect to itself.' }
}
const sourceDevice = project.devices.find((d) => d.id === sourceDeviceId)
const targetDevice = project.devices.find((d) => d.id === targetDeviceId)
const sourceDevice = diagram.devices.find((d) => d.id === sourceDeviceId)
const targetDevice = diagram.devices.find((d) => d.id === targetDeviceId)
const sourcePort = sourceDevice?.ports.find((p) => p.id === sourcePortId)
const targetPort = targetDevice?.ports.find((p) => p.id === targetPortId)
+2 -2
View File
@@ -1,7 +1,7 @@
import type { PortCategory, PortDirection } from './types'
// Device categories are no longer a fixed list — see `domain/project.ts`'s
// `allDeviceCategories` (built-ins + project-custom, merged).
// Device categories are no longer a fixed list — see `domain/diagram.ts`'s
// `allDeviceCategories` (public catalog + your own private ones, merged).
export const PORT_DIRECTIONS: { value: PortDirection; label: string }[] = [
{ value: 'input', label: 'Input' },
@@ -1,5 +1,5 @@
import { v4 as uuid } from 'uuid'
import type { CableType, Catalog, Device, DeviceCategoryDef, DeviceTemplate, PortType, Project } from './types'
import type { CableType, Catalog, Device, DeviceCategoryDef, Diagram, DeviceTemplate, PortType } from './types'
export function allPortTypes(catalog: Catalog): PortType[] {
return catalog.portTypes
@@ -125,7 +125,7 @@ export function expandCompatibleFamilyIds(selectedPortTypeIds: string[], allType
return [...families]
}
export function createEmptyProject(name = 'Untitled Project'): Project {
export function createEmptyDiagram(name = 'Untitled Diagram'): Diagram {
const now = new Date().toISOString()
return {
id: uuid(),
+4 -3
View File
@@ -16,11 +16,12 @@ export type PortCategory =
| 'other'
/** A device category id (references a DeviceCategoryDef). Kept as a plain
* string rather than a fixed union so projects can define their own. */
* string rather than a fixed union so users can define their own. */
export type DeviceCategory = string
/** A device grouping shown in the palette and category pickers. Built-ins
* ship in `library.ts`; users can add their own, scoped to the project. */
* ship in `library.ts`; users can add their own private ones via the
* shared catalog (see state/catalogStore.ts), not scoped to any one diagram. */
export interface DeviceCategoryDef {
id: string
name: string
@@ -134,7 +135,7 @@ export interface Connection {
notes?: string
}
export interface Project {
export interface Diagram {
id: string
name: string
createdAt: string