How 23520904/deepreader works
1. Overall shape
DeepReader is a polyglot, service-oriented platform. The browser talks to a single public entry point (web-module), which then delegates to backend services specialized by responsibility: orchestration (business-service), AI processing (ai-service), persistence (data-service), and vector search bridging (haystack-service).
2. Frontend boundary
The frontend/ app is a Next.js 16 + React 19 client that owns all user-facing screens: auth, library, reading, flashcards, profile, admin, help, and landing pages. It does not talk directly to internal services; instead it uses typed API clients under src/services/ to call the gateway.
3. Public API gateway
web-module is the external HTTP boundary on port 8083. It handles JWT auth, refresh-token sessions, CORS, rate limiting, security headers, and role-based access. It exposes the public routes for auth, books, summaries, flashcards, study progress, profile, and admin views, and forwards most book-related work to business-service.
4. Orchestration layer
business-service is the coordination layer on port 8082. Its main job is to fan requests out to ai-service and data-service, publish and consume book events via Kafka, and manage higher-level library workflows. This is where upload/ingestion sequencing and domain event routing are centralized.
5. AI processing engine
ai-service is the core AI subsystem on port 8080. It owns document ingestion, chunking, embedding, RAG chat, summary generation, flashcard generation, PDF vision/OCR, and object storage access. It also enforces AI-specific guardrails and runs background jobs for ingestion polling and retention cleanup.
6. Ingestion data flow
The upload pipeline is asynchronous: a user uploads a PDF/EPUB through the gateway, orchestration starts an ingestion job, ai-service extracts text, chunks it, embeds it, and writes vectors into Qdrant through haystack-service. After processing, job status is updated and the resulting book/chapter metadata is persisted through data-service.
7. Retrieval and chat flow
For chat and semantic search, ai-service embeds the query, retrieves top chunks from Qdrant, builds a grounded prompt, and asks either Gemini or Groq to generate the answer. The frontend shows source citations using the returned retrieved chunks, while chat history is stored separately in the data layer.
8. Persistence boundary
data-service is the system of record for application data on port 8081. It splits storage by model type: MongoDB holds books, chapters, summaries, flashcards, chat history, and reading sessions; PostgreSQL holds relational user accounts. This service isolates persistence concerns from both the gateway and the AI pipeline.
9. Vector search bridge
haystack-service is a thin Python FastAPI service on port 8000. It exists to wrap Haystack’s Qdrant document store and retriever, exposing /ingest and /search so the Java AI service can offload vector store interaction without embedding Haystack logic into the JVM service.
10. Shared infrastructure and state
Redis is used for short-lived operational state: JWT refresh sessions in web-module, rate-limit counters in both gateway and AI service, and daily guardrail counters in ai-service. PostgreSQL also stores ingestion jobs, audit logs, and dead-letter metadata. Optional object storage keeps uploaded source documents outside the services when enabled.
11. Async events and resilience
Kafka is the cross-service event bus, with deepreader.book.events as the main topic and a dead-letter topic for failed handling. business-service publishes and routes these events via Apache Camel and Spring Kafka, supporting decoupled workflows and operational recovery.
12. Operational and security boundaries
Security is layered: JWT-based authentication, refresh token rotation, admin-only routes, per-IP rate limiting, and configurable daily usage caps. Observability is built into all Java services via Micrometer/Prometheus, with Grafana dashboards and alert rules in observability/. This makes the system diagram naturally split into user entry, orchestration, AI, persistence, search, and shared runtime services.
Main entry points: web-module Web Module · ai-service AI Service · business-service Business Service · data-service Data Service
Components 25
Client
User-facing app and browser-side service clients
- Frontend · Browser UI for auth, library, reading, flashcards, profile, admin, and help screens
frontend - API Clients · Typed service layer used by the frontend to call the gateway
frontend/src/services
Gateway
Public HTTP boundary and auth/session control
- Web Module · Public entry point handling auth, sessions, security, and route forwarding
web-module - Auth Core · JWT issuance, refresh sessions, OAuth, and user context
web-module/src/main/java/com/deepreader/web_module/service - Public Routes · Public endpoints for books, study progress, profile, admin, and reading flows
web-module/src/main/java/com/deepreader/web_module/controller - Security Filters · CORS, rate limiting, auth filter, and security config
web-module/src/main/java/com/deepreader/web_module/config
Orchestration
Business workflow coordination and event routing
- Business Service · Coordinates library workflows and cross-service calls
business-service - Library Orchestration · Fanning requests to AI and data services for uploads, summaries, flashcards, and deletes
business-service/src/main/java/com/deepreader/business_service/service - Book Events · Publishes and consumes domain events for library workflows
business-service/src/main/java/com/deepreader/business_service/event
AI Processing
Ingestion, retrieval, generation, and vision
- AI Service · Document ingestion, retrieval, generation, OCR, and AI guardrails
ai-service - Ingestion Pipeline · Text extraction, chunking, embeddings, and ingestion job tracking
ai-service/src/main/java/com/deepreader/ai_service/service - Retrieval & Chat · Query embedding, vector retrieval, grounded prompt building, and LLM response generation
ai-service/src/main/java/com/deepreader/ai_service/service - Vision Module · PDF rasterization, embedded image extraction, and vision-assisted processing
ai-service/src/main/java/com/deepreader/ai_service/service - Background Jobs · Ingestion queue polling and retention cleanup tasks
ai-service/src/main/java/com/deepreader/ai_service/startup
Persistence
System-of-record services and repositories
- Data Service · System of record for books, chapters, summaries, flashcards, sessions, and user accounts
data-service - Library Data · Repository-backed storage for library and study content
data-service/src/main/java/com/deepreader/data_service/service - User Accounts · Relational user account persistence and profile storage
data-service/src/main/java/com/deepreader/data_service/service - Core Models · Shared domain entities used across services
core/src/main/java/com/deepreader/core/model
Infrastructure
Shared runtime and external backing services
- Haystack Service · FastAPI wrapper around Haystack/Qdrant search and ingest endpoints
haystack-service - Qdrant · Vector index used for semantic retrieval
- Redis · Refresh sessions, rate limits, and daily counters
- PostgreSQL · User accounts, jobs, audit logs, and operational metadata
- MongoDB · Books, chapters, summaries, flashcards, chat history, and reading sessions
- Kafka · Cross-service book event stream with dead-letter handling
- Object Storage · Optional storage for uploaded source documents
Connections 26
- Frontend → API Clients: uses · UI calls typed API clients
- API Clients → Web Module: HTTP API · Browser traffic goes to the public gateway
- Web Module → Security Filters: secures · Applies auth, rate limiting, and security filters
- Web Module → Auth Core: authenticates · Issues and validates tokens and sessions
- Web Module → Public Routes: serves · Exposes public and role-based routes
- Web Module → Business Service: delegates · Forwards library workflow requests
- Web Module → Data Service: profiles · Direct calls for user/account-related views
- Business Service → Library Orchestration: coordinates · Central workflow coordination for books and study content
- Business Service → Book Events: publishes · Emits and routes book domain events
- Book Events → Kafka: streams · Uses Kafka topic transport
- Business Service → AI Service: calls · Triggers AI work for ingestion, summaries, flashcards, and chat
- Business Service → Data Service: persists · Writes and reads application state
- AI Service → Ingestion Pipeline: runs · Processes uploaded documents into chunks and embeddings
- AI Service → Retrieval & Chat: answers · Builds grounded RAG responses and summaries
- AI Service → Vision Module: extracts · Handles PDF OCR and image-based processing
- AI Service → Background Jobs: schedules · Background ingestion polling and cleanup jobs
- Ingestion Pipeline → Haystack Service: indexes · Pushes vectors for storage and retrieval
- Retrieval & Chat → Haystack Service: searches · Retrieves top chunks for semantic answers
- Haystack Service → Qdrant: stores · Wraps the vector database interaction
- AI Service → Redis: limits · Uses cache for AI counters and rate limits
- Web Module → Redis: sessions · Stores refresh tokens and session state
- Data Service → MongoDB: stores · Persists content and study data
- Data Service → PostgreSQL: stores · Persists user accounts and relational metadata
- AI Service → Object Storage: reads/writes · Accesses uploaded source documents when enabled
- Data Service → Core Models: shares · Reuses shared domain entities
- Web Module → Kafka: observes · Receives or forwards user-facing workflow signals indirectly through services