# mohammadalqaisyyy/decentralized_cluster-based_nosql_db_system architecture

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

- Interactive diagram: https://gitdiagram.com/mohammadalqaisyyy/decentralized_cluster-based_nosql_db_system
- Repository: https://github.com/mohammadalqaisyyy/decentralized_cluster-based_nosql_db_system

## Overview

##### Project type and purpose
- This is a distributed, cluster-based NoSQL database system composed of multiple Spring-Boot microservices running in Docker containers.
- Purpose: demonstrate a decentralized database where each node stores JSON documents on its filesystem and coordinates reads/writes via REST and Kafka messaging to improve throughput and security.

##### File structure
- Top-level directories (services)
- BootstrapNode – the “seed” service that tracks cluster membership and responds to client bootstrap requests
- node_1, node_2, … node_5 – five identical data-store nodes, each running its own Spring Boot application, local JSON file store, and Kafka producer/consumer
- demo – a web-app client (JSP front end + Spring MVC controllers) illustrating login and CRUD against the cluster
- docker-compose.yml – orchestrates all services (BootstrapNode, node services, demo app, plus Kafka broker/container)
- Key packages under each node_x:
- config – Spring Security, RSA key props, RestTemplate, Kafka producer/consumer setup
- controller – REST endpoints for auth, bootstrap, client queries, node info
- databaseManager – file-based DB handler, collections, documents, index updaters
- redirection – broadcastQuery and affinity-based routing of operations
- commands – handlers for database/collection/document operations
- Resources: application.properties, certs (public/private PEM), under-resource DB folders containing JSON files + index files.

##### README for additional insights
- Confirms Java+Spring, Docker, and Kafka usage
- Emphasis on multi-node architecture for speed and security

##### Elements
- Containers (rectangles) for: Demo App, BootstrapNode, Node_1…Node_5, Kafka Broker
- Blue for web tier (Demo front end)
- Green for control plane (Bootstrap)
- Orange for data nodes
- Yellow for messaging layer (Kafka)
- Ports/endpoints where relevant (e.g., 8080 REST, 9092 Kafka)

##### Detail
- Call out index files under each node for quick lookups
- Certificate files feeding into Spring Security for each node
- Both synchronous (REST) and asynchronous (Kafka) flows

## Diagram (Mermaid)

