# Contributing to Prosody Node.js Thank you for your interest in contributing to Prosody Node.js! This document provides guidelines and instructions for contributing. ## Code of Conduct - Be respectful and inclusive - Welcome newcomers - Focus on constructive feedback - Assume good intentions ## How to Contribute ### Reporting Bugs Before creating a bug report, please check existing issues. When creating a bug report, include: - **Clear title and description** - **Steps to reproduce** the issue - **Expected behavior** vs actual behavior - **Environment details** (OS, Node.js version, etc.) - **Logs** if applicable Example: ```markdown **Description**: Server crashes when connecting with invalid credentials **Steps to Reproduce**: 1. Start server with `npm start` 2. Connect with client using invalid password 3. Server crashes with error **Expected**: Server should reject connection gracefully **Environment**: - OS: Ubuntu 22.04 - Node.js: v18.17.0 - Version: 1.0.0 **Logs**: ``` Error: Cannot read property 'jid' of undefined at Session.authenticate (session-manager.js:123) ``` ``` ### Suggesting Features Feature requests are welcome! Please include: - **Use case**: Why is this feature needed? - **Description**: What should it do? - **Examples**: How would it be used? - **Alternatives**: What alternatives exist? ### Pull Requests 1. **Fork** the repository 2. **Create a branch** from `main`: ```bash git checkout -b feature/my-feature ``` 3. **Make your changes** 4. **Test your changes** 5. **Commit** with clear messages: ```bash git commit -m "Add support for SCRAM-SHA-1 authentication" ``` 6. **Push** to your fork: ```bash git push origin feature/my-feature ``` 7. **Create Pull Request** on GitHub ## Development Setup ### Prerequisites - Node.js 18+ - Git - Text editor (VS Code recommended) ### Setup ```bash # Clone your fork git clone https://github.com/your-username/prosody-nodejs.git cd prosody-nodejs # Install dependencies npm install # Create environment file cp .env.example .env # Run in development mode npm run dev ``` ### Running Tests ```bash # Run all tests npm test # Run specific test file npm test -- session-manager.test.js # Run with coverage npm test -- --coverage # Watch mode npm test -- --watch ``` ### Code Style We use ESLint and Prettier: ```bash # Check style npm run lint # Fix style issues npm run lint -- --fix # Format code npm run format ``` ### Code Standards - Use **ES6+** features - Use **async/await** for asynchronous code - Add **JSDoc comments** for public APIs - Write **meaningful variable names** - Keep functions **small and focused** - Handle **errors properly** Example: ```javascript /** * Authenticate a session with credentials * @param {string} sessionId - Session identifier * @param {string} username - Username * @param {string} password - Password * @returns {Promise} True if authenticated * @throws {AuthenticationError} If authentication fails */ async authenticateSession(sessionId, username, password) { if (!sessionId || !username || !password) { throw new Error('Missing required parameters'); } try { const session = this.getSession(sessionId); if (!session) { throw new AuthenticationError('Session not found'); } // Authenticate... return true; } catch (error) { this.logger.error('Authentication failed:', error); throw error; } } ``` ## Project Structure ``` prosody-nodejs/ ├── src/ │ ├── core/ # Core server components │ ├── modules/ # XMPP modules │ ├── storage/ # Storage backends │ └── utils/ # Utilities ├── test/ # Test files ├── docs/ # Documentation └── examples/ # Examples ``` ## What to Contribute ### High Priority - **Core Modules**: roster, disco, vcard, private - **Storage Backends**: PostgreSQL, MongoDB - **Authentication**: SCRAM-SHA-1, SCRAM-SHA-256 - **S2S Federation**: Complete implementation - **BOSH**: Full implementation - **WebSocket**: Full implementation ### Medium Priority - **XEPs**: MAM, MUC, PubSub, HTTP Upload - **Admin Interface**: Web-based admin panel - **Metrics**: Prometheus metrics - **Clustering**: Multi-instance support ### Low Priority - **Additional Features**: Various XEPs - **Performance**: Optimizations - **Documentation**: Improvements - **Examples**: More examples ## Module Development To create a new module: 1. Create file in `src/modules/mod_yourmodule.js` 2. Follow the module template: ```javascript module.exports = { name: 'yourmodule', version: '1.0.0', description: 'Your module description', author: 'Your Name', dependencies: [], load(module) { const { logger, stanzaRouter } = module.api; logger.info('Your module loaded'); // Add your functionality }, unload(module) { module.api.logger.info('Your module unloaded'); } }; ``` 3. Add tests in `test/modules/mod_yourmodule.test.js` 4. Document in `docs/MODULES.md` ## Testing ### Unit Tests Test individual components: ```javascript // test/core/session-manager.test.js const SessionManager = require('../../src/core/session-manager'); describe('SessionManager', () => { let manager; beforeEach(() => { manager = new SessionManager({}); }); it('should create a session', () => { const session = manager.createSession({ id: 'test-123', jid: 'user@localhost' }); expect(session).toBeDefined(); expect(session.jid).toBe('user@localhost'); }); }); ``` ### Integration Tests Test component interaction: ```javascript // test/integration/c2s.test.js const Server = require('../../src/core/server'); const { Client } = require('@xmpp/client'); describe('C2S Integration', () => { let server; beforeAll(async () => { server = new Server(config); await server.start(); }); afterAll(async () => { await server.stop(); }); it('should accept client connection', async () => { const client = new Client({...}); await client.connect(); expect(client.online).toBe(true); }); }); ``` ## Documentation - Update **README.md** for major features - Add **API documentation** in `docs/API.md` - Create **guides** for new features - Add **examples** for common use cases - Update **CHANGELOG.md** ## Commit Messages Use clear, descriptive commit messages: ### Format ``` ():