# javitorres/datalakestudio architecture

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

- Interactive diagram: https://gitdiagram.com/javitorres/datalakestudio
- Repository: https://github.com/javitorres/datalakestudio

## Overview

##### Project Type & Purpose
- Datalake Studio is a full-stack data exploration and management tool. Its goal is to allow users to load, explore, manipulate, and expose large datasets using DuckDB for high-performance SQL analytics. It also integrates data enrichment from external APIs (including ChatGPT for SQL assistance), mapping for spatial data, support for multiple data formats, and capabilities for exposing data via APIs.

##### File Structure
- There are two major directories:
- Client: Contains a Vue-based frontend application (evidenced by files like App.vue, various components, assets, and a Vite config). It includes Docker configuration (Dockerfile) and local documentation.
- Server: Contains a Python-based backend with configuration files, a Dockerfile, service scripts, routes, and models that handle different types of requests (data loading, query processing, API enrichment, etc.). This back end also handles connections to the local DuckDB database and manages external integrations (e.g., S3, ChatGPT, remote databases).
- Docker-compose.yml file which orchestrates both the client and server containers, indicating containerized deployment.

##### Key Architectural Components
a. Frontend (Client):
- Vue Application: Built with Vue 3 and organized into components such as ApiRetriever, ChatGptAgent, CodeEditor, Map, QueryPanel, etc.
- Assets & Config: Static assets (CSS, images) and configuration files.
- Interaction: It connects to the backend via REST API calls.

b. Backend (Server):
- API Controllers: Various route modules (e.g., api_controller, apiretriever_controller, database_controller, gpt_controller) indicate a RESTful API design.
- Services: Dedicated services for each functionality (e.g., chatGPTService, databaseService, s3Service, queriesService) to abstract business logic.
- Models: Data Transfer Objects (DTOs) to standardize request inputs.
- Configuration & Secrets: YAML files for configurations and credentials.
- Data Persistence: Integration with DuckDB utilizing the “data/datalakeStudio.db” specified in configuration.

c. Integration Components:
- External APIs: ChatGPT services (for SQL assistants) and potential API endpoints for remote data enrichment.
- External Data Sources: Capability for loading data from local files, remote URLs, S3 buckets, and PostgreSQL databases.
- Mapping & Visualization: Integration with Mapbox (as per the secrets and map components).

d. Containerization:
- Dockerfiles in both client and server directories, as well as a docker-compose file. These provide the deployment strategy for running both components in containers.

##### Relationships & Data Flow
- The Client (frontend) sends HTTP requests (via REST APIs) to the Server.
- The Server processes these requests through its defined routes and then calls upon its service layer to:
- Query, transform, or load data into/from DuckDB.
- Enrich data through external API calls (ChatGPT or remote APIs).
- Interface with S3, remote databases, or other data sources.
- Responses (data, query results, visualizations) flow back to the Client which renders them.
- Docker Compose orchestrates the client and server containers for a cohesive deployment environment.

##### Architectural Patterns & Design Principles
- Separation of Concerns: Clearly divided front end (UI) and backend (API & business logic).
- Modularization: Both client components and server modules (controllers, services, models) are well isolated to handle specific tasks.
- Containerization: Use of Docker and Docker Compose for environment consistency and isolation.
- Integration with External Systems: Use of standard APIs and configuration files to handle integration points (ChatGPT, Mapbox, S3, PostgreSQL).

## Diagram (Mermaid)

```mermaid
flowchart TD

    %% Frontend Section
    subgraph "Client (Frontend)"
        direction TB
        vueApp("Vue Application"):::frontend
        queryPanel("Query Panel"):::frontend
        chatGptAgent("ChatGPT Assistance"):::frontend
        dataSelector("Data Selector"):::frontend
        mapViz("Map Visualization"):::frontend
        apiRetriever("API Retriever"):::frontend
        assets("Assets & Config"):::frontend
        
        vueApp --> queryPanel
        vueApp --> chatGptAgent
        vueApp --> dataSelector
        vueApp --> mapViz
        vueApp --> apiRetriever
    end

    %% Backend Section
    subgraph "Server (Backend)"
        direction TB
        apictrls("API Controllers"):::backend
        services("Services Layer"):::backend
        models("Models/DTOs"):::backend
        config("Configurations & Secrets"):::backend
        integration("External Integrations"):::backend
        dbServer("DuckDB Database"):::database
        
        apictrls --> services
        services --> models
        services --> dbServer
        services --> integration
    end

    %% Containerization & Deployment Section
    subgraph "Containerization & Deployment"
        direction TB
        dockerCompose("Docker Compose"):::deployment
        clientContainer("Client Container"):::deployment
        serverContainer("Server Container"):::deployment

        dockerCompose --> clientContainer
        dockerCompose --> serverContainer
    end

    %% Data Flow & Interaction
    vueApp -->|"REST_API_Request"| apictrls
    apictrls -->|"Query_Response"| vueApp
    services -->|"Query_Response"| vueApp
    services -->|"Data_Load_Query"| dbServer
    services -->|"External_API_Call"| integration

    %% External Integrations Detail
    integration -->|"ChatGPT_API_Call"| chatGptExternal("ChatGPT External"):::external
    integration -->|"S3_Operation"| s3External("S3 External"):::external
    integration -->|"RemoteDB_Call"| remoteDb("Remote Database"):::external
    integration -->|"Map_Service"| mapbox("Mapbox Service"):::external

    %% Click Events for Frontend Components
    click vueApp "https://github.com/javitorres/datalakestudio/blob/main/client/src/App.vue"
    click queryPanel "https://github.com/javitorres/datalakestudio/blob/main/client/src/components/QueryPanel.vue"
    click chatGptAgent "https://github.com/javitorres/datalakestudio/blob/main/client/src/components/ChatGptAgent.vue"
    click dataSelector "https://github.com/javitorres/datalakestudio/blob/main/client/src/components/DataSelector.vue"
    click mapViz "https://github.com/javitorres/datalakestudio/blob/main/client/src/components/Map.vue"
    click apiRetriever "https://github.com/javitorres/datalakestudio/blob/main/client/src/components/ApiRetriever.vue"
    click assets "https://github.com/javitorres/datalakestudio/tree/main/client/src/assets"

    %% Click Events for Backend Components
    click apictrls "https://github.com/javitorres/datalakestudio/tree/main/server/routes"
    click services "https://github.com/javitorres/datalakestudio/tree/main/server/services"
    click models "https://github.com/javitorres/datalakestudio/tree/main/server/model"
    click config "https://github.com/javitorres/datalakestudio/blob/main/server/config.yml"

    %% Click Events for Containerization
    click dockerCompose "https://github.com/javitorres/datalakestudio/blob/main/docker-compose.yml"
    click clientContainer "https://github.com/javitorres/datalakestudio/tree/main/client/Dockerfile"
    click serverContainer "https://github.com/javitorres/datalakestudio/tree/main/server/Dockerfile"

    %% Styles
    classDef frontend fill:#AED6F1,stroke:#1B4F72,stroke-width:2px;
    classDef backend fill:#ABEBC6,stroke:#196F3D,stroke-width:2px;
    classDef database fill:#F9E79F,stroke:#B7950B,stroke-width:2px;
    classDef external fill:#F5CBA7,stroke:#BA4A00,stroke-width:2px;
    classDef deployment fill:#D2B4DE,stroke:#6C3483,stroke-width:2px;
```
