Skip to content

feat(contracts): implement contract dependency tracker module (#151) - #163

Merged
mijinummi merged 2 commits into
MD-Creative-Production:mainfrom
Topmatrixmor2014:feat/contract-dependency-tracker-151
Jun 17, 2026
Merged

feat(contracts): implement contract dependency tracker module (#151)#163
mijinummi merged 2 commits into
MD-Creative-Production:mainfrom
Topmatrixmor2014:feat/contract-dependency-tracker-151

Conversation

@Topmatrixmor2014

Copy link
Copy Markdown
Contributor

Summary

Implements the Contract Dependency Tracker module as requested in issue #151.

What was implemented

New module: apps/backend/src/modules/contracts/dependencies/

File Purpose
interfaces/dependency-tracker.interface.ts RiskLevel, ContractNode, ContractDependency, DependencyGraph, RegisterContractDto, AddDependencyDto
dependency-tracker.service.ts Core business logic — register contracts, link dependencies, traverse graph, propagate risk
dependency-tracker.controller.ts REST endpoints (see below)
dependency-tracker.module.ts NestJS module wiring
dependency-tracker.service.spec.ts 20 unit tests

REST endpoints

POST /contracts/dependencies/register        — register a contract node
POST /contracts/dependencies                 — add a dependency edge
GET  /contracts/dependencies                 — list all registered contracts
GET  /contracts/dependencies/graph/:address  — full dependency graph with risk propagation

Key technical decisions

  • Risk propagation: Five-level ordinal scale (none → low → medium → high → critical). getGraph reduces across all nodes + edges and surfaces the maximum.
  • Cycle-safe BFS traversal: visited-set prevents infinite loops in circular dependency graphs.
  • In-memory store: Uses a Map<chain:address, ContractNode> keyed on lowercase address+chain, trivially swappable for a DB repository.
  • Address case-insensitivity: Keys normalised to lowercase, matching EVM convention.

Acceptance criteria

  • Dependencies mapped — registerContract + addDependency
  • Relationships visualised — getGraph returns full node list + adjacency
  • Risks correlated — propagatedRisk field surfaces worst-case risk in the subgraph

Testing

npm run test:backend   # 28/28 tests pass across 2 suites
npm run lint           # clean
npm run format:check   # clean

Closes #151

…ative-Production#151)

- add DependencyTrackerModule under src/modules/contracts/dependencies/
- add ContractNode, DependencyGraph, RiskLevel interfaces
- add DependencyTrackerService: registerContract, addDependency, getGraph
  (cycle-safe BFS traversal) and getAll with in-memory store
- add DependencyTrackerController exposing REST endpoints:
    POST /contracts/dependencies/register
    POST /contracts/dependencies
    GET  /contracts/dependencies
    GET  /contracts/dependencies/graph/:address?chain=
- add 20 unit tests covering happy paths, ConflictException,
  NotFoundException, risk propagation, and cycle-safety
- register module in AppModule

Closes MD-Creative-Production#151
@mijinummi

Copy link
Copy Markdown
Collaborator

Hi @Topmatrixmor2014 , well done for this effort, please kindly fix [Code Quality & Security / TypeScript Type Checking Failing

- add 'jest' to tsconfig.json types array so tsc --noEmit resolves
  jest globals in spec files (fixes TypeScript type checking CI job)
- enable build:backend in Dockerfile builder stage (was commented out)
- fix COPY path from /app/src to /app/apps/backend/dist
- fix CMD entrypoint to dist/apps/backend/src/main.js
  (fixes Docker Build Check CI job)
@Topmatrixmor2014

Topmatrixmor2014 commented Jun 17, 2026 via email

Copy link
Copy Markdown
Contributor Author

@Topmatrixmor2014
Topmatrixmor2014 force-pushed the feat/contract-dependency-tracker-151 branch from 5886d38 to 24ab11c Compare June 17, 2026 16:57
@mijinummi

Copy link
Copy Markdown
Collaborator

LGTM!

@mijinummi
mijinummi merged commit 1d59e5c into MD-Creative-Production:main Jun 17, 2026
18 of 22 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

🧩 Create Contract Dependency Tracker #

2 participants