Skip to main content

Modular Architecture

This document serves as the master index and architectural overview for the modular bearflare.sh codebase.

Module Hierarchy Overview

The bearflare.sh codebase has been modularized into 8 distinct module directories under src/lib/:

Module DirectoryPurposeCategory
utils/Core utilities and timing helpers (foundation layer)Foundation
logging/Logging system with rotation and ANSI strippingInfrastructure
config/Configuration loading with priority systemInfrastructure
cli/Command-line argument parsing and validationInterface
bear/Bear.app database operations (validation, schema, data)Domain
cloudflare/d1/Cloudflare D1 API integration (api, sync)Domain
data/Data batching and SQL transformationsDomain
sync/High-level sync orchestration (schema, data, validation)Orchestration

Architecture Diagram

graph TD
subgraph Foundation
UC[utils/core.sh]
UT[utils/timing.sh]
end

subgraph Infrastructure
LOG[logging/logger.sh]
CL[config/loader.sh]
CV[config/validator.sh]
end

subgraph Interface
CH[cli/help.sh]
CP[cli/parser.sh]
CVL[cli/validator.sh]
end

subgraph Domain
BV[bear/validation.sh]
BS[bear/schema.sh]
BD[bear/data.sh]
DA[cloudflare/d1/api.sh]
DS[cloudflare/d1/sync.sh]
DB[data/batching.sh]
end

subgraph Orchestration
SS[sync/schema.sh]
SD[sync/data.sh]
SV[sync/validation.sh]
end

LOG --> UC
LOG --> UT
CL --> LOG
CL --> UT
CV --> LOG
CP --> UC
CP --> LOG
CP --> CH
CVL --> UC
CVL --> LOG
CVL --> CH
BV --> LOG
BV --> UT
BV --> UC
BS --> LOG
BS --> UC
BD --> LOG
BD --> UC
DB --> UC
DA --> UC
DS --> DA
DS --> LOG
SS --> BS
SS --> DA
SS --> UT
SS --> UC
SS --> LOG
SD --> BD
SD --> DB
SD --> DS
SD --> DA
SD --> UT
SD --> UC
SD --> LOG
SV --> DS
SV --> DA
SV --> UT
SV --> UC
SV --> LOG

Module Dependency Matrix

Module NameDirect Dependencies
utils/core.shNone
utils/timing.shutils/core.sh
logging/logger.shutils/core.sh, utils/timing.sh
config/loader.shlogging/logger.sh, utils/timing.sh
config/validator.shlogging/logger.sh
cli/help.shNone
cli/parser.shutils/core.sh, logging/logger.sh, cli/help.sh
cli/validator.shutils/core.sh, logging/logger.sh, cli/help.sh
data/batching.shutils/core.sh
cloudflare/d1/api.shutils/core.sh
cloudflare/d1/sync.shcloudflare/d1/api.sh, logging/logger.sh
bear/validation.shlogging/logger.sh, utils/timing.sh, utils/core.sh
bear/schema.shlogging/logger.sh, utils/core.sh
bear/data.shlogging/logger.sh, utils/core.sh
sync/schema.shbear/schema.sh, cloudflare/d1/api.sh, utils/timing.sh, utils/core.sh, logging/logger.sh
sync/data.shbear/data.sh, data/batching.sh, cloudflare/d1/sync.sh, cloudflare/d1/api.sh, utils/timing.sh, utils/core.sh, logging/logger.sh
sync/validation.shcloudflare/d1/sync.sh, cloudflare/d1/api.sh, utils/timing.sh, utils/core.sh, logging/logger.sh

Sourcing Order

Modules must be sourced in dependency order:

  1. Foundation Layer: utils/core.sh, utils/timing.sh
  2. Infrastructure Layer: logging/logger.sh, config/loader.sh, config/validator.sh
  3. Interface Layer: cli/help.sh, cli/parser.sh, cli/validator.sh
  4. Domain Layer: data/batching.sh, cloudflare/d1/api.sh, cloudflare/d1/sync.sh, bear/validation.sh, bear/schema.sh, bear/data.sh
  5. Orchestration Layer: sync/schema.sh, sync/data.sh, sync/validation.sh