```mermaid
flowchart TD
    %% Frontend Layer
    subgraph "Demo Web App" 
        direction TB
        DemoApp["DemoApplication"]:::frontend
        Controllers["Controllers"]:::frontend
        Config["Config"]:::frontend
        Views["JSP Front-end"]:::frontend
        DemoApp --> Controllers
        DemoApp --> Config
        DemoApp --> Views
    end

    %% Control Plane
    subgraph "Bootstrap Service" 
        direction TB
        BootstrapApp["BootstrapNodeApplication"]:::control
        BootstrapCtrl["BootstrapController / ClientController"]:::control
        NodesModel["Nodes Model"]:::control
        Properties["application.properties"]:::control
        BootstrapApp --> BootstrapCtrl
        BootstrapApp --> NodesModel
        BootstrapApp --> Properties
    end

    %% Messaging Layer
    KafkaBroker["Kafka Broker (9092)"]:::messaging

    %% Data Nodes Cluster
    subgraph "Cluster Nodes" 
        direction TB
        subgraph "Node 1" 
            direction TB
            NodeApp1["NodeApplication"]:::data
            Controllers1["Auth / Bootstrap / Client / Nodes / Home Controllers"]:::data
            SecurityConfig1["SecurityConfig / RsaKeyProperties"]:::data
            KafkaConfig1["KafkaConfig / Producer / Consumer"]:::data
            Listener1["KafkaQueriesListener"]:::data
            Commands1["Command Handlers"]:::data
            Redirection1["BroadcastQuery & Affinity"]:::data
            DBManager1["DatabaseHandler & Indexing"]:::data
            FileStore1["Local JSON Store & Indexes"]:::fs
            Certs1["certs/private.pem & public.pem"]:::data
            Users1["users.json"]:::data

            NodeApp1 --> Controllers1
            NodeApp1 --> SecurityConfig1
            NodeApp1 --> KafkaConfig1
            NodeApp1 --> Listener1
            NodeApp1 --> Commands1
            NodeApp1 --> Redirection1
            NodeApp1 --> DBManager1
            DBManager1 --> FileStore1
            NodeApp1 --> Certs1
            NodeApp1 --> Users1
        end
        %% Node 2-5 are identical
        subgraph "Node 2..5" 
            direction TB
            Nodes["Node 2..5"]:::data
        end
    end

    %% Client interactions
    Browser["Browser"]:::external
    Browser -->|"HTTP"| DemoApp
    DemoApp -->|"REST"| BootstrapApp
    DemoApp -->|"REST"| Nodes
    DemoApp -->|"REST"| NodeApp1

    %% Bootstrap to Cluster
    BootstrapApp -->|"REST: bootstrap"| NodeApp1
    BootstrapApp -->|"REST: bootstrap"| Nodes

    %% Messaging interactions
    NodeApp1 -->|"Kafka publish/subscribe"| KafkaBroker
    Nodes -->|"Kafka publish/subscribe"| KafkaBroker

    %% File I/O
    FileStore1 -->|"Filesystem I/O"| DBManager1

    %% Orchestration
    DockerCompose["docker-compose.yml"]:::orchestration

    DockerCompose --> DemoApp
    DockerCompose --> BootstrapApp
    DockerCompose --> NodeApp1
    DockerCompose --> Nodes
    DockerCompose --> KafkaBroker

    %% Click Events
    click DemoApp "https://github.com/mohammadalqaisyyy/decentralized_cluster-based_nosql_db_system/blob/main/demo/src/main/java/com/demo/sgs/demo/DemoApplication.java"
    click Controllers "https://github.com/mohammadalqaisyyy/decentralized_cluster-based_nosql_db_system/tree/main/demo/src/main/java/com/demo/sgs/demo/controller/"
    click Config "https://github.com/mohammadalqaisyyy/decentralized_cluster-based_nosql_db_system/tree/main/demo/src/main/java/com/demo/sgs/demo/config/"
    click Views "https://github.com/mohammadalqaisyyy/decentralized_cluster-based_nosql_db_system/tree/main/demo/src/main/webapp/WEB-INF/views/"
    click BootstrapApp "https://github.com/mohammadalqaisyyy/decentralized_cluster-based_nosql_db_system/blob/main/BootstrapNode/src/main/java/com/example/BootstrapNode/BootstrapNodeApplication.java"
    click BootstrapCtrl "https://github.com/mohammadalqaisyyy/decentralized_cluster-based_nosql_db_system/blob/main/BootstrapNode/src/main/java/com/example/BootstrapNode/BootstrapController.java"
    click BootstrapCtrl "https://github.com/mohammadalqaisyyy/decentralized_cluster-based_nosql_db_system/blob/main/BootstrapNode/src/main/java/com/example/BootstrapNode/ClientController.java"
    click NodesModel "https://github.com/mohammadalqaisyyy/decentralized_cluster-based_nosql_db_system/blob/main/BootstrapNode/src/main/java/com/example/BootstrapNode/Nodes.java"
    click Properties "https://github.com/mohammadalqaisyyy/decentralized_cluster-based_nosql_db_system/blob/main/BootstrapNode/src/main/resources/application.properties"
    click NodeApp1 "https://github.com/mohammadalqaisyyy/decentralized_cluster-based_nosql_db_system/blob/main/node_1/src/main/java/com/decentralizedDB/node/NodeApplication.java"
    click Controllers1 "https://github.com/mohammadalqaisyyy/decentralized_cluster-based_nosql_db_system/tree/main/node_1/src/main/java/com/decentralizedDB/node/controller/"
    click SecurityConfig1 "https://github.com/mohammadalqaisyyy/decentralized_cluster-based_nosql_db_system/blob/main/node_1/src/main/java/com/decentralizedDB/node/config/SecurityConfig.java"
    click SecurityConfig1 "https://github.com/mohammadalqaisyyy/decentralized_cluster-based_nosql_db_system/blob/main/node_1/src/main/java/com/decentralizedDB/node/config/RsaKeyProperties.java"
    click KafkaConfig1 "https://github.com/mohammadalqaisyyy/decentralized_cluster-based_nosql_db_system/blob/main/node_1/src/main/java/com/decentralizedDB/node/config/kafka/KafkaConfig.java"
    click Listener1 "https://github.com/mohammadalqaisyyy/decentralized_cluster-based_nosql_db_system/blob/main/node_1/src/main/java/com/decentralizedDB/node/KafkaQueriesListener.java"
    click Commands1 "https://github.com/mohammadalqaisyyy/decentralized_cluster-based_nosql_db_system/blob/main/node_1/src/main/java/com/decentralizedDB/node/commands/DocumentExecutor.java"
    click Redirection1 "https://github.com/mohammadalqaisyyy/decentralized_cluster-based_nosql_db_system/blob/main/node_1/src/main/java/com/decentralizedDB/node/redirection/BroadcastQuery.java"
    click DBManager1 "https://github.com/mohammadalqaisyyy/decentralized_cluster-based_nosql_db_system/blob/main/node_1/src/main/java/com/decentralizedDB/node/databaseManager/DatabaseHandler.java"
    click FileStore1 "https://github.com/mohammadalqaisyyy/decentralized_cluster-based_nosql_db_system/tree/main/node_1/src/main/resources/DB/"
    click Certs1 "https://github.com/mohammadalqaisyyy/decentralized_cluster-based_nosql_db_system/blob/main/node_1/src/main/resources/certs/private.pem"
    click Users1 "https://github.com/mohammadalqaisyyy/decentralized_cluster-based_nosql_db_system/blob/main/node_1/src/main/resources/users.json"
    click DockerCompose "https://github.com/mohammadalqaisyyy/decentralized_cluster-based_nosql_db_system/blob/main/docker-compose.yml"

    %% Styles
    classDef frontend fill:#D0E6FF,stroke:#0044CC,color:#0044CC
    classDef control fill:#E6F7D0,stroke:#228B22,color:#228B22
    classDef data fill:#FFE6CC,stroke:#FF8C00,color:#FF8C00
    classDef messaging fill:#FFF5CC,stroke:#DAA520,color:#DAA520
    classDef fs fill:#EEEEEE,stroke:#888888,color:#555555
    classDef orchestration fill:#F0F0F0,stroke:#555555,color:#555555
    classDef external fill:#F0F8FF,stroke:#87CEFA,color:#4682B4
```
