# ciceksepetitech/sqlapi architecture

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

- Interactive diagram: https://gitdiagram.com/ciceksepetitech/sqlapi
- Repository: https://github.com/ciceksepetitech/sqlapi

## Overview

##### Main Components
- HTTP API Entry Point: Represent the REST API endpoint that accepts POST requests (e.g., at /sql on port 8033, as specified in the README).
- Command Entry/Server Bootstrap: The main entry point is in the “cmd/sqlapi/main.go” file that sets up the HTTP server.
- Database Abstraction / Query Handler: Within the application logic, there is a routing or handler layer that inspects the incoming JSON, extracts the DB credentials, and determines which internal component should execute the query.
- Database-Specific Modules: There are separate internal packages for each supported database:
- internal/mysql for MySQL
- internal/mssql for MSSQL
- internal/mongodb for MongoDB
- Docker/Deployment: The Dockerfile and GitHub Actions workflows indicate the application is containerized and set up for continuous integration.

##### Relationships and Data Flow
- The client sends an HTTP POST request with required JSON data (credentials and query).
- The API layer (within the main.go that initializes the server) receives and validates the request.
- A controller/handler layer directs the request to the appropriate database module based on the supplied “type” (e.g., “mysql”, “mssql”, or “mongodb”).
- Each internal module contains the logic to establish a connection with the database using the provided credentials, execute the query, and then return the result.
- The API layer converts the query response into JSON and sends it back to the client.

##### Architectural Patterns and Design Principles
- Separation of Concerns: The clear division between the HTTP server logic (in the cmd folder) and the database access logic (in the internal folder) keeps each responsibility isolated.
- Modular Architecture: Each database type has its own module, which is beneficial for extensibility and maintenance.
- API Gateway Pattern (simplified): The API acts as the single entry point and determines routing based on input data.
- Containerization: Including a Dockerfile shows that the system is deployed as a containerized service.

##### Relevant Technologies and Frameworks
- Go as the primary programming language with dependency management via go.mod and go.sum.
- Docker for containerization.
- HTTP based interfaces, likely using Go’s http package or a lightweight web framework.
- Integration with MySQL, MSSQL, and MongoDB, with potential use of driver libraries relevant to each.

## Diagram (Mermaid)

```mermaid
flowchart TB
    %% External Client
    Client["Client"]:::client

    %% Deployment subgraph (Docker Container/Deployment)
    subgraph "Deployment"
        deploy1["Dockerfile"]:::deployment
        deploy2["CI Workflow"]:::deployment
    end

    %% Docker Container subgraph encapsulating API Server and Request Handler
    subgraph "Docker Container"
        A["API Server (Port 8033)"]:::server
        B["Request Handler/Router"]:::handler
        A -->|"route"| B
    end

    %% Database Modules
    M1["MySQL Module"]:::module
    M2["MSSQL Module"]:::module
    M3["MongoDB Module"]:::module

    %% Data Flow Connections
    Client -->|"POST"| A
    B -->|"mysql"| M1
    B -->|"mssql"| M2
    B -->|"mongodb"| M3
    M1 -->|"result"| A
    M2 -->|"result"| A
    M3 -->|"result"| A
    A -->|"JSON_Response"| Client

    %% Deployment to Docker Container Connection
    deploy1 ---|"containerized"| A
    deploy2 ---|"containerized"| A

    %% Click Events
    click A "https://github.com/ciceksepetitech/sqlapi/blob/main/cmd/sqlapi/main.go"
    click B "https://github.com/ciceksepetitech/sqlapi/blob/main/cmd/sqlapi/main.go"
    click M1 "https://github.com/ciceksepetitech/sqlapi/blob/main/internal/mysql/mysql.go"
    click M2 "https://github.com/ciceksepetitech/sqlapi/blob/main/internal/mssql/mssql.go"
    click M3 "https://github.com/ciceksepetitech/sqlapi/blob/main/internal/mongodb/mongodb.go"
    click deploy1 "https://github.com/ciceksepetitech/sqlapi/tree/main/Dockerfile"
    click deploy2 "https://github.com/ciceksepetitech/sqlapi/blob/main/.github/workflows/main.yml"

    %% Styles
    classDef client fill:#f4cccc,stroke:#c27ba0,stroke-width:2px;
    classDef server fill:#c9daf8,stroke:#6d9eeb,stroke-width:2px;
    classDef handler fill:#d9ead3,stroke:#6aa84f,stroke-width:2px;
    classDef module fill:#fff2cc,stroke:#f1c232,stroke-width:2px;
    classDef deployment fill:#ead1dc,stroke:#cc99cc,stroke-width:2px;
```
