Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ Every education system organises what students should learn into structured docu

| | |
|---|---|
| **Visual Editor** | Build competency frameworks on an interactive canvas. Drag, connect, and organise items visually — no spreadsheets or hand-edited files required. |
| **Visual Editor** | Build competency frameworks in a tree view, and align their items to other frameworks (including CASE Global ones) by dragging — no spreadsheets or hand-edited files required. |
| **Publishing Server** | Publish frameworks through a standards-compliant API so that learning platforms, assessment tools, and credential systems can discover and consume them automatically. |
| **Identity and Access** | Multi-tenant security so that different organisations can each manage their own frameworks independently, with role-based access controls for viewers, authors, and administrators. |

Expand Down
12 changes: 5 additions & 7 deletions apps/editor/README.md
Original file line number Diff line number Diff line change
@@ -1,21 +1,19 @@
# OpenCASE — Visual Framework Editor

The Editor is the authoring interface for OpenCASE. It provides an interactive canvas where users build [1EdTech CASE](https://www.1edtech.org/activity/case) competency frameworks visually — organising learning objectives, connecting related standards, and publishing the result directly to the OpenCASE publishing server.
The Editor is the authoring interface for OpenCASE. It provides a tree view where users build [1EdTech CASE](https://www.1edtech.org/activity/case) competency frameworks visually — organising learning objectives, connecting related standards, and publishing the result directly to the OpenCASE publishing server.

---

## What it does

- **Visual canvas editing** — competencies appear as items on a canvas; users drag, reposition, and connect them to define relationships such as "is child of", "is related to", or "precedes"
- **Automatic layout** — when a framework is opened for the first time, the editor analyses its structure and applies an appropriate layout automatically, so items are arranged clearly from the start
- **Publish to the API** — frameworks edited on the canvas can be saved directly to the OpenCASE publishing server, making them immediately available to consuming systems
- **Tree editing** — a framework's items appear as a tree; users add and edit items and see the hierarchy at a glance
- **Crosswalks** — users align items to items in other frameworks on the server, or in CASE Global frameworks, by dragging one onto the other
- **Publish to the API** — edited frameworks can be saved directly to the OpenCASE publishing server, making them immediately available to consuming systems
- **Multi-tenant aware** — users sign in through the platform's identity service and work within their organisation's workspace

## How it works

A competency framework is a structured collection of items (individual learning objectives or standards) and associations (the relationships between them). On the canvas, items appear as nodes and associations appear as connections between them. Users can add, edit, reorder, and delete items; create associations between them; and rearrange the layout to suit the framework's structure.

The editor detects whether a framework is best displayed as a hierarchy, a radial layout, or a tree, and applies the most suitable arrangement before anything appears on screen.
A competency framework is a structured collection of items (individual learning objectives or standards) and associations (the relationships between them). The Tree View shows the items as a hierarchy, with a second panel of associated frameworks to align them to. Users can add and edit items and create, change, and remove associations to other frameworks.

Changes are saved as new immutable versions on the server, preserving a full history of every revision.

Expand Down
34 changes: 8 additions & 26 deletions apps/editor/docs/DEVELOPER.md
Original file line number Diff line number Diff line change
Expand Up @@ -47,35 +47,18 @@ Dependencies flow inward: `domain ← application ← infrastructure ← ui`
Editor state uses a **pure reducer** pattern. The reducer and all its helpers have zero React dependencies, which makes them straightforward to test and reason about.

- `state/EditorContext.tsx` — Thin React provider that wires the reducer to hooks. Orchestration only, no business logic.
- `state/editorReducer.ts` — Pure reducer handling all state transitions (selection, CRUD, layout, connect, delete, etc.)
- `state/helpers/nodeGeometry.ts` — Geometry utilities, type guards, graph adjacency builders
- `state/editorFactories.ts` — Factory functions for items, documents, edges, and graph structures
- `state/editorReducer.ts` — Pure reducer handling all state transitions (selection, item edits, adding items, inline alignment edits, graph loading)
- `state/graphTypes.ts` — Editor graph node/edge types and type guards
- `state/editorFactories.ts` — Factory functions for items, documents, and graphs

---

## Layout Algorithms
## Editor Graph Mapping

Three auto-layout modes, all pure functions with no side effects:
The CASE domain model (Framework, Item, Association) is the source of truth. The editor graph that the Tree View and save work from is a derived projection, with no layout:

| Layout | When to use | Edge style |
|--------|------------|-----------|
| **Hierarchy** | Flat lists — many items at one level | smoothstep |
| **Star** | Radial — framework at centre, branches fan out | bezier |
| **Tree** | General purpose — recursive horizontal spread | bezier |

The editor auto-detects which layout suits a framework when no saved positions exist, and applies it *before* the first render (so there's no visible jump).

- `layout/detectTopology.ts` — Classifies the graph shape
- `layout/applyInitialLayout.ts` — Pre-render layout orchestrator

---

## React Flow Mapping

The CASE domain model (Framework, Item, Association) is the source of truth. React Flow is a derived projection:

- `reactflow/mapping/toReactFlow.ts` — Domain → React Flow
- `reactflow/mapping/fromEditorGraph.ts` — React Flow → Domain + layout
- `state/mapping/toEditorGraph.ts` — Domain → editor graph
- `state/mapping/fromEditorGraph.ts` — editor graph → Domain

---

Expand All @@ -85,7 +68,7 @@ The CASE domain model (Framework, Item, Association) is the source of truth. Rea
npm run test
```

The test suite covers all the pure modules — reducer, layout algorithms, geometry helpers, topology detection, and factories. Tests live alongside the code they cover (`*.test.ts`), with shared fixtures in `src/__tests__/fixtures.ts`.
The test suite covers the pure modules — reducer, graph mapping, CASE package mappers, and factories. Tests live alongside the code they cover (`*.test.ts`), with shared fixtures in `src/__tests__/fixtures.ts`.

---

Expand All @@ -94,6 +77,5 @@ The test suite covers all the pure modules — reducer, layout algorithms, geome
- **React 19** + TypeScript
- **Vite** (build + dev server)
- **Tailwind CSS v4** + shadcn/ui
- **@xyflow/react** (React Flow)
- **Vitest** (testing)
- **oidc-client-ts** (authentication)
75 changes: 28 additions & 47 deletions apps/editor/docs/architecture.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,16 +2,15 @@

## What this project is

An **open-source editor for 1EdTech CASE frameworks**. You can create and edit frameworks (CFDocument), items (CFItem), and associations (CFAssociation) through a visual canvas, with a **draft → publish** workflow. It's deliberately focused on core authoring — not trying to replace commercial CASE tools.
An **open-source editor for 1EdTech CASE frameworks**. You can create and edit frameworks (CFDocument), items (CFItem), and associations (CFAssociation) in a Tree View, with a **draft → publish** workflow. It's deliberately focused on core authoring — not trying to replace commercial CASE tools.

Under the hood, the CASE model is treated as a **graph** (items + associations). The canvas you see in the UI is just one way to visualise that graph — the domain model is what matters.
Under the hood, the CASE model is treated as a **graph** (items + associations). The Tree View is one way to show that graph — the domain model is what matters. (An earlier canvas view, built on React Flow, was removed in CGE-165.)

## Tech stack

* React 19 + TypeScript (Vite)
* Tailwind CSS v4
* shadcn/ui components
* React Flow (`@xyflow/react`)
* Vitest (unit testing)
* oidc-client-ts (authentication)

Expand All @@ -23,12 +22,12 @@ These are the principles we don't bend on:

1. **Domain model is the source of truth** — The domain representation of a framework (items + associations) is authoritative.

2. **React Flow is a projection of the domain graph** — React Flow nodes/edges are derived from the domain model. They're not the canonical data.
2. **The editor graph is a projection of the domain model** — the editor's nodes/edges are derived from the domain model. They're not the canonical data.

3. **All user interactions become application commands** — UI events (edit node, add child, connect, delete) must translate to commands handled by the application layer.

4. **Clean architecture dependency direction** — Dependencies always point inward:
* `domain` has no dependencies on React, React Flow, APIs, or storage
* `domain` has no dependencies on React, APIs, or storage
* `application` depends on `domain`
* `infrastructure` implements interfaces defined by `application`
* `ui` depends on `application` (and uses `infrastructure` through composition)
Expand All @@ -37,12 +36,12 @@ These are the principles we don't bend on:

## Folder structure

Pure logic (reducer, layout algorithms, geometry) is isolated from React so it can be tested and reasoned about independently.
Pure logic (reducer, graph mapping) is isolated from React so it can be tested and reasoned about independently.

```
src
├── app
│ ├── App.tsx # App shell — topology detection + pre-render layout
│ ├── App.tsx # App shell — loading, saving, CASE Global targets
│ ├── main.tsx
│ └── providers/

Expand All @@ -62,26 +61,17 @@ src

├── ui
│ ├── editor
│ │ ├── components/ # Canvas, header, dialogs
│ │ ├── reactflow/
│ │ │ ├── nodeTypes/ # CaseItemNode, CaseFrameworkNode
│ │ │ ├── edgeTypes/ # LabeledEdge
│ │ │ ├── mapping/
│ │ │ │ ├── toReactFlow.ts # Domain → React Flow nodes/edges
│ │ │ │ └── fromEditorGraph.ts # React Flow → Domain + layout
│ │ │ └── types.ts # CaseEditorNodeType, CaseEditorEdge, CaseEdgeData
│ │ ├── FrameworkEditor.tsx # Header, Tree View, properties panel, save
│ │ ├── components/ # Header, properties panel, dialogs
│ │ ├── treePanel/ # Tree View and crosswalk (associated frameworks)
│ │ ├── state/
│ │ │ ├── EditorContext.tsx # React provider (orchestration only)
│ │ │ ├── editorReducer.ts # Pure state reducer (no React dependency)
│ │ │ ├── editorFactories.ts # Node/edge factory helpers
│ │ │ └── helpers/
│ │ │ └── nodeGeometry.ts # Pure geometry, type guards, adjacency
│ │ ├── layout/
│ │ │ ├── detectTopology.ts # Classify graph as hierarchy/star/tree
│ │ │ ├── applyInitialLayout.ts # Pre-render layout orchestrator
│ │ │ ├── hierarchyLayout.ts # Flat column layout (smoothstep)
│ │ │ ├── starLayout.ts # Elliptical radial layout (bezier)
│ │ │ └── treeLayout.ts # Recursive tree-spread layout (bezier)
│ │ │ ├── editorFactories.ts # Graph factory helpers
│ │ │ ├── graphTypes.ts # CaseEditorNodeType, CaseEditorEdge, CaseEdgeData
│ │ │ └── mapping/
│ │ │ ├── toEditorGraph.ts # Domain → editor graph
│ │ │ └── fromEditorGraph.ts # Editor graph → Domain
│ │ └── terminology/
│ │ ├── lens.ts
│ │ └── strings.ts
Expand Down Expand Up @@ -110,22 +100,22 @@ We treat CASE as a **graph**:
* `Association` = edge (`CFAssociation`)
* `Framework` = aggregate root owning items + associations (`CFDocument` + supporting structures)

The domain model has no knowledge of React Flow, the UI, or any external system.
The domain model has no knowledge of the UI or any external system.

---

## Domain ↔ React Flow mapping
## Domain ↔ editor graph mapping

This is the most important boundary in the codebase. The mapping code is intentionally centralised in two files:

* `src/ui/editor/reactflow/mapping/toReactFlow.ts` — Domain → React Flow
* `src/ui/editor/reactflow/mapping/fromEditorGraph.ts` — React Flow → Domain
* `src/ui/editor/state/mapping/toEditorGraph.ts` — Domain → editor graph
* `src/ui/editor/state/mapping/fromEditorGraph.ts` — editor graph → Domain

**How it works:**

1. **Domain → React Flow is derived** — React Flow nodes/edges are built from the domain `Framework` (Item → Node, Association → Edge).
2. **UI changes become commands** — When a user drags, edits, or connects something, the UI translates that into an application command. The command updates the domain model, and the UI re-renders by re-projecting the domain.
3. **Layout is separate** — Positions (x, y) are a UI concern. They're stored in UI state, not in domain entities.
1. **Domain → graph is derived** — the editor's nodes/edges are built from the domain `Framework` (Item → Node, Association → Edge).
2. **UI changes become commands** — When a user edits or adds something, the UI dispatches a reducer action; saving rebuilds the domain `Framework` from the graph.
3. **No layout** — nodes carry no positions. Saves no longer write the canvas-era `ext:opencase` layout, edge style, or remote-link data, and drop it where a loaded framework had it.

---

Expand All @@ -135,21 +125,12 @@ Editor state uses a **pure reducer** pattern, cleanly separated from React:

### Pure modules (no React dependency)

* **`state/editorReducer.ts`** — A single pure function that handles all state transitions: selection, CRUD, layout, connections, graph loading, etc.
* **`state/helpers/nodeGeometry.ts`** — Geometry utilities (sizing, handles, overlap detection), type guards, and graph adjacency builders.
* **`state/editorFactories.ts`** — Factory functions for items, documents, edges, and graph structures.

### Layout algorithms (also pure)

* **`layout/detectTopology.ts`** — Looks at a graph's shape and classifies it as `hierarchy`, `star`, or `tree`.
* **`layout/hierarchyLayout.ts`** — Vertical column: framework at top, items stacked below. Smoothstep edges.
* **`layout/starLayout.ts`** — Radial: framework at centre, branches fan out in angular sectors. Bezier edges.
* **`layout/treeLayout.ts`** — Recursive horizontal tree-spread. Bezier edges.
* **`layout/applyInitialLayout.ts`** — Pre-render orchestrator. Detects topology and applies layout *before* the first React Flow render, so there's no visible jump.
* **`state/editorReducer.ts`** — A single pure function that handles all state transitions: selection, item edits, adding items, inline alignment edits, graph loading.
* **`state/editorFactories.ts`** — Factory functions for items, documents, and graphs.

### React orchestration

* **`state/EditorContext.tsx`** — A thin React provider. It imports the reducer and layout functions, wires them up with hooks, and exposes the `EditorContext` API. Business logic stays out.
* **`state/EditorContext.tsx`** — A thin React provider. It wires the reducer up with hooks and exposes the `EditorContext` API. Business logic stays out.

---

Expand Down Expand Up @@ -178,7 +159,7 @@ Implements the interfaces defined in `application/ports`:

## UI layer

* Renders the canvas editor (React Flow)
* Renders the framework in the Tree View
* Provides panels and dialogs for editing properties
* Translates UI events → commands
* Shows draft status and the explicit publishing flow
Expand Down Expand Up @@ -219,7 +200,7 @@ npm run test # Single run
npm run test:watch # Watch mode
```

If you're adding a new reducer action or layout algorithm, please add tests to go with it.
If you're adding a new reducer action, please add tests to go with it.

---

Expand All @@ -233,8 +214,8 @@ Where to put things:
* **External integrations** → `infrastructure/`

If you're working on **nodes/edges**:
* Change components in `ui/editor/reactflow/*`
* Keep mapping logic in `mapping/*`
* Change the graph types in `ui/editor/state/graphTypes.ts`
* Keep mapping logic in `ui/editor/state/mapping/*`

If you're adding **state logic**:
* Add new actions to the `Action` union in `editorReducer.ts`
Expand Down
8 changes: 4 additions & 4 deletions apps/editor/docs/associations.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# Associations: import, display and authoring

How the editor and server handle a framework's associations: what gets imported, where associations are stored, how the Tree View shows and edits them, and what happens on save. The canvas view is disabled and is not covered here.
How the editor and server handle a framework's associations: what gets imported, where associations are stored, how the Tree View shows and edits them, and what happens on save.

---

Expand Down Expand Up @@ -103,9 +103,9 @@ Import order matters for hosted vs remote. When imported frameworks link to each

## Loading into the editor

The editor state (`EditorContext`, `editorReducer`) holds a framework as nodes (items and the document) and edges (associations between them). Only associations with **both ends in the framework** become edges. Associations to anything else, including every external association, have no edge. `withOffCanvasAssociations` carries them over from the framework as loaded when the editor saves, so they aren't lost.
The editor state (`EditorContext`, `editorReducer`) holds a framework as nodes (items and the document) and edges (associations between them). Only associations with **both ends in the framework** become edges. Associations to anything else, including every external association, have no edge. `withOffCanvasAssociations` carries them over from the framework as loaded when the editor saves, so they aren't lost. That includes links the former canvas view drew to CASE Global frameworks (`ext:opencase.remoteLink`); a save keeps them but drops the canvas's handle positions from their `ext:opencase`, along with the document's and items' layout, edge style, and `linkedFrameworks`/`remoteItemLinks`.

Edges keep their association's stored node titles (`toReactFlow` → `fromEditorGraph`), so a save writes back the titles that were loaded.
Edges keep their association's stored node titles (`toEditorGraph` → `fromEditorGraph`), so a save writes back the titles that were loaded.

---

Expand Down Expand Up @@ -208,7 +208,7 @@ Associations interact with forking in four ways:
| Alignment framework shape, ownership, merge, fork remap | `src/domain/framework/alignmentFrameworks.ts` |
| Inline edits made in the Tree View | `src/domain/framework/inlineAlignmentEdits.ts`, `editorReducer` (`inlineAlignment/*`) |
| Moving associations on save | `src/application/framework/services/AlignmentStorage.ts` |
| Saving, plan before fork warning | `src/ui/editor/EditorCanvas.tsx` (`handleSave`, `doSave`), `src/app/App.tsx` (`handleSaveToServer`) |
| Saving, plan before fork warning | `src/ui/editor/FrameworkEditor.tsx` (`handleSave`, `doSave`), `src/app/App.tsx` (`handleSaveToServer`) |
| Data-change detection (editor) | `src/domain/framework/hasFrameworkDataChanged.ts` |
| Associations without an edge | `src/domain/framework/offCanvasAssociations.ts` |
| Association export, node titles | `src/application/framework/mappers/case/toCasePackage.ts` |
Expand Down
2 changes: 2 additions & 0 deletions apps/editor/docs/design.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
# Project Context: CASE Framework Editor

> Historical design notes. The React Flow canvas described below was removed in CGE-165; the editor now uses the Tree View only. See [architecture.md](architecture.md) for the current structure.

## What this project is

This project is an **editor for CASE frameworks**, built as an **open-source reference implementation**.
Expand Down
Loading
Loading