log4brains

repository·develop·Indexed 23 days ago

https://github.com/thomvaill/log4brains

A docs-as-code knowledge base for managing Architecture Decision Records (ADRs). It allows developers to write decisions in Markdown within Git repositories and automatically publish them as a searchable, interactive static website. Features include a global CLI for initialization and ADR creation, a local preview mode with Hot Reloading, and support for publishing to GitHub Pages, GitLab Pages, and AWS S3. It utilizes a patched version of the MADR 2.1.2 format and provides a core library (@log4brains/core) for custom integrations.

Tokens
15.7K
Snippets
32
Records
111
Agent score
78%

What's inside log4brains

  1. What is an ADR and why use them

    develop

    An Architectural Decision (AD) is a software design choice addressing significant functional or non-functional requirements. An Architectural Decision Record (ADR) captures a single AD. A collection of these records forms a project's decision log.

    Key characteristics and benefits of ADRs:

    • Immutability: ADRs are immutable; only their status (e.g., becoming deprecated or superseded) should change. This allows teams to read the decision log chronologically to understand project history.
    • Onboarding: Speeds up the onboarding process for new team members.
    • Context Preservation: Prevents the blind acceptance or reversal of past decisions by providing the original rationale.
    • Formalization: Formalizes the team's decision-making process.
  2. Manage ADRs in multi-package projects

    develop

    Log4brains supports different project structures for managing Architecture Decision Records (ADRs):

    Mono-repository (Multi-package)

    Install Log4brains in the root folder. It can manage both "global ADRs" (located in the root docs/adr) and "package-specific ADRs" (located within individual package directories like packages/<package name>/docs/adr).

    One repository per package

    Currently, all ADRs must be stored in a central repository. You can organize them by creating subdirectories within the central ADR folder for each package (e.g., adr/package1/, adr/package2/).

  3. Avoid using React.FC or React.SFC types

    develop

    When writing new React components in the Log4brains codebase, avoid using the React.FC (or React.SFC) type. These types are considered unnecessary and introduce downsides, such as implicitly adding children props and failing to support generic types on children.

    Instead, define your component as a standard function and explicitly include children in your props type definition if needed.

    /* Avoid this: */
    type BadProps = { text: string };
    const BadComponent: FC<BadProps> = ({ text, children }) => (
      <div>
        <div>{text}</div>
        {children}
      </div>
    );
    
    /* Do this instead: */
    type GoodProps = { text: string; children?: React.ReactNode };
    const GoodComponent = ({ text, children }: GoodProps) => (
      <div>
        <div>{text}</div>
        {children}
      </div>
    );
  4. ADR filename format and unique identification

    develop

    Log4brains identifies Architecture Decision Records (ADRs) by their filename slug (the filename without the extension) rather than an incremental number. To ensure uniqueness and prevent git merge conflicts, use the following filename format:

    YYYYMMDD-adr-title.md

    Where YYYYMMDD is the date of creation. This format allows files to remain correctly sorted in IDEs while avoiding the collisions common with incremental numbering.

    YYYYMMDD-adr-title.md
  5. How Markdown parsing is handled in Log4brains

    develop

    In Log4brains, Markdown parsing is treated as part of the core domain logic rather than a technical infrastructure detail. This design choice allows the system to perform 'smart' parsing of ADRs (Architecture Decision Records) without requiring a rigid, predefined structure.

    Because parsing is part of the domain, the logic used to interpret Markdown content is central to the application's business rules and is subject to comprehensive testing. Note that this means the core logic is tightly coupled to the Markdown format, making it difficult to switch to a different document format (like JSON or AsciiDoc) in the future.

  6. How ADRs are sorted

    develop

    The Log4brains core library handles the sorting of ADRs. When displaying or processing records, they are sorted according to the following priority rules:

    1. Date field: The date specified within the markdown file's frontmatter (if present).
    2. Git creation date: The date the file was created in Git (this does not follow renames).
    3. File creation date: The filesystem creation date if no versioning information is available.
    4. Slug: The filename slug (alphabetical/chronological based on the date prefix).
  7. Understand the MADR format with Log4brains patch

    develop

    Log4brains uses a patched version of the MADR (Markdown Architectural Decision Records) 2.1.2 format. This format is designed to be lean and easy to maintain while ensuring architectural decisions are documented clearly.

    Compared to the original MADR specification, the Log4brains patch introduces three specific modifications to better suit collaborative development:

    1. Filename Format: Instead of the standard NNN-adr-name (numeric prefix), Log4brains uses YYYYMMDD-adr-name (date prefix) to reduce merge conflicts in Git.
    2. Draft Status: Adds a draft status to allow for collaborative writing before a decision is finalized.
    3. Tags Field: Adds a Tags field to the frontmatter for better categorization.

    An ADR should typically include the following sections:

    • Context and Problem Statement: The background and the problem being addressed.
    • Considered Options: A list of potential solutions or approaches.
    • Decision Outcome: The chosen option and the rationale behind it.
    • Links: References to related documents or external resources.
  8. Understand the two modes of Log4brains

    develop

    Log4brains operates in two distinct modes to support the lifecycle of Architecture Decision Records (ADRs):

    1. Edit Mode: Used by developers to edit ADRs via a web UI or directly in an IDE. This mode is served locally and supports live-reloading when markdown files are modified. It is typically started with npm run log4brains.
    2. Build Mode: Used to generate a static site from the ADRs, ready for deployment to hosting services like GitHub Pages. This mode is typically executed by a CI/CD pipeline using npm run log4brains-build.

    The project uses Next.js as the underlying framework to ensure code reusability between these two modes and to provide high extensibility via TypeScript.

  9. Structure a Log4brains ADR file

    develop

    When creating a new Architectural Decision Record (ADR) in Log4brains, use the following Markdown structure. Note that the filename must follow the YYYYMMDD-adr-name.md pattern.

    # {Title}
    
    - Status: {accepted|draft|superseded|deprecated}
    - Date: {YYYY-MM-DD}
    - Tags: {tag1, tag2}
    
    ## Context and Problem Statement
    
    {Describe the context and the problem being addressed.}
    
    ## Considered Options
    
    - [Option 1]
    - [Option 2]
    
    ## Decision Outcome
    
    Chosen option: "{Option Name}", because
    
    - {Reason 1}
    - {Reason 2}
    
    ## Links
    
    - Relates to [{Link Text}]({SLUG}.md)
    # Use Markdown Architectural Decision Records
    
    - Status: accepted
    - Date: {DATE_YESTERDAY}
    - Tags: doc
    
    ## Context and Problem Statement
    
    We want to record architectural decisions made in this project.
    Which format and structure should these records follow?
    
    ## Considered Options
    
    - [MADR](https://adr.github.io/madr/) 2.1.2 with Log4brains patch
    - [MADR](https://adr.github.io/madr/) 2.1.2 – The original Markdown Architectural Decision Records
    - [Michael Nygard's template](http://thinkrelevance.com/blog/2011/11/15/documenting-architecture-decisions) – The first incarnation of the term "ADR"
    - [Sustainable Architectural Decisions](https://www.infoq.com/articles/sustainable-architectural-design-decisions) – The Y-Statements
    - Other templates listed at <https://github.com/joelparkerhenderson/architecture_decision_record>
    - Formless – No conventions for file format and structure
    
    ## Decision Outcome
    
    Chosen option: "MADR 2.1.2 with Log4brains patch", because
    
    - Implicit assumptions should be made explicit.
      Design documentation is important to enable people understanding the decisions later on.
      See also [A rational design process: How and why to fake it](https://doi.org/10.1109/TSE.1986.6312940).
    - The MADR format is lean and fits our development style.
    - The MADR structure is comprehensible and facilitates usage & maintenance.
    - The MADR project is vivid.
    - Version 2.1.2 is the latest one available when starting to document ADRs.
    - The Log4brains patch adds more features, like tags.
    
    ## Links
    
    - Relates to [Use Log4brains to manage the ADRs]({LOG4BRAINS_ADR_SLUG}.md)
  10. Install and initialize Log4brains

    develop

    To start using Log4brains in your project, install the CLI globally and run the initialization command in your project's root directory. The init command will guide you through configuration, create necessary template files, and generate your first ADR.

    Note: If you want to use the latest beta version, use log4brains@beta during installation.

    npm install -g log4brains
    log4brains init
  11. Publish to GitHub Pages with GitHub Actions

    develop

    You can automatically publish your knowledge base to GitHub Pages. This requires setting fetch-depth: 0 in your checkout step so Log4brains can access the full Git history.

    After the first deployment, you must create a .nojekyll file in your gh-pages branch to prevent GitHub from using Jekyll, which would cause 404 errors for the static site.

    Workflow steps:

    1. Create .github/workflows/publish-log4brains.yml.
    2. Use log4brains build --basePath /${GITHUB_REPOSITORY#*/}/log4brains.
    3. Deploy the contents of .log4brains/out to the gh-pages branch.
    4. Add a .nojekyll file to the gh-pages branch.
    5. Configure GitHub Pages settings to use the gh-pages branch and the / (root) folder.
    name: Publish Log4brains
    on:
      push:
        branches:
          - main
    jobs:
      build-and-publish:
        runs-on: ubuntu-latest
        steps:
          - uses: actions/checkout@v4
            with:
              persist-credentials: false
              fetch-depth: 0
          - uses: actions/setup-node@v4
            with:
              node-version: lts/*
          - name: Install and Build Log4brains
            run: |
              npm install -g log4brains
              log4brains build --basePath /${GITHUB_REPOSITORY#*/}/log4brains
          - name: Deploy
            uses: JamesIves/github-pages-deploy-action@3.7.1
            with:
              GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
              BRANCH: gh-pages
              FOLDER: .log4brains/out
              TARGET_FOLDER: log4brains
  12. Check Log4brains prerequisites

    develop

    Before installing Log4brains, ensure your environment meets the following requirements:

    • Node.js: An active or maintenance LTS version. Versions outside this range are not guaranteed to work; the 'current' version is supported on a best-effort basis.
    • Package Manager: NPM or Yarn.
    • Git: Required for version control integration.

    Log4brains is designed to work with any project type, not just JavaScript/TypeScript projects, though it requires Node and NPM to be installed globally to run.