Dendron Engine Architecture
Entry
Lifecycle
Init
init {
	store.init
}
Init Notes in Store
init {
  @initNotes
}
initNotes {
  notesWithLinks = []
  // loop through all vaults
  @vaults.forEach vault => {
    // read all notes from disk
    notes = @_initNotes(vault)
    // if notes have links, add it to notesWithLinks array
    notesWithLinks.push filterLinks(notes)
  }
  // calculate backlinks based on all notes with links
  @_addBacklinks(notesWithLink)
}
Details of _initNotes
_initNotes(vault) {
  noteFiles := getAllFiles(vault)
	parser = new NoteParser
	notes = parser.parse(noteFiles)
  cache = readNotesFromCache(vault)
  {notes, cacheUpdates} = new NoteParser(cache).parseFiles(noteFiles)
  notes.map n => {
    return if n.stub 
    return if n.body.length > DENDRON_DEFAULT_MAX_NOTE_LENGTH
    if has(cacheUpdates, n) {
      // update all links and anchors if cache is different [[../packages/engine-server/src/drivers/file/storev2.ts#^link-anchor]]
      links = findLinks
      cacheUpdates[n].data.links = links
      n.links = links
    } else {
      // update links from cache
      n.lnks = cacheUpdates[n].data.links
    }
  }
  return { notes, cacheUpdates, cache, errors }
}
parseFiles(allPaths) {
  fileMetaDict := allPaths
  root = fileMetaDict[1].find(n => n.fpath === "root.md") as FileMeta;
  ...
  lvl = 2
  prevNotes = fileMetaDict[1]
  prevNotes.flatMap(ent) {
    // see [[Arch|dendron://dendron.docs/pkg.dendron-engine.t.engine.arch#^45PEWoYX9mr8]]
    out = parseNoteProps(ent)
  }
}
Common
The following are referenced by other blocks in this note
parseNoteProps
parseNoteProps(notePath) {
  file2NoteWithCache(notePath, @cache)
}
file2NoteWithCache(notePath, cache) {
  name := notePath
  content = read(notePath)
  sig = hash(content)
  if(sig in cache) {
    body := content
    note = {
      ...cache.notes[name],
      body,
      vault
    }
    return note
  }
  string2Note
}
string2Note(content) {
  data, body = matter(contents)
  note :=
  return note
}
Add backlinks
_addBacklinks {
  @_addBacklinksImpl
}
_addBacklinksImpl(allNotes, notesWithLinks) {
  notesWithLinks.forEach noteFrom => {
    // noteFrom is where the link is originating from
    noteFrom.links.forEach link => {
      // get note that link is pointing to
      fnameTo = link.to.fname
      // all notes that this points to (if the note doesn't have xvault link, the same note name might exist in multiple vaults)
      notes := fnameTo
      // for all notes that this link is a backlink to, add it as a backlink for that note
      notes.forEach noteTo => {
        addBacklink(noteFrom, noteTo, link)
      }
    }
  }
}
addBacklink(from: Note, to: Note) {
  to.links.push(...)
}
Cook
Past Tasks
Backlinks