How xarest/gobs works
Project Type and Purpose
• This is a Go-based dependency-injection & lifecycle management framework (library), not a full-stack app.
• Its purpose is to let users register “services” (instances) that implement lifecycle interfaces (Init, Setup, Start, Stop), resolve dependencies between them, then orchestrate those lifecycle phases in a correct order.
Main Components
1. Application Layer (samples / user code)
– sample/*.go (main.go)
– Calls gobs.NewBootstrap(), bs.AddDefault(&MyService{}), bs.StartBootstrap(ctx)
2. GoBs Core Library
a. Bootstrap Manager (bootstrap.go, service.go, config.go, dependencies.go)
– Registers services, holds service descriptors, kicks off lifecycle
b. Scheduler (scheduler/scheduler.go)
– Builds dependency graph, computes execution order (topological sort), invokes hooks
c. Common & Types (common/*.go, types/types.go)
– Defines ServiceStatus, ServiceLifeCycle, Dependencies, and error types
d. Logger (logger/log.go)
– Centralized logging of each phase and service outcome
e. Utils (utils/*.go)
– Helper functions (e.g., loop over services concurrently or sequentially)
3. Tests (test/*.go)
– Verify behaviour of Bootstrap and Scheduler
– Not part of runtime, but indicate coverage of each lifecycle phase
Relationships & Interactions
• Application Layer → Bootstrap Manager
(registers services, passes context)
• Bootstrap Manager ↔ Common / Types
(records each IService, its dependencies, status flags)
• Bootstrap Manager → Scheduler
(invoke scheduler.Init(), .Setup(), .Start(), .Stop())
• Scheduler → Services
(calls each service’s Init/Setup/Start/Stop in order dictated by dependency graph)
• Scheduler & Bootstrap → Logger
(emit “Service X Init successfully”, etc.)
• Dependencies flow: service D depends on B,C; B depends on A; C depends on A,B; etc.
Architectural Patterns & Design Principles
• Dependency Injection via “AddDefault(new(Service))”
• Lifecycle hook interfaces (IServiceInit, IServiceSetup, etc.)
• Graph-based scheduling (topological sort + reverse order for teardown)
• Separation of concerns: registration vs. scheduling vs. logging vs. common types
Essential Elements
– A small inset showing a sample dependency graph (nodes A, B, C, D with directed edges)
[APPLICATION (samples/main.go)]
│
└─► Register Services
│
▼
[BOOTSTRAP MANAGER] ◀── uses ── [common & types]
│─► build graph ──► [SCHEDULER]
│ │
│ ├─► calls IService.Init()
│ ├─► calls IService.Setup()
│ ├─► calls IService.Start()
│ └─► calls IService.Stop() (reverse order)
│
└─► logs ──► [LOGGER]
Inset:
Dependency Graph
A ↘ ↘
B ─────► C
↗
D
• Blue: Core packages
• Green: User application
• Orange: Scheduling engine
• Purple: Logging
• Gray: Shared types