Future Prospect
Of course. Here is a detailed explanation of how the Akoma Ntoso format is leveraged for versioning documents in your project, breaking down the technical logic and connecting it to your codebase and architecture.
The Core Principle: Stable Identifiers in Akoma Ntoso
The entire versioning system hinges on a core concept from Akoma Ntoso: the use of stable, unique identifiers for every structural part of the document. In your structured JSON files, this is represented by the @eId (element identifier) field.
Example from chapter6_akoma_ntoso.json:
JSON
"section": [
{
"@eId": "sec_97",
"num": "97.",
"heading": "Appointment to certain posts...",
"content": [ ... ]
},
{
"@eId": "sec_98",
"num": "98.",
"heading": "Appointment of Engineer, Health Officer etc.-",
"content": [ ... ]
}
]Think of @eId: "sec_97" as a permanent address for Section 97. No matter how many amendments are made—even if sections are added before it, causing its page number to change—its unique identifier, sec_97, remains the same.
This is the key that allows a machine to reliably track a specific piece of text across different versions of the document.
The Detailed Versioning and Diffing Workflow
The diagram you provided outlines a sophisticated version control engine. Your current codebase in page.tsx simulates this engine on the frontend. Here’s how the Akoma Ntoso structure fits into this workflow, step-by-step.
Step 1: Establishing the Base Version (The "First Commit")
Logic: The initial, original text of the BBMP Act is converted into the Akoma Ntoso JSON format. This structured file (e.g.,
chapter7_akoma_ntoso.json) becomes our base version, or "v1.0". Every element within it has a unique@eId.In Your Code: The HTML generated from this base JSON is stored in the
chapterVII_v1Contentconstant insrc/app/page.tsx. This string represents the foundational state of the document upon which all future changes will be applied.
Step 2: Processing Amendments
Logic: An amendment is essentially a set of instructions for changing the base document. For example, an amendment might say, "In Section 106, Sub-section 1, replace the phrase 'municipal governance of Bengaluru' with 'municipal governance and administration of Bengaluru'."
In Your Code: The amendments are stored as separate HTML snippets like
chapterVII_amend1Content. In the current frontend-only implementation, the "instructions" are implicitly coded into theapplyAmend...functions. For example, the instruction to change Section 106 is hardcoded in theapplyAmend1VIIfunction.
Step 3: Generating a New Version by Applying Changes
Logic: To create a new version (e.g., "v2.0"), a "Diff Engine" (as shown in your diagram) would programmatically apply the amendment's changes to the base version. Because every section and sub-section has a stable
@eId, the engine can precisely locate where to apply the change, regardless of other modifications.In Your Code: Your
applyAmend...functions insrc/app/page.tsxsimulate this diff engine. They take the HTML string of a previous version and use JavaScript'sreplace()method to find and alter the text.Code Snippet (
src/app/page.tsx):JavaScript
function applyAmend1VII(original: string, addDiff: boolean = true) { let amended = original; const delStart = addDiff ? '<del style="...">' : ""; const delEnd = addDiff ? "</del>" : ""; const insStart = addDiff ? '<ins style="...">' : ""; const insEnd = addDiff ? "</ins>" : ""; // The function targets specific text within the document to apply changes amended = amended.replace( "municipal governance of Bengaluru", `${delStart}municipal governance of Bengaluru${delEnd}${insStart}municipal governance and administration of Bengaluru${insEnd}` ); // ... more replacements ... return amended; }While this code operates on a simple string, it's a direct simulation of a more robust process that would target the content associated with a specific
@eIdin the Akoma Ntoso JSON.
Step 4: Creating the Visual Diff with <ins> and <del>
Logic: The core of displaying the version differences is to wrap the original text in
<del>tags (deletions) and the new text in<ins>tags (insertions). The browser then renders these with distinct styling (red for deletions, green for insertions), as defined in your CSS and the inline styles inpage.tsx.In Your Code and UI: This is exactly what the
applyAmend...functions do. They construct the final HTML string with these tags. The result is what you see in the screenshot: the document viewer displays the text with color-coded highlights, making the changes immediately obvious to the user.
Step 5: Managing the Timeline and Different Diff Views
Logic: The application needs to manage multiple versions and display diffs either cumulatively (all changes from v1) or incrementally (changes from the previous version). The structured nature of Akoma Ntoso makes this manageable. A backend could store each version as a complete Akoma Ntoso document.
In Your Code: The
computeVersionsfunction insrc/app/page.tsxmanages this logic.For cumulative diffs, it chains the
applyAmend...functions. To generatev3, it first generatesv2(with diffs) and then applies the third amendment to that result.For incremental diffs, it applies changes to a "clean" version of the previous state. To show the diff for
v3, it first generates the plain text ofv2(by callingapplyAmend1VIIwithaddDiff: false) and then applies theapplyAmend2VIIfunction to that clean text.
How Akoma Ntoso Enables a Scalable Backend Architecture
While your current implementation cleverly simulates the process on the frontend, the Akoma Ntoso format is designed for a more robust backend, as envisioned in your architecture diagram.
Here’s how it would work in that ideal scenario:
Version Storage: Instead of storing HTML strings, a database would store each version of the act as a complete Akoma Ntoso JSON object.
The Diff Engine: When a user wants to compare two versions (e.g., v1 and v2), the backend "Diff Engine" would:
Fetch the two corresponding Akoma Ntoso JSON objects from the database.
Traverse both JSON trees simultaneously.
For each element with the same
@eId(e.g.,sec_106), it would compare theircontent.If the content differs, it would generate the appropriate HTML with
<ins>and<del>tags.
Sending to Frontend: The backend would then send the pre-processed, diff-ready HTML to the Next.js frontend, which would simply render it using
dangerouslySetInnerHTML.
This backend approach is more scalable and less prone to errors than frontend string replacement, and it's all made possible by the stable identifiers and clear hierarchy provided by the Akoma Ntoso format.
Last updated