CoolLib — Containerized Library Ecosystem: A Clean Architecture Implementation
A high-performance distributed system built on Clean Architecture, with a Dockerized backend orchestrating core business logic via Spring Boot and PostgreSQL. The architecture leverages Cloudflare D1 for edge-side persistence of telemetry, while Workers provide a reactive observability layer. Secure, zero-trust connectivity is maintained via Cloudflare Tunnels, delivering a seamless experience to Android (Compose) and iOS (SwiftUI) clients.
Project Overview
CoolLib Backend is a mission-critical RESTful service built with Spring Boot and Kotlin. Beyond standard CRUD, it orchestrates complex business state machines and implements Cloudflare-native infrastructure to ensure global low-latency data synchronization and secure asset management across the mobile ecosystem.
Key Technical Wins
Clean Architecture
Adheres to Clean Architecture and DDD principles. It maintains a pure domain model by strictly decoupling JPA Entities from API DTOs via custom mapping layers, preventing database leakage into the presentation tier.
Edge Persistence & D1
Implements Cloudflare D1 as a globally distributed SQLite layer. It offloads high-frequency telemetry and health metrics from the primary PostgreSQL instance, ensuring the core database remains optimized for ACID-compliant transactions.
Stateless Security & Tunnels
Orchestrates Spring Security + JWT for stateless, mobile-first authentication. The backend origin is shielded by Cloudflare Tunnels, eliminating public entry points and ensuring a Zero-Trust connectivity model.
Reactive Observability Pipeline
Engineered an observability stack using Cloudflare Workers to intercept and analyze traffic patterns in real-time. This provides instant insights into API performance without introducing latency to the Spring Boot origin.
System Architecture
Architecture Design
Cloudflare Edge-secured system with Dockerized backend and real-time observability.
Security & Acceleration Strategy
Hybrid Security & Caching Architecture
Distributed authentication with edge-level performance optimization.
Architectural Highlights
- Latency Reduction: Read-heavy endpoints (like book search) are cached at 300+ global edge locations.
- Zero Public Ports: The Spring Boot server remains invisible to the public internet via Cloudflare Tunnel.
- Separation of Concerns: Security is handled at the Origin (JWT), while delivery is optimized at the Edge.
Tech Stack
-
Core Framework:
Spring Boot 3.x,Kotlin,Gradle -
Edge Infrastructure:
Cloudflare D1 (SQL),Workers,R2 (S3 Storage),Tunnels -
Data & Security:
PostgreSQL,Spring Data JPA,JWT,Spring Security -
DevOps:
Docker,Nginx,GitHub Actions (CI/CD)
Core Features
Identity Management
Advanced Search
Transaction Logic
Deployment Stack
| Method | Endpoint | Description | Auth |
|---|---|---|---|
| POST | /api/auth/login |
Verify credentials and issue a JWT Access Token. | |
| POST | /api/borrow/scan |
Process borrowing via Barcode/ISBN scan. In Dev | |
| GET | /api/stats/loans |
Fetch aggregate data of active loans and trends. Planned | |
| GET | /api/users/profile |
Retrieve identity claims from the decrypted JWT payload. | |
| GET | /api/auth/validate |
Check if the current token is expired or blacklisted. |
| Method | Endpoint | Description | Auth |
|---|---|---|---|
| GET | /api/books/search |
Multi-criteria filtering by Title, Author, Publisher, and Year. | |
| GET | /api/books/fuzzy |
Fuzzy search using Levenshtein Distance or partial matching logic. In Dev | |
| GET | /api/books/recommend |
Content-based filtering using User Borrowing History. Planned | |
| GET | /api/books/isbn/{isbn} |
Direct lookup via 10 or 13-digit International Standard Book Number. |
Transaction Processing Pipeline
ACID SECUREuserId & roles from JWT claims.SELECT FOR UPDATE to prevent race conditions.Persist LoanRecord & update Inventory.
Managed by Spring @Transactional logic.
Zero-Trust Tunnel
Utilizing Cloudflare Tunnels to expose the API via encrypted outbound connections, eliminating attack surfaces and public-facing ports.
Edge & R2 Storage
Offloading media to Cloudflare R2 with zero egress fees, combined with Edge Caching to deliver assets at millisecond speeds.
Docker Orchestration
Encapsulating Spring Boot, Nginx, and Postgres within Docker Compose for consistent environments and automated deployment.
Traffic Architecture
Developed with passion by Ryan Su © 2026