How chetan202/codesnippet works
Purpose and deployment shape
CodeHub is a Java/Spring code-snippet management platform: authenticated users create, search, share, bookmark, version, import/export, and manage snippets; administrators oversee users and statistics. The repository contains both the active monolith and a planned/extracted microservice topology. Root deployment assets target Docker and Render: Dockerfile, render.yaml, docker-compose.microservices.yml, render.microservices.yaml.
Monolith application entry and presentation
The primary runnable application is Spring Boot at src/main/java/com/example/CodeHub/CodeHubApplication.java. It serves server-rendered HTML views and static assets, rather than a separate frontend:
• Web routes and API-like authentication endpoints: src/main/java/com/example/CodeHub/Controller/homeController.java, src/main/java/com/example/CodeHub/Controller/AuthApiController.java, src/main/java/com/example/CodeHub/Controller/SnippetController.java.
• Templates define the user/admin workflow surfaces: src/main/resources/templates/home.html, src/main/resources/templates/admin-statistics.html, src/main/resources/templates/view-snippet.html.
• Runtime properties are centralized in src/main/resources/application.properties.
Authentication, authorization, and request boundary
Spring Security is the main ingress boundary. Security configuration, JWT processing, OAuth account integration, login outcomes, and cross-cutting filters sit in:
src/main/java/com/example/CodeHub/Configuration/securityConfig.java,
src/main/java/com/example/CodeHub/Configuration/JwtAuthenticationFilter.java,
src/main/java/com/example/CodeHub/Configuration/CorrelationIdFilter.java.
Requests pass through authentication, rate limiting, correlation ID assignment, and global error handling before controllers. Identity lookup and token functions are implemented by src/main/java/com/example/CodeHub/Services/CustomUserDetailsService.java and src/main/java/com/example/CodeHub/Services/JwtService.java.
Snippet domain lifecycle
The core domain is persisted snippets and their related ownership, bookmarks, and revision history:
src/main/java/com/example/CodeHub/Entity/Snippet.java,
src/main/java/com/example/CodeHub/Entity/SnippetVersion.java,
src/main/java/com/example/CodeHub/Entity/Bookmark.java.
SnippetController receives creation, editing, discovery, sharing, and viewing operations; SnippetServiceImpl applies business behavior; Spring Data repositories persist/query the model through SnippetRepository and SnippetVersionRepository. DTOs (SnippetDto) form a boundary between web inputs/views and persistence entities.
Users, roles, and administration
User records and user-view activity support ownership, role-sensitive dashboards, and administration:
src/main/java/com/example/CodeHub/Entity/User.java,
src/main/java/com/example/CodeHub/Controller/UserController.java,
src/main/java/com/example/CodeHub/Controller/AdminController.java.
UserServiceImpl manages user-level logic, while UserViewServiceImpl records or exposes viewing behavior. The admin controller and statistics template form the management path distinct from normal snippet ownership flows.
Extracted microservice topology
A parallel Maven/Spring Boot microservices layout splits responsibilities behind a gateway:
microservices/gateway/src/main/java/com/codehub/gateway/GatewayApplication.java,
microservices/auth-service/src/main/java/com/codehub/auth/AuthServiceApplication.java,
microservices/snippet-service/src/main/java/com/codehub/snippet/SnippetServiceApplication.java.
The gateway is the intended external routing entry point; auth-service owns authentication-facing endpoints; snippet-service owns snippet-facing endpoints; notification-admin-service exposes administrative notification operations via microservices/notification-admin-service/src/main/java/com/codehub/notificationadmin/AdminController.java. Each service has independent Maven, Docker, and properties boundaries.
Infrastructure and external dependencies
The application requires a JDBC-compatible relational database per the README; actual connection/provider settings are runtime-configured in the monolith and each service’s application.properties. Render hosts the live monolith and has service deployment manifests. Docker supports both a single application image and multi-container microservice execution. GitHub Actions CI is defined in .github/workflows/ci.yml.
Main entry points: securityConfig.java Security and request boundary · SnippetController.java Web and auth controllers · GatewayApplication.java API gateway · CodeHubApplication.java CodeHub application
Components 20
Spring Boot monolith
- CodeHub application · Active server-rendered application.
src/main/java/com/example/CodeHub/CodeHubApplication.java - Security and request boundary · Authentication, JWT, rate limiting, correlation, and error handling.
src/main/java/com/example/CodeHub/Configuration/securityConfig.java - JWT filter
src/main/java/com/example/CodeHub/Configuration/JwtAuthenticationFilter.java - Correlation ID filter
src/main/java/com/example/CodeHub/Configuration/CorrelationIdFilter.java - Web and auth controllers · Home, authentication, and snippet routes.
src/main/java/com/example/CodeHub/Controller/SnippetController.java - Server-rendered views · User snippet and admin workflow surfaces.
src/main/resources/templates/home.html
Domain services
- Snippet service · Applies snippet creation, editing, discovery, sharing, and viewing behavior.
- Snippet DTO boundary · Separates web inputs and views from persistence entities.
- Snippet lifecycle model · Snippets, revisions, and bookmarks.
src/main/java/com/example/CodeHub/Entity/Snippet.java - Snippet repositories · Queries snippets and revision history.
- Users and administration · User dashboards, roles, and administrative management.
src/main/java/com/example/CodeHub/Controller/AdminController.java - Identity services · Loads users and issues or validates JWTs.
src/main/java/com/example/CodeHub/Services/JwtService.java
Extracted services
- API gateway · Intended external routing entry point for extracted services.
microservices/gateway/src/main/java/com/codehub/gateway/GatewayApplication.java - Auth service · Owns authentication-facing endpoints.
microservices/auth-service/src/main/java/com/codehub/auth/AuthServiceApplication.java - Snippet service · Owns snippet-facing endpoints.
microservices/snippet-service/src/main/java/com/codehub/snippet/SnippetServiceApplication.java - Notification admin service · Exposes administrative notification operations.
microservices/notification-admin-service/src/main/java/com/codehub/notificationadmin/AdminController.java
Deployment and operations
- Relational database · Runtime-configured persistence for users and snippets.
- Monolith runtime properties
src/main/resources/application.properties - Docker and Render deployment · Supports monolith and multi-service deployments.
docker-compose.microservices.yml - GitHub Actions CI
.github/workflows/ci.yml
Connections 21
- CodeHub application → Security and request boundary: boots
- Security and request boundary → JWT filter: authenticates via
- Security and request boundary → Correlation ID filter: assigns tracing
- Security and request boundary → Web and auth controllers: authorizes requests to
- Web and auth controllers → Server-rendered views: renders
- Web and auth controllers → Snippet DTO boundary: maps inputs and views
- Snippet DTO boundary → Snippet service: invokes
- Snippet service → Snippet lifecycle model: manages
- Snippet service → Snippet repositories: persists through
- Snippet repositories → Relational database: reads and writes
- Security and request boundary → Identity services: uses
- Identity services → Relational database: looks up users
- Web and auth controllers → Users and administration: routes user and admin flows
- Users and administration → Relational database: manages users and activity
- Monolith runtime properties → CodeHub application: configures
- API gateway → Auth service: routes auth requests
- API gateway → Snippet service: routes snippet requests
- API gateway → Notification admin service: routes admin operations
- Docker and Render deployment → CodeHub application: deploys active application
- Docker and Render deployment → API gateway: orchestrates extracted topology
- GitHub Actions CI → CodeHub application: builds and verifies