How 9tigerio/db2rest works
Project Type and Purpose
• DB2Rest is a Java-based, multi-module Maven project that provides an auto-generated, low-code REST API layer on top of any supported relational database. It’s primarily a backend service (Spring Boot), not a two-sided UI/DB app, with plugin-style support for different SQL dialects and pluggable authentication providers.
High-Level Modules / Components
a. api-rest (Spring Boot application)
b. auth (authentication filter + auth-provider plugins: API-key, Basic, JWT, UnKey)
c. rest-common & db2rest-common (shared DTOs, exception handlers, common config)
d. rdbms-common & rdbms-support (core JDBC routing, service layer for CRUD/RPC operations, RSQL parsing)
e. dialects/*-dialect (plugin modules supplying SQL templates and Dialect implementations per database)
f. external systems: supported relational databases (Postgres, MySQL, Oracle, MSSQL, MariaDB, …), Docker/Testcontainers for integration tests
Request Flow and Component Interactions
1. Client → HTTP(S)
2. api-rest: incoming request enters Spring’s DispatcherServlet
3. AuthFilter (from auth module) intercepts → chooses AuthProvider plugin → validates credentials → on failure throws AuthenticationFailedException
4. DatabaseContextRequestInterceptor sets the current database context (multi-DB routing)
5. Controller layer (jdbc/rest/…) matches the REST verb/URL → invokes corresponding Controller (e.g., ReadController, CreateController)
6. Controllers delegate to RdbmsRestApi (generic entry point) → hands off to JdbcOperationService (rdbms-support)
7. JdbcOperationService uses RSQLParser + QueryRequest → builds SQL via Jinjava templates (in api-rest/src/main/resources/sql-templates)
8. RoutingDataSource (multi-DB support) picks the right DataSource bean based on context
9. JDBC driver + Dialect plugin generate SQL and execute on the target database
10. Results mapped to DTOs (db2rest-common) and returned as JSON
Architectural Patterns and Design Principles
• Layered Architecture:
• Presentation/API layer (Spring controllers, filters)
• Service/Business layer (JdbcOperationService, core CRUD/RPC services)
• Data/Infrastructure layer (RoutingDataSource, Dialect implementations, JDBC manager)
• Plugin/Extension Model: Dialect modules and Auth providers packaged as separate Maven sub-modules
• Convention over Configuration: Jinjava templates for SQL generation, standard REST paths
• Multi-tenancy/Multi-DB: DatabaseContextHolder + RoutingDataSource
• Use of TestContainers: integration tests spun up per-database via docker-compose/testcontainers
Final Checklist
[ ] Distinct layer boundaries (API, Auth, Common, Business, Data, External)
[ ] All main Maven modules shown as components