'modules' folder created - update architecture to hybrid microsservices/monolit#19
'modules' folder created - update architecture to hybrid microsservices/monolit#19DrakoMichael merged 23 commits intomainfrom
Conversation
Refactored WebSocket bootstrap logic for improved initialization and error handling. Updated ws_functions to accept config and improved broadcast logic. Replaced index_test.js with a simpler bypass.js for testing, and updated package.json test script accordingly. Cleaned up spam generator code and improved settings loader export. Added release notes for v1.0.1.
Co-authored-by: DrakoMichael <22016138+DrakoMichael@users.noreply.github.com>
Co-authored-by: DrakoMichael <22016138+DrakoMichael@users.noreply.github.com>
Co-authored-by: DrakoMichael <22016138+DrakoMichael@users.noreply.github.com>
Co-authored-by: DrakoMichael <22016138+DrakoMichael@users.noreply.github.com>
…shake-twitch [WIP] Implement handshake using OAuth2 with Twitch external websocket
Co-authored-by: DrakoMichael <22016138+DrakoMichael@users.noreply.github.com>
Co-authored-by: DrakoMichael <22016138+DrakoMichael@users.noreply.github.com>
Co-authored-by: DrakoMichael <22016138+DrakoMichael@users.noreply.github.com>
[WIP] Add web page to edit config.json settings
Co-authored-by: DrakoMichael <22016138+DrakoMichael@users.noreply.github.com>
Co-authored-by: DrakoMichael <22016138+DrakoMichael@users.noreply.github.com>
…auth0 [WIP] Add redirect URL for Auth0 in Express application
Deleted the entire contents of the docs/api directory, including HTML documentation, fonts, scripts, and styles. This cleans up generated documentation and related assets from the repository.
Moved Twitch-specific connection logic from connectionHUB.js to a new handleTwitchConnection.js module for better separation of concerns. Updated connectionHUB.js to delegate Twitch events to the new handler. Minor code style and class name improvements in index.js.
Extracted Twitch EventSub WebSocket event handling and protocol logic from connectionWS.js into a new connectionRules.js module for improved separation of concerns and maintainability. Updated connectionWS.js to delegate event handling to connectionRules. Minor cleanup in logManager.js and websocket_bootstrap.js.
There was a problem hiding this comment.
Pull request overview
This pull request introduces a significant architectural refactoring that transitions the codebase toward a hybrid microservices/monolith architecture by creating a 'modules' folder. The primary focus is on integrating Twitch OAuth2 EventSub WebSocket support and reorganizing the spam generator functionality into a standalone module.
Changes:
- Added comprehensive Twitch OAuth2 integration with EventSub WebSocket support, including authentication, session management, keepalive handling, and event processing
- Refactored spam generator from services to a new modular structure in
modules/service_spamChatBot/ - Enhanced WebSocket functionality with config injection and new broadcast method
- Added extensive documentation including OAuth2 guide and usage examples
- Updated configuration structure to support Twitch credentials and module-specific settings
Reviewed changes
Copilot reviewed 108 out of 146 changed files in this pull request and generated 9 comments.
Show a summary per file
| File | Description |
|---|---|
| src/tests/bypass.js | New test bypass utility (contains unprofessional comment) |
| src/tests/index_test.js | Removed placeholder test class |
| src/services/websocket/ws_functions.js | Enhanced with config injection and broadcast method |
| src/services/websocket/websocket_starter.js | Improved error handling |
| src/services/websocket/websocket_bootstrap.js | Refactored to class-based singleton with logging |
| src/services/spamGenerator/liveChatSpam.js | Deleted - moved to modules |
| src/services/settings/loadsettings.js | Function declaration style change |
| src/services/settings/config_backup.js | Added Twitch configuration section |
| src/services/externalConnections/twitch/* | New Twitch OAuth2 integration files |
| src/services/dataBase/sqlite3_bootstrap.js | Fixed import path case sensitivity |
| src/services/app/logManager.js | Minor formatting corrections |
| src/services/app/debugBootstrap.js | Added Twitch connection initialization (has bug) |
| src/services/app/bootstrapApp.js | Updated to use new module structure |
| src/public/scripts.js | WebSocket port changed to 8181 |
| src/index.js | Class renamed from 'main' to 'Main' |
| src/config.json | Added Twitch config (misconfigured) |
| package.json | Added dotenv dependency |
| modules/service_spamChatBot/* | New modular spam chat bot implementation |
| docs/api/* | Removed outdated API documentation |
| EXAMPLE_USAGE.md, .env.example | New documentation files |
| .gitignore | Fixed log paths |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
| // ensure bot is running (start if not) | ||
| let bot = spamChatBot.getInstance(); | ||
| if (!bot) { | ||
| bot = await spamChatBot.start({ port: this.config.spam_port || 8081, pingInterval: this.config.pingInterval }); |
There was a problem hiding this comment.
The port configuration fallback uses 'config.spam_port' which doesn't exist in the configuration. According to config.json, the property should be 'config.dev_config.spam_module_websocket_port'. This will result in the port being set to 8081 (default) instead of the configured value.
| // EXEMPLO 6: Uso com função helper (compatibilidade total) | ||
| // ============================================================================ | ||
|
|
||
| const { createSpamGenerator, stopLiveChatSpam } = require('./liveChatSpam'); |
There was a problem hiding this comment.
The example file uses 'require' syntax (CommonJS) on line 147, but the rest of the codebase uses ES6 module imports. This inconsistency may cause errors if the file is executed, as the project uses "type": "module" in package.json.
| } | ||
| } else { | ||
| // fallback to existing websocket bootstrap if present | ||
| const wsFunctions = websocket_bootstrap.getInstance(); |
There was a problem hiding this comment.
The import for 'websocket_bootstrap' is missing. Line 68 references 'websocket_bootstrap.getInstance()' but there is no import statement for this module at the top of the file.
| // fallback to existing websocket bootstrap if present | ||
| const wsFunctions = websocket_bootstrap.getInstance(); | ||
| if (wsFunctions && typeof wsFunctions.sendNewChat === 'function') { | ||
| try { wsFunctions.sendNewChat(formattedMessage); } catch (_) {} |
There was a problem hiding this comment.
The method 'sendNewChat' does not exist on wsFunctions. Based on the ws_functions.js changes in this PR, the method was renamed to 'broadcast'. This will cause a runtime error if this fallback code path is executed.
| * Exemplo de uso do LiveChatSpam | ||
| */ | ||
|
|
||
| import LiveChatSpam from './liveChatSpam.js'; |
There was a problem hiding this comment.
Line 5 imports 'LiveChatSpam' but the module 'liveChatSpam.js' was deleted in this PR and replaced with 'spammer.js'. This example file will not work and appears to reference the old API.
| "dev_config": { | ||
| "dev_websocket_port" : 8181, | ||
| "dev_express_port" : 3232, | ||
| "debbug": false, |
There was a problem hiding this comment.
The 'debbug' configuration option is misspelled. It should be 'debug' for consistency and clarity. This appears in the configuration file and throughout the codebase.
| "connected_chat_notify": true, | ||
| "enable_spam": true, | ||
| "connected_chat_notify": true, | ||
| "spam_module_websocket_port": 8282, |
There was a problem hiding this comment.
The property 'spam_module_websocket_port' is added to the configuration but is not referenced anywhere in the Spammer or spamChatBot code. The spammer.js file uses 'config.spam_port' on line 21, which doesn't exist in the configuration. This inconsistency will cause the spam feature to malfunction.
| "twitch": { | ||
| "client_id": "", | ||
| "client_secret": "", | ||
| "access_token": "", | ||
| "refresh_token": "", | ||
| "enable_twitch_connection": true |
There was a problem hiding this comment.
The 'enable_twitch_connection' is set to 'true' in config.json but the Twitch OAuth2 credentials (client_id, client_secret, access_token, refresh_token) are empty strings. This will cause the Twitch connection to fail on startup with the error "Missing client_id or access_token in configuration". For a default configuration file, this should either be set to false or include placeholder comments indicating required values.
| */ | ||
| static async init(config) { | ||
| console.log("Debug Bootstrap initialized."); | ||
| await websocket_bootstrap.ignite_test(); |
There was a problem hiding this comment.
The websocket_bootstrap.ignite_test() method is called but it was removed in the websocket_bootstrap.js changes in this PR. This will cause a runtime error when debug mode is enabled.
This pull request introduces significant improvements and documentation updates related to Twitch OAuth2 integration, application bootstrapping, and logging. It includes new guides and example usage, enhanced release notes, and updates to environment variable configuration. Additionally, it removes an outdated API documentation file.
Twitch OAuth2 Integration Documentation and Configuration:
.env.examplewith detailed Twitch OAuth2 configuration variables and instructions for obtaining credentials and tokens.TWITCH_OAUTH2_GUIDE.md, a comprehensive setup and troubleshooting guide for integrating Twitch OAuth2 and EventSub WebSocket, including both automatic and manual token flows, security tips, and next steps.EXAMPLE_USAGE.mdproviding a practical, step-by-step example for configuring and running the application with Twitch OAuth2, including expected logs, troubleshooting, and usage of the Session ID.Release Notes and Feature Improvements:
RELEASE_NOTES.mdfor v1.0.1, detailing new features such as enhanced bootstrapping (sequential module initialization, health checks, safe error handling), an advanced logging system (multi-level, file output, colored console), improved configuration loading, bug fixes, technical details, and planned future improvements.Documentation Cleanup:
docs/api/1.module_Main-Main.htmlto keep the documentation up-to-date.