How base/chains works
Project Type and Purpose
• It is organized as a collection of Gradle sub-projects:
• model: defines domain objects (Chain, Explorer, NativeCurrency)
• processor: validates JSON files against the domain model and constraints, then composes aggregate outputs
• tools: Node.js scripts for ancillary tasks (schema checking, cleanup)
• website (static site not shown but implied by directory)
File Structure Analysis
• Top-level directories:
• httpsloader, model, processor: three Kotlin/Gradle modules following a pipeline
• tools: Node.js utility scripts and JSON schemas
• ci/.github: CI/CD configuration (GitHub Actions)
• gradle/…: build system
• The processor module contains:
• src/main: core validation and aggregation logic
• src/test: unit tests covering invalid and valid scenarios
• README specifies constraints, example JSON, aggregation outputs, and usage contexts
• CI pipelines run ‘./gradlew run’, schema checks, formatting, and on success deploy outputs
Main Components and Their Interactions
a. Data Sources (raw):
• _data/chains/*.json – individual chain definitions
b. HTTPS/IPFS Loader (httpsloader):
• Ensures that assets are reachable and cached if necessary
c. Domain Model (model):
• Kotlin data classes: Chain, Explorer, NativeCurrency
• Shared by loader and processor for serialization/deserialization
d. Processor (processor):
• Reads raw JSON via model
• Emits aggregate JSON outputs: chains.json, chains_mini.json
• Runs unit tests to guard invalid cases
e. Tools (Node scripts + schemas):
• schema/chainSchema.json – formal JSON Schema definitions
• schemaCheck.js – validates files against schema before Gradle tasks
• rmNetwork.js, package.json – other maintenance tasks
f. CI/CD (GitHub Actions):
• build.yml – compiles modules, runs validation
• deploy.yml – publishes aggregated outputs to chainid.network or npm
• pr_checks.yml, prettier.yml, validate_json.yml – maintain quality
Architectural Patterns and Principles
• Modular architecture: clear separation into “loader”, “domain model”, “processor”, and “tools”
• Pipeline pattern: raw data → loader → model → processor → published outputs
• Test-driven validation: exhaustive unit tests for invalid/legal cases in processor
• CI-oriented: automated checks and deployment on each PR
• Data-centric: focus on JSON schemas and domain integrity
Essential Elements
• Data ingestion (raw JSON → modules)
• Validation loops (processor ↔ tests; tools ↔ schema)
• Deployment (processor → published outputs → consumers)