# 0x4bd0/nestjs-microservices-tcp-example architecture

> Architecture diagram of the GitHub repository 0x4bd0/nestjs-microservices-tcp-example, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2025-02-12). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/0x4bd0/nestjs-microservices-tcp-example
- Repository: https://github.com/0x4bd0/nestjs-microservices-tcp-example

## Overview

##### Project Type Analysis
This is a microservices-based application consisting of two main services:
- An HTTP server (frontend API)
- A Math microservice (backend service)
The services communicate using TCP transport protocol.

##### Main Components

A. Client Layer
- External clients (Postman, Insomnia, etc.)

B. HTTP Server Service
- Main HTTP API (Port 3000)
- Controllers (app.controller.ts)
- Services (app.service.ts, math.service.ts)

C. Math Microservice
- TCP-based service
- Controllers (app.controller.ts)
- Services (app.service.ts)

- [Clients] → [HTTP Server Service] → [Math Microservice]

##### Detailed Component Representation

HTTP Server Service (Port 3000):
**┌─────────────────────────┐**
- HTTP Server Service  │
- ┌───────────────────┐  │
- app.controller   │  │
- ┘  │
- ┌───────────────────┐  │
- math.service    │  │
- ┘  │
- ┘

Math Microservice:
**┌─────────────────────────┐**
- Math Microservice    │
- ┌───────────────────┐  │
- app.controller   │  │
- ┘  │
- ┌───────────────────┐  │
- app.service     │  │
- ┘  │
- ┘

##### Flow Representation
- POST request flow: Client → HTTP Server → Math Microservice
- Data format: {data: [numbers]} as request payload
- Response flow back to client

##### Additional Elements
- TCP transport layer between services
- Port numbers (3000 for HTTP)
- Request/Response payload formats
- NestJS framework indication
- TypeScript usage indication

##### Important Notes
- Microservices architecture
- Clear separation between services
- TCP as the transport mechanism
- Environment configurations
- Testing capabilities (e2e tests present in both services)

##### Technical Stack Indicators
- NestJS framework
- TypeScript
- TCP transport
- HTTP protocol (for client communication)

## Diagram (Mermaid)

```mermaid
graph TB
    %% Client Layer
    Client(("External Client")):::client

    %% HTTP Server Service
    subgraph HTTP["HTTP Server Service"]
        direction TB
        HTTPEntry["Entry Point"]:::component
        HTTPModule["Module Config"]:::component
        HTTPController["Controller"]:::component
        HTTPService["Main Service"]:::component
        MathService["Math Service"]:::component
        HTTPTests["E2E Tests"]:::test
        
        HTTPEntry --> HTTPModule
        HTTPModule --> HTTPController
        HTTPController --> HTTPService
        HTTPController --> MathService
        HTTPTests -.- HTTPController
    end

    %% Math Microservice
    subgraph Math["Math Microservice"]
        direction TB
        MathEntry["Entry Point"]:::component
        MathModule["Module Config"]:::component
        MathController["Controller"]:::component
        MathMainService["Service"]:::component
        MathTests["E2E Tests"]:::test
        
        MathEntry --> MathModule
        MathModule --> MathController
        MathController --> MathMainService
        MathTests -.- MathController
    end

    %% Connections
    Client -->|HTTP POST| HTTP
    HTTP -->|TCP Transport| Math
    Math -->|Response| HTTP
    HTTP -->|Response| Client

    %% Styles
    classDef client fill:#2374AB,stroke:#2374AB,color:#fff
    classDef component fill:#95B46A,stroke:#666,color:#fff
    classDef test fill:#D4AA7D,stroke:#666,color:#fff

    %% Click Events
    click HTTP "https://github.com/0x4bd0/nestjs-microservices-TCP-Example/tree/master/http-server"
    click HTTPController "https://github.com/0x4bd0/nestjs-microservices-TCP-Example/blob/master/http-server/src/app.controller.ts"
    click HTTPService "https://github.com/0x4bd0/nestjs-microservices-TCP-Example/blob/master/http-server/src/app.service.ts"
    click MathService "https://github.com/0x4bd0/nestjs-microservices-TCP-Example/blob/master/http-server/src/math/math.service.ts"
    click HTTPEntry "https://github.com/0x4bd0/nestjs-microservices-TCP-Example/blob/master/http-server/src/main.ts"
    click HTTPModule "https://github.com/0x4bd0/nestjs-microservices-TCP-Example/blob/master/http-server/src/app.module.ts"
    click HTTPTests "https://github.com/0x4bd0/nestjs-microservices-TCP-Example/blob/master/http-server/test/app.e2e-spec.ts"
    
    click Math "https://github.com/0x4bd0/nestjs-microservices-TCP-Example/tree/master/math-microservice"
    click MathController "https://github.com/0x4bd0/nestjs-microservices-TCP-Example/blob/master/math-microservice/src/app.controller.ts"
    click MathMainService "https://github.com/0x4bd0/nestjs-microservices-TCP-Example/blob/master/math-microservice/src/app.service.ts"
    click MathEntry "https://github.com/0x4bd0/nestjs-microservices-TCP-Example/blob/master/math-microservice/src/main.ts"
    click MathModule "https://github.com/0x4bd0/nestjs-microservices-TCP-Example/blob/master/math-microservice/src/app.module.ts"
    click MathTests "https://github.com/0x4bd0/nestjs-microservices-TCP-Example/blob/master/math-microservice/test/app.e2e-spec.ts"
```
