6.9 KiB
6.9 KiB
Project Structure
prosody-nodejs/
├── config/
│ └── default.yaml # Default server configuration
├── src/
│ ├── index.js # Main entry point
│ ├── core/ # Core server components
│ │ ├── server.js # Main server orchestrator
│ │ ├── config-manager.js # Configuration management
│ │ ├── session-manager.js # Session management
│ │ ├── stanza-router.js # Stanza routing
│ │ ├── host-manager.js # Virtual host management
│ │ ├── module-manager.js # Module system
│ │ ├── xmpp-stream.js # XMPP stream handler
│ │ ├── c2s-server.js # Client-to-Server
│ │ ├── s2s-server.js # Server-to-Server
│ │ ├── bosh-server.js # BOSH HTTP binding
│ │ ├── websocket-server.js # WebSocket support
│ │ └── component-server.js # Component protocol
│ ├── modules/ # Server modules
│ │ ├── mod_roster.js # Roster management
│ │ ├── mod_disco.js # Service discovery
│ │ ├── mod_presence.js # Presence handling
│ │ ├── mod_message.js # Message handling
│ │ ├── mod_mam.js # Message archive
│ │ ├── mod_muc.js # Multi-user chat
│ │ └── ...
│ ├── storage/ # Storage backends
│ │ ├── storage-manager.js
│ │ └── storage/
│ │ ├── memory.js # In-memory storage
│ │ ├── file.js # File-based storage
│ │ └── database.js # Database storage
│ └── utils/ # Utilities
│ ├── logger.js # Logging
│ ├── jid.js # JID parsing
│ └── xml.js # XML utilities
├── docs/ # Documentation
│ ├── QUICKSTART.md # Quick start guide
│ ├── API.md # API documentation
│ ├── MODULE_DEVELOPMENT.md # Module dev guide
│ └── DEPLOYMENT.md # Deployment guide
├── examples/ # Example code
│ ├── echo-bot.js # Echo bot example
│ ├── simple-client.js # Client example
│ └── modules/ # Example modules
│ └── mod_welcome.js
├── test/ # Tests
│ ├── core/
│ ├── modules/
│ └── integration/
├── logs/ # Log files (created at runtime)
├── data/ # Data storage (created at runtime)
├── certs/ # TLS certificates
├── uploads/ # File uploads
├── .env.example # Example environment variables
├── .gitignore # Git ignore file
├── package.json # NPM package configuration
├── setup.sh # Setup script
└── README.md # Main README
## File Descriptions
### Core Files
#### src/index.js
Main entry point. Initializes and starts the server.
#### src/core/server.js
Main server class that orchestrates all components:
- Initializes managers
- Starts network servers
- Handles lifecycle
#### src/core/config-manager.js
Singleton configuration manager:
- Loads YAML configuration
- Applies environment variables
- Provides configuration access
#### src/core/session-manager.js
Manages all active XMPP sessions:
- Session creation and authentication
- JID-to-session mapping
- Session lifecycle events
#### src/core/stanza-router.js
Routes XMPP stanzas to destinations:
- Message routing
- Presence broadcasting
- IQ request handling
#### src/core/host-manager.js
Manages virtual hosts:
- Multi-domain support
- Per-host configuration
- Module management per host
#### src/core/module-manager.js
Plugin/module system:
- Module loading and unloading
- Module API provisioning
- Event hooks
#### src/core/xmpp-stream.js
Handles XMPP stream negotiation:
- Stream features
- SASL authentication
- Resource binding
- Stream management
### Network Servers
#### src/core/c2s-server.js
Client-to-Server connections:
- TCP/TLS socket handling
- Connection limits
- Stream initialization
#### src/core/s2s-server.js
Server-to-Server federation:
- Dialback authentication
- Remote server connections
- Stanza forwarding
#### src/core/bosh-server.js
HTTP binding (BOSH):
- HTTP long-polling
- Session management
- CORS support
#### src/core/websocket-server.js
WebSocket support:
- WebSocket connections
- XMPP framing protocol
- Binary/text frames
#### src/core/component-server.js
External component protocol:
- Component authentication
- Component routing
- XEP-0114 support
### Storage
#### src/storage/storage-manager.js
Storage abstraction layer:
- Multiple backend support
- Store creation and management
- Host isolation
#### src/storage/storage/memory.js
In-memory storage implementation:
- Fast development storage
- No persistence
- Simple key-value store
### Modules
Modules extend server functionality. Each module can:
- Hook into events
- Handle stanzas
- Store data
- Interact with other modules
### Utilities
#### src/utils/logger.js
Winston-based logging:
- Multiple log levels
- File and console output
- Labeled loggers
## Configuration Files
### config/default.yaml
Main configuration file with:
- Server settings
- Network configuration
- Virtual hosts
- Module configuration
- Security settings
### .env
Environment-specific settings:
- Overrides YAML config
- Secrets and credentials
- Environment variables
## Runtime Directories
### logs/
Application log files:
- prosody-nodejs.log - Main log
- error.log - Error log
### data/
Runtime data storage:
- Session data
- Temporary files
- Database files (if file-based)
### certs/
TLS/SSL certificates:
- server.crt - Server certificate
- server.key - Private key
### uploads/
User file uploads (if enabled)
## Development Files
### test/
Unit and integration tests
### examples/
Example code and modules
### docs/
Comprehensive documentation
## Entry Points
1. **Server**: `npm start` runs `src/index.js`
2. **Development**: `npm run dev` runs with nodemon
3. **Tests**: `npm test` runs Jest tests
4. **Setup**: `./setup.sh` for initial setup
## Key Concepts
### Hosts
Virtual hosts allow multi-domain support. Each host can have:
- Own configuration
- Own modules
- Own data storage
### Sessions
Represent active client connections:
- Authenticated or not
- Associated with JID
- Has presence and priority
### Stanzas
XML elements in XMPP:
- message - Chat messages
- presence - Availability
- iq - Info/Query requests
### Modules
Extend server functionality:
- Load per host
- Hook into events
- Access server API
### Storage
Persistent data:
- Per-host isolation
- Multiple backends
- Key-value or document