# ptdat4823/sql-injection-demo architecture

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

- Interactive diagram: https://gitdiagram.com/ptdat4823/sql-injection-demo
- Repository: https://github.com/ptdat4823/sql-injection-demo

## Overview

##### Project Type and Purpose
- This is a full-stack demonstration app intended to showcase SQL injection vulnerabilities.
- The project is divided cleanly between a front-end (client-side UI built in TypeScript/React using Vite) and a back-end (Node.js server handling API requests and database connectivity) along with an external SQL script that likely sets up the vulnerable database.
- The focus is on login/authentication (note files like “services/auth.js”, “front-end/src/Login.tsx”, and “database/sql_injection_dtb_account.sql”) and JWT handling, making security concerning SQL injection central to the demo.

##### File Structure
- Top-level directories:
- “front-end”: Contains the client-side code (React components, contexts, styling, and build configuration) which handles the user interface and client interactions.
- “back-end”: Contains server code including configuration files (in “config”), database utilities (in “database”), and service logic (in “services” for authentication and JWT management). The “index.js” is the entry point.
- “database”: Includes at least one SQL script for setting up a database table with an obvious SQL injection vulnerability.
- The naming and organization suggest the back-end is broken into concerns around configuration, database access/utility functions, and service logic for authentication and JWT token generation.
- The front-end clearly separates application assets, configuration, and source code.

a. Front-End Component:
- Details like “React / TypeScript” and “Vite” configuration, and note key UI components such as “Login”, “Home”, and shared context (“AuthContext”).
b. Back-End Component:
- Inside it, break down:
- “Configuration”: Highlight the existence of database configuration (config/database.js).
- “Database Layer”: Represent the modules (auth.js, util.js) responsible for interfacing with SQL.
- “Services”: Identify the authentication service and JWT management (services/auth.js and services/jwt.js).
- Entry point (“index.js”) as the central starting point.
c. Database Component:
- That there is an external SQL script (sql_injection_dtb_account.sql) used for setting up the vulnerable table, and mention that this is the interaction point for SQL queries from the back-end.

##### Relationships and Data Flow
- From “Front-End Client” to “Back-End Server” indicating API calls (likely REST or similar) for login and data submission.
- From “Back-End Server” to “SQL Database” indicating SQL query interactions (especially in the authentication process, which could be vulnerable to SQL Injection).
- That the “Back-End Server” both authenticates users and issues JWT tokens (connecting the “Auth Service” and “JWT Service”).

##### Architectural Patterns / Design Principles
- Separation of concerns:
- Client-side and server-side responsibilities are clearly divided.
- Within the back-end, configuration, database utilities, and services are separated into distinct modules.
- That the system is built for demonstration purposes – showcasing how a typical login flow might be exploited by SQL injection if proper sanitization is not performed.

##### Relevant Technologies and Libraries
- Front-End: React, TypeScript, Vite, ESLint for style enforcement.
- Back-End: Node.js (with Express may be assumed though not explicitly seen), JWT for token management.
- Database: An SQL database configured via the provided SQL script.

## Diagram (Mermaid)

```mermaid
flowchart TD

    %% Front-End Subgraph
    subgraph "Front-End Client"
        FE1["Login (React)"]:::frontend
        FE2["Home (React)"]:::frontend
        FE3["Auth Context"]:::frontend
        FE4["Vite Config"]:::frontend
    end

    %% Back-End Subgraph
    subgraph "Back-End Server"
        BE1["Entry Point (index.js)"]:::backend
        BE2["Database Config (database.js)"]:::backend
        BE3["Database Layer (auth.js & util.js)"]:::backend
        BE4["Authentication Service (auth.js)"]:::backend
        BE5["JWT Service (jwt.js)"]:::backend
    end

    %% SQL Database Node
    DB["SQL Database"]:::database

    %% Connections from Front-End to Back-End
    FE1 -->|"API_Call"| BE1

    %% Back-End Internal Connections
    BE1 -->|"load_config"| BE2
    BE1 -->|"authenticate_user"| BE4
    BE4 -->|"execute_SQL_query"| BE3
    BE4 -->|"generate_JWT"| BE5
    BE3 -->|"run_query"| DB

    %% Click Events for Front-End Components
    click FE1 "https://github.com/ptdat4823/sql-injection-demo/blob/main/front-end/src/Login.tsx"
    click FE2 "https://github.com/ptdat4823/sql-injection-demo/blob/main/front-end/src/Home.tsx"
    click FE3 "https://github.com/ptdat4823/sql-injection-demo/blob/main/front-end/src/AuthContext.tsx"
    click FE4 "https://github.com/ptdat4823/sql-injection-demo/blob/main/front-end/vite.config.ts"

    %% Click Events for Back-End Components
    click BE1 "https://github.com/ptdat4823/sql-injection-demo/blob/main/back-end/index.js"
    click BE2 "https://github.com/ptdat4823/sql-injection-demo/blob/main/back-end/config/database.js"
    click BE3 "https://github.com/ptdat4823/sql-injection-demo/blob/main/back-end/database/auth.js"
    click BE3 "https://github.com/ptdat4823/sql-injection-demo/blob/main/back-end/database/util.js"
    click BE4 "https://github.com/ptdat4823/sql-injection-demo/blob/main/back-end/services/auth.js"
    click BE5 "https://github.com/ptdat4823/sql-injection-demo/blob/main/back-end/services/jwt.js"

    %% Click Event for SQL Database Setup Script
    click DB "https://github.com/ptdat4823/sql-injection-demo/blob/main/database/sql_injection_dtb_account.sql"

    %% Styling
    classDef frontend fill:#AED6F1,stroke:#1B4F72,stroke-width:2px;
    classDef backend fill:#A9DFBF,stroke:#196F3D,stroke-width:2px;
    classDef database fill:#F9E79F,stroke:#B7950B,stroke-width:2px;
```
