How nats-io/nats-server works
NATS Server is a communications server for services and devices. Its principal workflow accepts client connections, authenticates them, processes subscriptions and published messages, and distributes matching messages; JetStream adds persistent streaming and storage. The tree also shows clustering, monitoring, configuration, and security subsystems. The excerpts establish startup, subscription insertion, and account setup, but leave much of runtime dispatch and subsystem wiring unsampled, so uncertain relationships are shown as dashed and unverified.
Main entry points: server.go Server runtime · client.go Client protocol · main.go Server CLI · stream.go Stream management
Components 22
Startup and configuration
- Server CLI
main.go - Config parsing
conf/parse.go - Server runtime
server/server.go
Client messaging
- Client protocol
server/client.go - Protocol parser
server/parser.go - Authentication
server/auth.go - Subscription matching
server/sublist.go - Subject tree
server/stree/stree.go - Accounts
server/accounts.go
JetStream persistence
- JetStream
server/jetstream.go - Stream management
server/stream.go - Message storage
server/store.go - Stream backup
server/stream_backup.go
Distributed operation
- Route connections
server/route.go - Gateway connections
server/gateway.go - Leaf connections
server/leafnode.go
Security and operations
- Authorization
server/auth_callout.go - Certificate handling
server/certidp/certidp.go - Monitoring
server/monitor.go - Logging
logger/log.go
Other components
- Operator
- NATS clients
Connections 21
- Operator → Server CLI: configures
- Server CLI → Server runtime: starts
main.go - Server CLI → Config parsing: loads config
- Server runtime → Logging: uses logging
server/server.go - NATS clients → Client protocol: connects
- Client protocol → Authentication: authenticates
- Client protocol → Protocol parser: processes protocol
- Client protocol → Accounts: updates account
server/client.go - Client protocol → Subscription matching: inserts subscriptions
server/client.go - Client protocol → Subject tree: matches subjects
- Server runtime → Accounts: registers accounts
server/server.go - Server runtime → JetStream: initializes
- JetStream → Stream management: manages streams
- Stream management → Message storage: persists messages
- Stream management → Stream backup: backs up
- Server runtime → Route connections: manages routes
- Server runtime → Gateway connections: manages gateways
- Server runtime → Leaf connections: manages leaf nodes
- Server runtime → Monitoring: starts monitoring
- Server runtime → Authorization: configures authorization
- Server runtime → Certificate handling: configures certificates