# itsshashanksp/generic_sql_rest_api_framework architecture

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

- Interactive diagram: https://gitdiagram.com/itsshashanksp/generic_sql_rest_api_framework
- Repository: https://github.com/itsshashanksp/generic_sql_rest_api_framework

## Overview

This is a reusable PHP SQL REST API framework: clients submit JSON operations, the API authenticates and authorizes the principal, validates requests, builds safe database operations, and returns JSON results. Its domain stages include authentication and permissions, queries and routines, generic writes, metadata and SQL Resources, and database execution. Separate product branches provide loopback administration and a non-executing SQL-to-request parser. The source index and excerpts establish several internal calls; broader capability links use the README, and unsampled wiring is not inferred.

Main entry points: [`api/index.php`](https://github.com/itsshashanksp/generic_sql_rest_api_framework/blob/dev/api/index.php) (JSON API), [`app/Controllers/QueryController.php`](https://github.com/itsshashanksp/generic_sql_rest_api_framework/blob/dev/app/Controllers/QueryController.php) (Query Controller), [`sqlparser/src/SqlParserRequestHandler.php`](https://github.com/itsshashanksp/generic_sql_rest_api_framework/blob/dev/sqlparser/src/SqlParserRequestHandler.php) (Parser Handler), [`admin/api.php`](https://github.com/itsshashanksp/generic_sql_rest_api_framework/blob/dev/admin/api.php) (Admin Console and API)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_api["API Request Flow"]
  node_api_entry["JSON API<br/>[index.php]"]
  node_query_controller["Query Controller"]
  node_query_validation["Query Validation"]
  node_response["JSON Response<br/>[Response.php]"]
end

subgraph group_data["Database Operations"]
  node_query_service["Query Service<br/>[QueryService.php]"]
  node_query_repo["Query Repository"]
  node_write_service["Write Operations<br/>[WriteService.php]"]
  node_metadata_service["Metadata Operations"]
  node_sql_resources["SQL Resources"]
  node_query_engine["Query Engine<br/>[QueryEngine.php]"]
  node_database["Database Access<br/>[Database.php]"]
end

subgraph group_management["Management and Security"]
  node_auth["Authentication"]
  node_authorization["API Authorization"]
  node_admin_plane["Admin Console and API<br/>[api.php]"]
  node_admin_config["Admin Configuration"]
  node_backup["Configuration Backup"]
  node_runtime_config["Runtime Configuration"]
  node_health["Health Endpoints<br/>[health.php]"]
end

subgraph group_parser["SQL Parser"]
  node_parser_endpoint["Parser Endpoint<br/>[index.php]"]
  node_parser_handler["Parser Handler"]
  node_sql_parser["SQL Parser<br/>[SqlParser.php]"]
  node_sql_generator["Request Generator<br/>[SqlGenerator.php]"]
end

node_client(("API Client"))
node_sql_database[("SQL Database")]

node_client -->|"submits JSON"| node_api_entry
node_api_entry -->|"runs middleware"| node_auth
node_api_entry -->|"runs middleware"| node_authorization
node_api_entry -->|"routes operations"| node_query_controller
node_query_controller -->|"delegates"| node_query_service
node_query_controller -->|"validates request"| node_query_validation
node_query_service -->|"delegates"| node_query_repo
node_query_repo -->|"executes SQL"| node_query_engine
node_query_engine -->|"uses connection"| node_database
node_database -->|"executes statements"| node_sql_database
node_api_entry -->|"supports CRUD"| node_write_service
node_api_entry -->|"supports metadata"| node_metadata_service
node_api_entry -->|"supports resources"| node_sql_resources
node_api_entry -->|"returns envelope"| node_response
node_admin_plane -->|"manages settings"| node_admin_config
node_admin_plane -->|"supports backups"| node_backup
node_admin_config -->|"loads configuration"| node_runtime_config
node_api_entry -->|"offers health checks"| node_health
node_client -->|"submits SQL"| node_parser_endpoint
node_parser_endpoint -->|"dispatches to"| node_parser_handler
node_parser_handler -->|"generates request"| node_sql_generator
node_sql_parser -.->|"parses SQL"| node_parser_handler

click node_api_entry "https://github.com/itsshashanksp/generic_sql_rest_api_framework/blob/dev/api/index.php"
click node_auth "https://github.com/itsshashanksp/generic_sql_rest_api_framework/blob/dev/app/Middleware/AuthenticationMiddleware.php"
click node_authorization "https://github.com/itsshashanksp/generic_sql_rest_api_framework/blob/dev/app/Middleware/AuthorizationMiddleware.php"
click node_query_controller "https://github.com/itsshashanksp/generic_sql_rest_api_framework/blob/dev/app/Controllers/QueryController.php"
click node_query_validation "https://github.com/itsshashanksp/generic_sql_rest_api_framework/blob/dev/app/Requests/QueryRequestValidator.php"
click node_query_service "https://github.com/itsshashanksp/generic_sql_rest_api_framework/blob/dev/app/Services/QueryService.php"
click node_query_repo "https://github.com/itsshashanksp/generic_sql_rest_api_framework/blob/dev/app/Repositories/QueryRepository.php"
click node_write_service "https://github.com/itsshashanksp/generic_sql_rest_api_framework/blob/dev/app/Services/WriteService.php"
click node_metadata_service "https://github.com/itsshashanksp/generic_sql_rest_api_framework/blob/dev/app/Services/MetadataService.php"
click node_sql_resources "https://github.com/itsshashanksp/generic_sql_rest_api_framework/blob/dev/app/Resources/SqlResourceDiscovery.php"
click node_query_engine "https://github.com/itsshashanksp/generic_sql_rest_api_framework/blob/dev/core/QueryEngine.php"
click node_database "https://github.com/itsshashanksp/generic_sql_rest_api_framework/blob/dev/core/Database.php"
click node_response "https://github.com/itsshashanksp/generic_sql_rest_api_framework/blob/dev/core/Response.php"
click node_admin_plane "https://github.com/itsshashanksp/generic_sql_rest_api_framework/blob/dev/admin/api.php"
click node_admin_config "https://github.com/itsshashanksp/generic_sql_rest_api_framework/blob/dev/app/Repositories/AdminConfigurationRepository.php"
click node_backup "https://github.com/itsshashanksp/generic_sql_rest_api_framework/blob/dev/app/Backup/ApplicationBackupManager.php"
click node_runtime_config "https://github.com/itsshashanksp/generic_sql_rest_api_framework/blob/dev/app/Configuration/RuntimeConfiguration.php"
click node_health "https://github.com/itsshashanksp/generic_sql_rest_api_framework/blob/dev/api/health.php"
click node_parser_endpoint "https://github.com/itsshashanksp/generic_sql_rest_api_framework/blob/dev/sqlparser/index.php"
click node_parser_handler "https://github.com/itsshashanksp/generic_sql_rest_api_framework/blob/dev/sqlparser/src/SqlParserRequestHandler.php"
click node_sql_parser "https://github.com/itsshashanksp/generic_sql_rest_api_framework/blob/dev/sqlparser/src/SqlParser.php"
click node_sql_generator "https://github.com/itsshashanksp/generic_sql_rest_api_framework/blob/dev/sqlparser/src/SqlGenerator.php"

classDef toneNeutral fill:#f8fafc,stroke:#334155,stroke-width:1.5px,color:#0f172a
classDef toneBlue fill:#dbeafe,stroke:#2563eb,stroke-width:1.5px,color:#172554
classDef toneAmber fill:#fef3c7,stroke:#d97706,stroke-width:1.5px,color:#78350f
classDef toneMint fill:#dcfce7,stroke:#16a34a,stroke-width:1.5px,color:#14532d
classDef toneRose fill:#ffe4e6,stroke:#e11d48,stroke-width:1.5px,color:#881337
classDef toneIndigo fill:#e0e7ff,stroke:#4f46e5,stroke-width:1.5px,color:#312e81
classDef toneTeal fill:#ccfbf1,stroke:#0f766e,stroke-width:1.5px,color:#134e4a
class node_api_entry,node_query_controller,node_query_validation,node_response,node_client toneBlue
class node_query_service,node_query_repo,node_write_service,node_metadata_service,node_sql_resources,node_query_engine,node_database,node_sql_database toneAmber
class node_auth,node_authorization,node_admin_plane,node_admin_config,node_backup,node_runtime_config,node_health toneMint
class node_parser_endpoint,node_parser_handler,node_sql_parser,node_sql_generator toneRose
```

## Components

### API Request Flow

- [JSON API](https://github.com/itsshashanksp/generic_sql_rest_api_framework/blob/dev/api/index.php): `api/index.php`
- [Query Controller](https://github.com/itsshashanksp/generic_sql_rest_api_framework/blob/dev/app/Controllers/QueryController.php): `app/Controllers/QueryController.php`
- [Query Validation](https://github.com/itsshashanksp/generic_sql_rest_api_framework/blob/dev/app/Requests/QueryRequestValidator.php): `app/Requests/QueryRequestValidator.php`
- [JSON Response](https://github.com/itsshashanksp/generic_sql_rest_api_framework/blob/dev/core/Response.php): `core/Response.php`

### Database Operations

- [Query Service](https://github.com/itsshashanksp/generic_sql_rest_api_framework/blob/dev/app/Services/QueryService.php): `app/Services/QueryService.php`
- [Query Repository](https://github.com/itsshashanksp/generic_sql_rest_api_framework/blob/dev/app/Repositories/QueryRepository.php): `app/Repositories/QueryRepository.php`
- [Write Operations](https://github.com/itsshashanksp/generic_sql_rest_api_framework/blob/dev/app/Services/WriteService.php): `app/Services/WriteService.php`
- [Metadata Operations](https://github.com/itsshashanksp/generic_sql_rest_api_framework/blob/dev/app/Services/MetadataService.php): `app/Services/MetadataService.php`
- [SQL Resources](https://github.com/itsshashanksp/generic_sql_rest_api_framework/blob/dev/app/Resources/SqlResourceDiscovery.php): `app/Resources/SqlResourceDiscovery.php`
- [Query Engine](https://github.com/itsshashanksp/generic_sql_rest_api_framework/blob/dev/core/QueryEngine.php): `core/QueryEngine.php`
- [Database Access](https://github.com/itsshashanksp/generic_sql_rest_api_framework/blob/dev/core/Database.php): `core/Database.php`

### Management and Security

- [Authentication](https://github.com/itsshashanksp/generic_sql_rest_api_framework/blob/dev/app/Middleware/AuthenticationMiddleware.php): `app/Middleware/AuthenticationMiddleware.php`
- [API Authorization](https://github.com/itsshashanksp/generic_sql_rest_api_framework/blob/dev/app/Middleware/AuthorizationMiddleware.php): `app/Middleware/AuthorizationMiddleware.php`
- [Admin Console and API](https://github.com/itsshashanksp/generic_sql_rest_api_framework/blob/dev/admin/api.php): `admin/api.php`
- [Admin Configuration](https://github.com/itsshashanksp/generic_sql_rest_api_framework/blob/dev/app/Repositories/AdminConfigurationRepository.php): `app/Repositories/AdminConfigurationRepository.php`
- [Configuration Backup](https://github.com/itsshashanksp/generic_sql_rest_api_framework/blob/dev/app/Backup/ApplicationBackupManager.php): `app/Backup/ApplicationBackupManager.php`
- [Runtime Configuration](https://github.com/itsshashanksp/generic_sql_rest_api_framework/blob/dev/app/Configuration/RuntimeConfiguration.php): `app/Configuration/RuntimeConfiguration.php`
- [Health Endpoints](https://github.com/itsshashanksp/generic_sql_rest_api_framework/blob/dev/api/health.php): `api/health.php`

### SQL Parser

- [Parser Endpoint](https://github.com/itsshashanksp/generic_sql_rest_api_framework/blob/dev/sqlparser/index.php): `sqlparser/index.php`
- [Parser Handler](https://github.com/itsshashanksp/generic_sql_rest_api_framework/blob/dev/sqlparser/src/SqlParserRequestHandler.php): `sqlparser/src/SqlParserRequestHandler.php`
- [SQL Parser](https://github.com/itsshashanksp/generic_sql_rest_api_framework/blob/dev/sqlparser/src/SqlParser.php): `sqlparser/src/SqlParser.php`
- [Request Generator](https://github.com/itsshashanksp/generic_sql_rest_api_framework/blob/dev/sqlparser/src/SqlGenerator.php): `sqlparser/src/SqlGenerator.php`

### Other components

- **API Client**
- **SQL Database**

## Connections

- API Client → JSON API: submits JSON (evidence: `README.md`)
- JSON API → Authentication: runs middleware (evidence: `api/index.php`)
- JSON API → API Authorization: runs middleware (evidence: `api/index.php`)
- JSON API → Query Controller: routes operations (evidence: `api/index.php`)
- Query Controller → Query Service: delegates (evidence: `app/Controllers/QueryController.php`)
- Query Controller → Query Validation: validates request (evidence: `api/index.php`)
- Query Service → Query Repository: delegates (evidence: `app/Services/QueryService.php`)
- Query Repository → Query Engine: executes SQL (evidence: `app/Repositories/QueryRepository.php`)
- Query Engine → Database Access: uses connection (evidence: `core/QueryEngine.php`)
- Database Access → SQL Database: executes statements (evidence: `README.md`)
- JSON API → Write Operations: supports CRUD (evidence: `README.md`)
- JSON API → Metadata Operations: supports metadata (evidence: `README.md`)
- JSON API → SQL Resources: supports resources (evidence: `README.md`)
- JSON API → JSON Response: returns envelope (evidence: `README.md`)
- Admin Console and API → Admin Configuration: manages settings (evidence: `README.md`)
- Admin Console and API → Configuration Backup: supports backups (evidence: `README.md`)
- Admin Configuration → Runtime Configuration: loads configuration (evidence: `app/Repositories/AdminConfigurationRepository.php`)
- JSON API → Health Endpoints: offers health checks (evidence: `README.md`)
- API Client → Parser Endpoint: submits SQL (evidence: `README.md`)
- Parser Endpoint → Parser Handler: dispatches to (evidence: `sqlparser/index.php`)
- Parser Handler → Request Generator: generates request (evidence: `sqlparser/src/SqlParserRequestHandler.php`)
- SQL Parser → Parser Handler: parses SQL
