Search by

adachsoft / project-map

Arkadiusz Adach

Hierarchical project map domain library for context discovery

Package info

gitlab.com/a.adach/project-map

Issues

pkg:composer/adachsoft/project-map

Statistics

Installs: 18

Dependents: 1

Suggesters: 0

Stars: 0

v0.1.0 2026-11-27 20:55 UTC

This package is auto-updated.

Last update: 2026-11-27 19:56:04 UTC


README

adachsoft/project-map is a framework-agnostic PHP library that stores a hierarchical project map as a set of JSON documents. The map describes the project as a graph of significant areas of responsibility and data flows (maps and nodes) instead of a plain file listing, so tools and agents can discover relevant context, validate references to existing paths and keep the description in sync with the repository.

Purpose

A project map is a small, versioned JSON document tree kept inside the project (by default in docs/project-map):

  • index.json is the root map that links to the other maps,
  • every other map groups nodes that belong to one area of responsibility,
  • every node points to a project-relative path and explains its role.

The library provides the domain model, the persistence port and a ready-to-use JSON file adapter, together with a node authoring policy and path validation.

Main capabilities

  • Hierarchical maps – maps are addressed by a slug identifier and linked from the index map.
  • Node upsert and removal – nodes are added, replaced by identifier or removed without touching other entries.
  • Lazy map creation – writing a node to a non-existing map creates the map and links it from the index.
  • Authoring policy – node descriptions must be non-empty and bounded in length, must not contain task identifiers, and their paths must exist in the project; files are only accepted for CONFIG, DOCUMENTATION and MAP node types.
  • Path validation – every map or all maps can be validated against the project filesystem in one call.
  • Typed model – immutable DTOs, value objects, an enum of node types and a dedicated exception hierarchy.
  • Swappable infrastructure – storage and path validation are ports (Spi), so JSON files or the local filesystem can be replaced by another adapter without changing the service.

Requirements

  • PHP 8.3 or newer
  • adachsoft/collection (installed automatically)

Installation

composer require adachsoft/project-map

Integration

The library is created through a factory that wires the default adapters:

<?php

declare(strict_types=1);

use AdachSoft\ProjectMap\Dto\ProjectMapNodeDto;
use AdachSoft\ProjectMap\Enum\NodeTypeEnum;
use AdachSoft\ProjectMap\Factory\ProjectMapServiceFactory;
use AdachSoft\ProjectMap\Vo\MapIdVo;
use AdachSoft\ProjectMap\Vo\NodeIdVo;
use AdachSoft\ProjectMap\Vo\RelativePathVo;

$projectMapService = ProjectMapServiceFactory::create(
    projectBasePath: __DIR__,                 // absolute project root
    mapsRelativeDirectory: 'docs/project-map', // maps storage, relative to the root
    maxDescriptionLength: 400,                 // node description limit
);

$projectMapService->upsertNode(
    new MapIdVo('domain'),
    new ProjectMapNodeDto(
        new NodeIdVo('project-map-service'),
        NodeTypeEnum::COMPONENT,
        'Project map service',
        new RelativePathVo('src/Service'),
        'Application service that coordinates project map operations.',
    ),
    'Domain',
    'Domain layer of the project.',
);

$index = $projectMapService->readIndex();
$validation = $projectMapService->validateAll();

Every operation is available through ProjectMapServiceInterface:

  • getSummary() – whether the index map exists, its relative path and the number of available maps,
  • readIndex() / readMap(MapIdVo $mapIdVo) – read a map,
  • upsertNode(...) – add or replace a node (and create the target map when needed),
  • removeNode(MapIdVo $mapIdVo, NodeIdVo $nodeIdVo) – remove a node from a map,
  • validateMap(MapIdVo $mapIdVo) / validateAll() – validate node paths against the project filesystem.

Custom infrastructure

ProjectMapServiceFactory returns the service with the JSON file repository and the filesystem validator. To store maps elsewhere or to validate paths differently, implement AdachSoft\ProjectMap\Spi\ProjectMapRepositoryInterface and/or AdachSoft\ProjectMap\Spi\ProjectMapFileValidatorInterface and pass them to AdachSoft\ProjectMap\Service\ProjectMapService together with a AdachSoft\ProjectMap\Service\ProjectMapNodePolicy instance.

Map format

Each map is stored as a pretty-printed JSON object:

{
  "format": "project-map",
  "version": "1.0",
  "id": "index",
  "title": "Index",
  "description": "",
  "nodes": [
    {
      "id": "domain",
      "type": "MAP",
      "title": "Domain",
      "path": "docs/project-map/domain.json",
      "description": "Domain layer of the project.",
      "map_path": null
    }
  ]
}

Available node types: MAP, MODULE, CONFIG, COMPONENT, TESTS, DIRECTORY, DOCUMENTATION.

Examples

See docs/examples for complete usage scenarios.