# victorcazuriaga/backend_letssign architecture

> Architecture diagram of the GitHub repository victorcazuriaga/backend_letssign, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2025-05-13). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/victorcazuriaga/backend_letssign
- Repository: https://github.com/victorcazuriaga/backend_letssign

## Overview

##### Project type and purpose
- This is a NestJS-based monorepo containing three backend microservices (auth, document, notification) plus a shared library (common).
- Each “app” is a standalone NestJS application, communicating over HTTP (and potentially RabbitMQ) and sharing reusable modules for database access and messaging.

##### Core components
a. Microservices
- Auth Service (apps/auth)
- Document Service (apps/document)
- Notification Service (apps/notification)
b. Shared Library
- Common Library (libs/common) with two sub-modules:
- Database Module (abstract repository/schema)
- RMQ Module (RabbitMQ wrapper)
c. Infrastructure
- MongoDB (for persisting users, companies, documents)
- RabbitMQ broker (for event-driven interactions)
d. Clients / External Actors
- API Consumers (web/mobile clients or API Gateway)
- Optional administration console or other microservices

##### Relationships and interactions
- Clients → HTTP → Auth Service (login, signup, JWT issuance)
- Clients → HTTP → Document Service (CRUD operations on documents)
- Clients → HTTP → Notification Service (dispatch or query notifications)
- Auth/Document Services → MongoDB (via Common Database Module)
- Auth/Document Services → RabbitMQ (publish domain events via Common RMQ Module)
- Notification Service → RabbitMQ (subscribe to relevant event queues and send out notifications)
- All three microservices import the Common Library for shared abstractions

##### Architectural patterns and design principles
- Microservice architecture: each service has its own code, configuration, and lifecycle.
- Modular code sharing: libs/common provides centralized data-access and messaging modules.
- Dependency inversion: controllers depend on service interfaces, and those rely on abstract repositories/schemas.
- Event-driven communication: RabbitMQ for decoupling and asynchronous workflows.

##### Detailed elements
- Component labels (Auth Service, Document Service, Notification Service, Common Library, MongoDB, RabbitMQ, Clients)
- Arrowheads and direction for data flow
- Optional: ports/endpoints (e.g., Auth Service: POST /login, POST /users) and queue names/topics (e.g., user.created)

## Diagram (Mermaid)

