# arjuunns/dbms architecture

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

- Interactive diagram: https://gitdiagram.com/arjuunns/dbms
- Repository: https://github.com/arjuunns/dbms

## Overview

##### Main Components
- SQL Parsing Layer:
- There are modules like sqlparser.cpp/sqlparser.h and parser.cpp. These should be grouped as the “SQL Parser” component, responsible for reading, tokenizing, and understanding SQL commands.
- Database Management Component:
- Files like database.cpp/database.h indicate a “Database Manager” or “DB Engine,” which likely handles data storage, retrieval, and overall DB operations.
- Table Handling:
- The table.cpp/table.h files represent the “Table” component, encapsulating the structure and data of individual tables.
- Query Operations:
- Modules groupby.cpp, join.cpp, orderby.cpp represent various query operations which can be illustrated as distinct sub-components (or services) that the database engine uses to execute specific SQL operations.
- Global Variables/Utilities:
- globals.cpp/globals.h and functions.txt can be noted as supplementary modules that provide common definitions or utility functions required across the system.

##### Relationships and Interactions
- The entry point (main.cpp) orchestrates the overall flow: it receives user input (from command-line or file input like testcase1.txt) and passes it to the SQL Parser.
- The SQL Parser processes and translates SQL commands and then communicates them to the Database Manager.
- The Database Manager coordinates with the Table component to perform table-specific operations and uses the query operation modules (GroupBy, Join, OrderBy) to manipulate and retrieve data.
- Utility modules (globals and others) are used across these primary components for shared functions and constants.

##### Architectural Patterns or Design Principles
- The project demonstrates modular design by separating parsing, database operations, and query functionalities into distinct files.
- There’s a separation of concerns: parsing is isolated from data management, and table manipulation logic is encapsulated in its own files.
- The code organization follows a procedural or modular design rather than a full object-oriented approach, which can be seen in the division of responsibilities across different files.

##### Technologies and Frameworks
- This is a pure C/C++ code project, compiled using a Makefile.

##### Elements
- Clear Labels: Make sure each component (Main Controller, SQL Parser, Database Manager, Table, Query Operations like GroupBy, Join, OrderBy, Global Utilities) is clearly labeled.
- If applicable, show feedback or error reporting flowing backwards.

## Diagram (Mermaid)

```mermaid
flowchart TD
    %% Top Layer
    A["User Input (testcase1.txt)"]:::input

    %% Middle Layer
    B["Main Controller"]:::entry

    %% SQL Parsing Layer
    subgraph "SQL Parsing Layer"
        C["SQL Parser"]:::process
    end

    %% Global Utilities (used across layers)
    D["Global Utilities"]:::utilities

    %% Bottom Layer
    E["Database Manager"]:::process
    F["Table Handler"]:::table
    subgraph "Query Operations"
        G["Join"]:::query
        H["Group By"]:::query
        I["Order By"]:::query
    end

    %% Connections
    A -->|"triggers"| B
    B -->|"initiates"| C
    B -->|"uses"| D
    C -->|"parses_to"| E
    E -->|"operates_on"| F
    E -->|"executes"| G
    E -->|"executes"| H
    E -->|"executes"| I
    C -.->|"depends_on"| D
    E -.->|"depends_on"| D

    %% Click Events
    click B "https://github.com/arjuunns/dbms/blob/main/main.cpp"
    click C "https://github.com/arjuunns/dbms/blob/main/sqlparser.cpp"
    click C "https://github.com/arjuunns/dbms/blob/main/sqlparser.h"
    click C "https://github.com/arjuunns/dbms/blob/main/parser.cpp"
    click E "https://github.com/arjuunns/dbms/blob/main/database.cpp"
    click E "https://github.com/arjuunns/dbms/blob/main/database.h"
    click F "https://github.com/arjuunns/dbms/blob/main/table.cpp"
    click F "https://github.com/arjuunns/dbms/blob/main/table.h"
    click H "https://github.com/arjuunns/dbms/blob/main/groupby.cpp"
    click G "https://github.com/arjuunns/dbms/blob/main/join.cpp"
    click I "https://github.com/arjuunns/dbms/blob/main/orderby.cpp"
    click D "https://github.com/arjuunns/dbms/blob/main/globals.cpp"
    click D "https://github.com/arjuunns/dbms/blob/main/globals.h"
    click D "https://github.com/arjuunns/dbms/blob/main/functions.txt"

    %% Styles
    classDef entry fill:#ADD8E6,stroke:#000,stroke-width:2px;
    classDef process fill:#90EE90,stroke:#000,stroke-width:2px;
    classDef utilities fill:#FFD700,stroke:#000,stroke-width:2px;
    classDef table fill:#EE82EE,stroke:#000,stroke-width:2px;
    classDef query fill:#FFA07A,stroke:#000,stroke-width:2px;
    classDef input fill:#D3D3D3,stroke:#000,stroke-width:2px;
```
