How smerteliko/knowledge-hub-backend-spring works
1. Overall shape
- This is a Spring Boot 3 backend for a personal knowledge system.
- The code follows a classic layered architecture: API controllers → domain/services → persistence repositories → PostgreSQL and Elasticsearch.
- The backend is the system of record for users, notes, links, and tags; Elasticsearch is used as a derived search index.
2. API boundary
- The HTTP layer is split by responsibility into AuthController, ContentController, TagController, SearchController, and LinkParsingController.
- These controllers expose the main user-facing capabilities: authentication, CRUD over knowledge items, tag management, text search, and URL parsing.
- DTOs under dto/* define request/response shapes and keep the API contract separate from internal entities.
3. Authentication and security
- Security is JWT-based, with JwtAuthenticationFilter and SecurityConfig enforcing token validation on protected routes.
- AuthService, JwtService, and JpaUserDetailsService form the authentication backend.
- UserRepository persists users, while Role models authorization scope.
- The architecture is stateless at the API level: login returns a JWT, and subsequent requests carry that token.
4. Core domain model
- The central content model is built around ContentItem, with concrete types Note and Link.
- Tag is a separate domain entity used to classify content items.
- This suggests the system supports mixed knowledge objects but keeps a common content layer for shared operations and search/export logic.
5. Relational persistence
- PostgreSQL is the primary durable store, accessed through Spring Data JPA repositories.
- ContentItemRepository, TagRepository, and UserRepository are the main relational persistence boundaries.
- The database holds authoritative business state, including ownership, relationships, and content metadata.
6. Search subsystem
- Elasticsearch is configured through ElasticsearchConfig and used via LinkSearchRepository and NoteSearchRepository.
- LinkIndex and NoteIndex are separate search documents, indicating the system indexes different content types independently.
- SearchService likely coordinates query execution and relevance behavior across those indices.
- This creates a clear split: PostgreSQL for truth, Elasticsearch for fast full-text retrieval.
7. Content management flow
- ContentService is the orchestration layer for creating and retrieving notes/links.
- Content creation requests come in through NoteCreateRequest and LinkCreateRequest, then are persisted relationally and reflected into search indexing.
- This service boundary is where ownership, tagging, and indexing consistency are likely managed together.
8. URL parsing and enrichment
- LinkParsingService and LinkParsingController handle fetching metadata from external URLs.
- The readme indicates Jsoup is used to extract title, description, and Open Graph tags.
- This is an ingestion/enrichment path: external web pages become structured link objects inside the knowledge hub.
9. Export subsystem
- ExportService is a distinct capability for generating knowledge reports.
- The readme indicates PDF and Markdown output, with Apache PDFBox for PDF generation.
- This is a read-only outbound pipeline that transforms stored knowledge into portable reports.
10. Testing and environment isolation
- Tests are organized by subsystem, with unit and integration coverage for auth, link parsing, and search.
- Test infrastructure includes AbstractTest plus a test-specific Elasticsearch config, indicating environment substitution for search integration tests.
- The readme mentions Testcontainers, so external dependencies such as PostgreSQL and Elasticsearch are likely validated in isolated containers rather than mocks only.
11. Deployment and runtime topology
- The repo includes Dockerfile and compose.yaml, so the application is designed to run as part of a containerized stack.
- The stack includes the Spring app plus PostgreSQL and Elasticsearch, which are the two backing infrastructure services that define the main architecture boundary.
- GitHub Actions workflow exists under .github/workflows/main.yml, suggesting CI builds and tests the same layered stack.
12. Important diagram boundary
- If you draw the architecture, the key separation is: client/API traffic enters the Spring Boot app; business logic lives in services; relational writes go to PostgreSQL; search queries and index writes go to Elasticsearch; outbound enrichment reaches the public web for link parsing; export turns stored content into files.
Main entry points: ContentService.java Content service · SearchService.java Search service · UserRepository.java User repo · ExportService.java Export service
Components 30
API layer
HTTP controllers and request/response DTOs
- Auth API · Login and registration endpoints
src/main/java/com/smerteliko/knowledgehub/controller/AuthController.java - Content API · Note and link CRUD endpoints
src/main/java/com/smerteliko/knowledgehub/controller/ContentController.java - Tag API · Tag management endpoints
src/main/java/com/smerteliko/knowledgehub/controller/TagController.java - Search API · Search query endpoints
src/main/java/com/smerteliko/knowledgehub/controller/SearchController.java - Parse API · Link metadata parsing endpoint
src/main/java/com/smerteliko/knowledgehub/controller/LinkParsingController.java
Core domain
Business services and entities
- Auth service · Registration and authentication flow
src/main/java/com/smerteliko/knowledgehub/service/auth/AuthService.java - Content service · Coordinates note and link persistence
src/main/java/com/smerteliko/knowledgehub/service/content/ContentService.java - Tag service · Tag lifecycle and assignment
src/main/java/com/smerteliko/knowledgehub/service/tag/TagService.java - Search service · Query execution across search indices
src/main/java/com/smerteliko/knowledgehub/service/search/SearchService.java - Parse service · Fetches and extracts link metadata
src/main/java/com/smerteliko/knowledgehub/service/parse/LinkParsingService.java - Export service · Builds PDF and Markdown exports
src/main/java/com/smerteliko/knowledgehub/service/export/ExportService.java - Content item · Shared base content model
src/main/java/com/smerteliko/knowledgehub/entity/ContentItem.java - Note · Text knowledge item
src/main/java/com/smerteliko/knowledgehub/entity/Note.java - Link · URL-backed knowledge item
src/main/java/com/smerteliko/knowledgehub/entity/Link.java - Tag · Content classification
src/main/java/com/smerteliko/knowledgehub/entity/Tag.java - User · Authenticated account
src/main/java/com/smerteliko/knowledgehub/entity/User.java - Role · Authorization scope
src/main/java/com/smerteliko/knowledgehub/entity/enums/Role.java
Persistence
Relational and search-backed storage
- Content repo · Relational boundary for content items
src/main/java/com/smerteliko/knowledgehub/repository/ContentItemRepository.java - Tag repo · Relational tag persistence
src/main/java/com/smerteliko/knowledgehub/repository/TagRepository.java - User repo · Relational user persistence
src/main/java/com/smerteliko/knowledgehub/repository/UserRepository.java - Link search · Search access for links
src/main/java/com/smerteliko/knowledgehub/es/repository/LinkSearchRepository.java - Note search · Search access for notes
src/main/java/com/smerteliko/knowledgehub/es/repository/NoteSearchRepository.java - Link index · Indexed link search view
src/main/java/com/smerteliko/knowledgehub/es/entity/LinkIndex.java - Note index · Indexed note search view
src/main/java/com/smerteliko/knowledgehub/es/entity/NoteIndex.java
Infrastructure
Security and runtime configuration
- App · Application bootstrap
src/main/java/com/smerteliko/knowledgehub/KnowledgehubApplication.java - JWT service · Creates and validates JWTs
src/main/java/com/smerteliko/knowledgehub/service/JWT/JwtService.java - User details · Loads users for Spring Security
src/main/java/com/smerteliko/knowledgehub/service/security/JpaUserDetailsService.java - Security config · HTTP security and filter chain
src/main/java/com/smerteliko/knowledgehub/config/SecurityConfig.java - JWT filter · Validates bearer tokens on requests
src/main/java/com/smerteliko/knowledgehub/config/JwtAuthenticationFilter.java - ES config · Elasticsearch client and wiring
src/main/java/com/smerteliko/knowledgehub/config/ElasticsearchConfig.java
Connections 32
- App → Security config: loads · Application starts with security and web configuration
- App → ES config: loads · Application starts with search infrastructure
- Security config → JWT filter: uses · Security chain includes JWT validation
- JWT filter → JWT service: validates · Filter verifies bearer tokens
- Security config → User details: uses · Security authenticates against JPA users
- Auth API → Auth service: calls · Login and registration flow
- Auth service → JWT service: issues · Creates JWT responses
- Auth service → User repo: persists · Stores and loads users
- Content API → Content service: calls · CRUD operations for notes and links
- Content service → Content repo: persists · Writes authoritative content state
- Content service → Tag service: coordinates · Assigns and resolves tags
- Content service → Search service: indexes · Reflects content into search views
- Content service → Content item: manages · Works through shared content abstraction
- Content service → Note: creates · Handles note creation
- Content service → Link: creates · Handles link creation
- Tag API → Tag service: calls · Tag management endpoints
- Tag service → Tag repo: persists · Stores tag records
- Search API → Search service: calls · Search queries enter here
- Search service → Link search: queries · Searches link index
- Search service → Note search: queries · Searches note index
- Search service → Link index: reads · Uses link search document shape
- Search service → Note index: reads · Uses note search document shape
- Parse API → Parse service: calls · URL parsing and enrichment requests
- Parse service → Link: builds · Produces structured link data
- Parse service → Content service: may save · Parsed links flow into content management
- Export service → Content repo: reads · Exports stored knowledge
- Export service → Tag repo: reads · Includes tags in reports
- Export service → User repo: reads · Can scope exports by owner
- User details → User repo: loads · Resolves users for authentication
- Content repo → Content item: stores · Relational store for shared content
- Tag repo → Tag: stores · Relational store for tags
- User repo → User: stores · Relational store for accounts