# yeissonosorno/lang2sql architecture

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

- Interactive diagram: https://gitdiagram.com/yeissonosorno/lang2sql
- Repository: https://github.com/yeissonosorno/lang2sql

## Overview

##### Main Components Identification

a) Core Application Layer:
- Main NestJS Application Module (app.module.ts)
- Controllers Layer (app.controller.ts)
- Services Layer (app.service.ts)

b) Feature Modules:
- OpenAI Module (separate module for OpenAI integration)

c) Supporting Components:
- DTOs (Data Transfer Objects)
- Interfaces
- Common Utilities

##### Architectural Representation

a) Use a layered architecture approach with these levels (top to bottom):
**┌─────────────────────────────┐**
- Client Requests        │
- ┘
- ↓
**┌─────────────────────────────┐**
- Controllers Layer      │
- ┘
- ↓
**┌─────────────────────────────┐**
- Services Layer        │
- ┘
- ↓
**┌─────────────────────────────┐**
- External Services       │
- (OpenAI API)        │
- ┘

##### Component Details

- Rectangles with rounded corners: NestJS modules
- Regular rectangles: Controllers and Services
- Hexagons: External services (OpenAI)

##### Specific Elements

a) Main Application Components:
**┌─────────────────────────────┐**
- App Module             │
- ┌─────────────────┐      │
- App Controller  │      │
- ┘      │
- ┌─────────────────┐      │
- App Service   │      │
- ┘      │
- ┘

b) OpenAI Integration:
**┌─────────────────────────────┐**
- OpenAI Module          │
- ┌─────────────────┐      │
- OpenAI Service  │      │
- ┘      │
- ┘

##### Implementation Notes

- Maintain consistent spacing and alignment

##### Key Relationships to Highlight

- HTTP request flow from controllers to services
- Integration points with OpenAI API
- Data transformation through DTOs
- Error handling paths
- Test coverage boundaries

## Diagram (Mermaid)

```mermaid
flowchart TB
    subgraph Client
        CR[Client Requests]
    end

    subgraph NestJS_Core
        AM["App Module"]:::module
        AC["App Controller"]:::controller
        AS["App Service"]:::service
        ME["Main Entry Point"]:::core
        DTO["Data Transfer Objects"]:::dto
        INT["Interfaces"]:::interface
        UTIL["Common Utilities"]:::util
    end

    subgraph OpenAI_Integration
        OAM["OpenAI Module"]:::module
        OAS["OpenAI Service"]:::service
    end

    subgraph External_Services
        OAPI["OpenAI API"]:::external
    end

    subgraph Testing
        E2E["E2E Tests"]:::test
    end

    %% Relationships
    CR --> AC
    AC --> AS
    AS --> OAS
    OAS --> OAPI
    AC --> DTO
    AS --> INT
    AS --> UTIL
    OAS --> INT
    AM --> OAM
    ME --> AM
    E2E --> AC

    %% Click Events
    click AM "https://github.com/YeissonOsorno/lang2sql/blob/main/src/app.module.ts"
    click AC "https://github.com/YeissonOsorno/lang2sql/blob/main/src/app.controller.ts"
    click AS "https://github.com/YeissonOsorno/lang2sql/blob/main/src/app.service.ts"
    click ME "https://github.com/YeissonOsorno/lang2sql/blob/main/src/main.ts"
    click DTO "https://github.com/YeissonOsorno/lang2sql/blob/main/src/dto/translate.dto.ts"
    click INT "https://github.com/YeissonOsorno/lang2sql/blob/main/src/interfaces/index.interface.ts"
    click UTIL "https://github.com/YeissonOsorno/lang2sql/blob/main/src/common/utils.ts"
    click OAM "https://github.com/YeissonOsorno/lang2sql/blob/main/src/openai/open-ai.module.ts"
    click OAS "https://github.com/YeissonOsorno/lang2sql/blob/main/src/openai/open-ai.service.ts"
    click E2E "https://github.com/YeissonOsorno/lang2sql/blob/main/test/app.e2e-spec.ts"

    %% Styling
    classDef module fill:#b8d4ff,stroke:#333,stroke-width:2px
    classDef controller fill:#afd7ff,stroke:#333,stroke-width:1px
    classDef service fill:#a1e9ff,stroke:#333,stroke-width:1px
    classDef core fill:#ffcccb,stroke:#333,stroke-width:2px
    classDef dto fill:#ffe6cc,stroke:#333,stroke-width:1px,stroke-dasharray: 5 5
    classDef interface fill:#e6ccff,stroke:#333,stroke-width:1px,stroke-dasharray: 5 5
    classDef util fill:#ccffe6,stroke:#333,stroke-width:1px
    classDef external fill:#ffb366,stroke:#333,stroke-width:2px
    classDef test fill:#e6e6e6,stroke:#333,stroke-width:1px

    %% Legend
    subgraph Legend
        L1["Module"]:::module
        L2["Controller"]:::controller
        L3["Service"]:::service
        L4["Core"]:::core
        L5["DTO/Interface"]:::dto
        L6["Utility"]:::util
        L7["External Service"]:::external
        L8["Test"]:::test
    end
```