```mermaid
flowchart TB
    %% Clients
    Clients["Clients/API Gateway"]:::client

    %% Auth Service
    subgraph "Auth Service"
        direction TB
        AuthEntry["main.ts"]:::file
        AuthController["auth.controller.ts"]:::file
        AuthService["auth.service.ts"]:::file
        JWTGuard["jwt-auth.guard.ts"]:::file
        LocalGuard["local-auth.guard.ts"]:::file
        JWTStrategy["jwt.strategy.ts"]:::file
        LocalStrategy["local.strategy.ts"]:::file
        subgraph "Users Module"
            direction TB
            UsersModule["users.module.ts"]:::file
            UsersController["users.controller.ts"]:::file
            UsersService["users.service.ts"]:::file
            UsersRepo["users.repository.ts"]:::file
            CompanyRepo["company.repository.ts"]:::file
        end
    end

    %% Document Service
    subgraph "Document Service"
        direction TB
        DocEntry["main.ts"]:::file
        DocController["document.controller.ts"]:::file
        DocService["document.service.ts"]:::file
    end

    %% Notification Service
    subgraph "Notification Service"
        direction TB
        NotifEntry["main.ts"]:::file
        NotifController["notification.controller.ts"]:::file
        NotifService["notification.service.ts"]:::file
    end

    %% Shared Library
    subgraph "Common Library"
        direction TB
        CommonRoot["libs/common/src"]:::lib
        subgraph "Database Module"
            direction TB
            AbstractSchema["abstract.schema.ts"]:::file
            AbstractRepo["abstract.repository.ts"]:::file
        end
        subgraph "RMQ Module"
            direction TB
            RMQModule["rmq.module.ts"]:::file
            RMQService["rmq.service.ts"]:::file
        end
    end

    %% Infrastructure
    MongoDB["MongoDB"]:::db
    RabbitMQ["RabbitMQ Broker"]:::mq

    %% Connections
    Clients -->|HTTP| AuthEntry
    Clients -->|HTTP| DocEntry
    Clients -->|HTTP| NotifEntry

    AuthEntry -->|imports common| CommonRoot
    DocEntry -->|imports common| CommonRoot
    NotifEntry -->|imports common| CommonRoot

    AuthEntry -->|DB calls via Common DB Module| MongoDB
    DocEntry -->|DB calls via Common DB Module| MongoDB

    AuthEntry -.->|publish events via RMQ| RabbitMQ
    DocEntry -.->|publish events via RMQ| RabbitMQ
    RabbitMQ -.->|subscribe events| NotifEntry

    %% Click Events
    click Clients "https://github.com/victorcazuriaga/backend_letssign/tree/main/N/A"
    click AuthEntry "https://github.com/victorcazuriaga/backend_letssign/blob/main/apps/auth/src/main.ts"
    click AuthController "https://github.com/victorcazuriaga/backend_letssign/blob/main/apps/auth/src/auth.controller.ts"
    click AuthService "https://github.com/victorcazuriaga/backend_letssign/blob/main/apps/auth/src/auth.service.ts"
    click JWTGuard "https://github.com/victorcazuriaga/backend_letssign/blob/main/apps/auth/src/guards/jwt-auth.guard.ts"
    click LocalGuard "https://github.com/victorcazuriaga/backend_letssign/blob/main/apps/auth/src/guards/local-auth.guard.ts"
    click JWTStrategy "https://github.com/victorcazuriaga/backend_letssign/blob/main/apps/auth/src/strategies/jwt.strategy.ts"
    click LocalStrategy "https://github.com/victorcazuriaga/backend_letssign/blob/main/apps/auth/src/strategies/local.strategy.ts"
    click UsersModule "https://github.com/victorcazuriaga/backend_letssign/blob/main/apps/auth/src/users/users.module.ts"
    click UsersController "https://github.com/victorcazuriaga/backend_letssign/blob/main/apps/auth/src/users/users.controller.ts"
    click UsersService "https://github.com/victorcazuriaga/backend_letssign/blob/main/apps/auth/src/users/users.service.ts"
    click UsersRepo "https://github.com/victorcazuriaga/backend_letssign/blob/main/apps/auth/src/users/repositories/users.repository.ts"
    click CompanyRepo "https://github.com/victorcazuriaga/backend_letssign/blob/main/apps/auth/src/users/repositories/company.repository.ts"

    click DocEntry "https://github.com/victorcazuriaga/backend_letssign/blob/main/apps/document/src/main.ts"
    click DocController "https://github.com/victorcazuriaga/backend_letssign/blob/main/apps/document/src/document.controller.ts"
    click DocService "https://github.com/victorcazuriaga/backend_letssign/blob/main/apps/document/src/document.service.ts"

    click NotifEntry "https://github.com/victorcazuriaga/backend_letssign/blob/main/apps/notification/src/main.ts"
    click NotifController "https://github.com/victorcazuriaga/backend_letssign/blob/main/apps/notification/src/notification.controller.ts"
    click NotifService "https://github.com/victorcazuriaga/backend_letssign/blob/main/apps/notification/src/notification.service.ts"

    click CommonRoot "https://github.com/victorcazuriaga/backend_letssign/tree/main/libs/common/src"
    click AbstractRepo "https://github.com/victorcazuriaga/backend_letssign/blob/main/libs/common/src/database/abstract.repository.ts"
    click AbstractSchema "https://github.com/victorcazuriaga/backend_letssign/blob/main/libs/common/src/database/abstract.schema.ts"
    click RMQModule "https://github.com/victorcazuriaga/backend_letssign/blob/main/libs/common/src/rmq/rmq.module.ts"
    click RMQService "https://github.com/victorcazuriaga/backend_letssign/blob/main/libs/common/src/rmq/rmq.service.ts"

    %% Styles
    classDef client fill:#E8F1FA,stroke:#1E90FF,color:#1E90FF;
    classDef service fill:#F0F8E8,stroke:#32CD32,color:#32CD32;
    classDef db fill:#FFEFD5,stroke:#FF8C00,color:#FF8C00,shape:cylinder;
    classDef mq fill:#FFF5EE,stroke:#DC143C,color:#DC143C,shape:cloud;
    classDef lib fill:#F5F5F5,stroke:#A9A9A9,color:#696969;
    classDef file fill:#FFFFFF,stroke:#A9A9A9,color:#000000;

    class AuthEntry,AuthController,AuthService,JWTGuard,LocalGuard,JWTStrategy,LocalStrategy,UsersModule,UsersController,UsersService,UsersRepo,CompanyRepo service;
    class DocEntry,DocController,DocService service;
    class NotifEntry,NotifController,NotifService service;
    class MongoDB db;
    class RabbitMQ mq;
    class CommonRoot,AbstractSchema,AbstractRepo,RMQModule,RMQService lib;
```
