How edilsonlm217/whatsapp-session-manager works
Main Components
• App Module – The entry point of the application which wires together the various modules (see src/app.module.ts).
• WhatsApp Module – Contains the controller and service handling WhatsApp-related operations (see src/core/whatsapp/whatsapp.module.ts, whatsapp.controller.ts, and whatsapp.service.ts).
• WhatsApp Session Manager – A specialized sub-module handling WhatsApp session management and authentication (under src/core/whatsapp/session-manager) that includes:
• Auth State Module – Managing different authentication states with its own service and helper classes (see auth-state.module.ts, auth-state.service.ts, and the services in auth-state/services).
• Session management service – Orchestrates session-related actions using components like whatsapp-session.ts.
• Database Module – Manages data persistence and repository operations (located in src/database). It includes repositories for credentials (creds.repository.ts) and keys (keys.repository.ts).
• Testing components – Indicated by integration and e2e tests in the test folder.
• Configuration files – Files such as docker-compose.yml, tsconfig.json, nest-cli.json, and various linting/formatting configuration files support deployment, building, and coding standards.
Relationships and Interactions
• Flow of a Request:
• External requests go to the App Controller(s) or a dedicated WhatsApp Controller. The WhatsApp Controller (src/core/whatsapp/whatsapp.controller.ts) handles incoming API calls.
• The controller delegates business logic to the WhatsApp Service (src/core/whatsapp/whatsapp.service.ts). This service, in turn, may interact with the session manager to handle authentication and session persistence.
• The Session Manager orchestrates interactions with the Auth State components. The Auth State Service utilizes its helper services (for credentials and keys processing) contained in auth-state/services.
• Database interactions are handled by the Database Module. Specific repositories (creds.repository.ts and keys.repository.ts) are used by session manager components or other services to store or retrieve data.
• Dependency Relationships:
• Modules are decoupled using NestJS’s dependency injection and modular architecture.
• The WhatsApp module depends on both the session manager and the database modules.
• The session manager leverages the Auth State sub-module to manage authentication states.
Architectural Patterns and Key Technologies
• Modular Architecture – The clear separation of features into separate modules (e.g., app, whatsapp, database) follows the NestJS modular pattern.
• Service-Controller-Repository Pattern – Controllers receiving HTTP requests, services for business logic, and repositories for database interactions.
• Dependency Injection – NestJS’s DI is used extensively to wire modules and services together.
• Docker and Environment Configuration – Presence of docker-compose.yml suggests containerized deployment.
• Testing – Presence of unit and e2e test folders indicates focus on quality with proper test organization.