Relevant source files
The following files were used as context for generating this wiki page:
This document provides an overview of the module structure within the apps/api directory, focusing on how different feature modules are organized and integrated into the main application. It details the AppModule as the root, along with specific examples like HealthModule, IntegrationPlatformModule, and QuestionnaireModule, illustrating their responsibilities and dependencies.
The architecture leverages NestJS modules to encapsulate related functionalities, promoting modularity and maintainability. Each module typically groups controllers, services, and repositories relevant to a specific domain, which are then imported into the AppModule to form the complete API application.
Core Application Module (AppModule)
The AppModule serves as the root module for the NestJS API application. It aggregates all other feature modules, global configurations, and core services required for the application to function. This module is responsible for setting up global configurations like rate limiting and loading environment-specific settings.
Global Configuration and Guards
The AppModule initializes several global configurations and guards:
ConfigModule: Configures the application to load environment variables and specific configuration objects (awsConfig,betterAuthConfig). It is set as global, making configuration available throughout the application.ThrottlerModule: Implements rate limiting to protect the API from abuse. It is configured to allow 100 requests per minute (ttl: 60000,limit: 100) per IP address.APP_GUARD: TheThrottlerGuardis provided globally usingAPP_GUARD, ensuring that rate limiting is applied to all routes by default.
Sources: apps/api/src/app.module.ts:1-60
Feature Module Imports
The AppModule imports a wide array of feature modules, each responsible for a specific domain or functionality within the API. This modular approach helps in organizing the codebase and managing dependencies.
The AppModule imports 29 distinct feature modules, demonstrating a comprehensive microservices-like architecture within a single NestJS application.
The following diagram illustrates the primary modules imported by the AppModule:
Sources: apps/api/src/app.module.ts:31-57
Health Module (HealthModule)
The HealthModule is a simple module dedicated to providing health check endpoints for the API. It contains only a controller, HealthController, which would typically expose endpoints to verify the application's operational status.
Sources: apps/api/src/health/health.module.ts:1-6
Integration Platform Module (IntegrationPlatformModule)
The IntegrationPlatformModule is a comprehensive module responsible for managing various aspects of third-party integrations. It encompasses controllers for handling OAuth flows, managing connections, administrative tasks, and webhook processing. It also provides services for credential management, connection handling, and automated checks, supported by dedicated repositories for data persistence.
Components
This module is structured with a clear separation of concerns, including:
- Controllers: Handle incoming HTTP requests related to integrations.
- Services: Encapsulate business logic for integration functionalities.
- Repositories: Manage data access for integration-related entities.
The module also exports several services, making them available for use by other modules that import IntegrationPlatformModule.
Exporting services like CredentialVaultService and ConnectionService allows other modules to securely interact with integration functionalities without needing to know the internal implementation details of the IntegrationPlatformModule.
Module Structure
The following diagram illustrates the internal components of the IntegrationPlatformModule:
Sources: apps/api/src/integration-platform/integration-platform.module.ts:1-62
Questionnaire Module (QuestionnaireModule)
The QuestionnaireModule handles functionalities related to questionnaires. It includes a controller for API endpoints and a service for business logic. Notably, it imports the TrustPortalModule, indicating a dependency on trust portal functionalities, possibly for questionnaire publishing or data integration.
Sources: apps/api/src/questionnaire/questionnaire.module.ts:1-11