Real World Example

Module Map of a Payments Backend

A payments company like Razorpay or PhonePe splits its backend into many modules. A simplified NestJS version:

AppModule
├── ConfigModule (global)        env, secrets
├── DatabaseModule               TypeORM / Prisma connection
├── AuthModule      ──imports──> UsersModule
├── MerchantsModule
├── PaymentsModule  ──imports──> MerchantsModule, LedgerModule
├── LedgerModule                 double-entry accounting
├── WebhooksModule  ──imports──> PaymentsModule
└── NotificationsModule          SMS, email

src/payments/payments.module.ts

import { Module } from '@nestjs/common';
import { MerchantsModule } from '../merchants/merchants.module';
import { LedgerModule } from '../ledger/ledger.module';
import { PaymentsController } from './payments.controller';
import { PaymentsService } from './payments.service';
import { UpiGateway } from './gateways/upi.gateway';
import { CardGateway } from './gateways/card.gateway';

@Module({
  imports: [MerchantsModule, LedgerModule],
  controllers: [PaymentsController],
  providers: [PaymentsService, UpiGateway, CardGateway],
  exports: [PaymentsService],          // WebhooksModule updates payment status
})
export class PaymentsModule {}