# chetan202/codesnippet architecture

> Architecture diagram of the GitHub repository chetan202/codesnippet, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2026-08-20). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/chetan202/codesnippet
- Repository: https://github.com/chetan202/codesnippet

## Overview

#### 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: [`src/main/java/com/example/CodeHub/Configuration/securityConfig.java`](https://github.com/chetan202/codesnippet/blob/main/src/main/java/com/example/CodeHub/Configuration/securityConfig.java) (Security and request boundary), [`src/main/java/com/example/CodeHub/Controller/SnippetController.java`](https://github.com/chetan202/codesnippet/blob/main/src/main/java/com/example/CodeHub/Controller/SnippetController.java) (Web and auth controllers), [`microservices/gateway/src/main/java/com/codehub/gateway/GatewayApplication.java`](https://github.com/chetan202/codesnippet/blob/main/microservices/gateway/src/main/java/com/codehub/gateway/GatewayApplication.java) (API gateway), [`src/main/java/com/example/CodeHub/CodeHubApplication.java`](https://github.com/chetan202/codesnippet/blob/main/src/main/java/com/example/CodeHub/CodeHubApplication.java) (CodeHub application)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_monolith["Spring Boot monolith"]
  node_monolith_app{{"CodeHub application<br/>Spring Boot entry"}}
  node_request_boundary["Security and request boundary<br/>Spring Security filters"]
  node_jwt_filter["JWT filter<br/>request filter"]
  node_correlation_filter["Correlation ID filter<br/>request filter"]
  node_web_controllers["Web and auth controllers<br/>MVC controllers"]
  node_views["Server-rendered views<br/>HTML templates<br/>[home.html]"]
end

subgraph group_domain["Domain services"]
  node_snippet_service["Snippet service<br/>domain service"]
  node_snippet_dto["Snippet DTO boundary<br/>DTOs"]
  node_snippet_model["Snippet lifecycle model<br/>JPA entities<br/>[Snippet.java]"]
  node_snippet_repositories["Snippet repositories<br/>Spring Data"]
  node_user_admin["Users and administration<br/>MVC controllers"]
  node_identity_services["Identity services<br/>security services<br/>[JwtService.java]"]
end

subgraph group_microservices["Extracted services"]
  node_gateway{{"API gateway<br/>Spring Boot gateway"}}
  node_auth_service["Auth service<br/>Spring Boot service"]
  node_snippet_service_ms["Snippet service<br/>Spring Boot service"]
  node_notification_admin["Notification admin service"]
end

subgraph group_operations["Deployment and operations"]
  node_relational_db[("Relational database<br/>JDBC database")]
  node_runtime_properties["Monolith runtime properties<br/>application configuration"]
  node_container_deployment["Docker and Render deployment<br/>deployment manifests"]
  node_ci["GitHub Actions CI<br/>CI pipeline<br/>[ci.yml]"]
end

node_monolith_app -->|"boots"| node_request_boundary
node_request_boundary -->|"authenticates via"| node_jwt_filter
node_request_boundary -->|"assigns tracing"| node_correlation_filter
node_request_boundary -->|"authorizes requests to"| node_web_controllers
node_web_controllers -->|"renders"| node_views
node_web_controllers -->|"maps inputs and views"| node_snippet_dto
node_snippet_dto -->|"invokes"| node_snippet_service
node_snippet_service -->|"manages"| node_snippet_model
node_snippet_service -->|"persists through"| node_snippet_repositories
node_snippet_repositories -->|"reads and writes"| node_relational_db
node_request_boundary -->|"uses"| node_identity_services
node_identity_services -->|"looks up users"| node_relational_db
node_web_controllers -->|"routes user and admin flows"| node_user_admin
node_user_admin -->|"manages users and activity"| node_relational_db
node_runtime_properties -.->|"configures"| node_monolith_app
node_gateway -->|"routes auth requests"| node_auth_service
node_gateway -->|"routes snippet requests"| node_snippet_service_ms
node_gateway -->|"routes admin operations"| node_notification_admin
node_container_deployment -.->|"deploys active application"| node_monolith_app
node_container_deployment -.->|"orchestrates extracted topology"| node_gateway
node_ci -.->|"builds and verifies"| node_monolith_app

click node_monolith_app "https://github.com/chetan202/codesnippet/blob/main/src/main/java/com/example/CodeHub/CodeHubApplication.java"
click node_request_boundary "https://github.com/chetan202/codesnippet/blob/main/src/main/java/com/example/CodeHub/Configuration/securityConfig.java"
click node_jwt_filter "https://github.com/chetan202/codesnippet/blob/main/src/main/java/com/example/CodeHub/Configuration/JwtAuthenticationFilter.java"
click node_correlation_filter "https://github.com/chetan202/codesnippet/blob/main/src/main/java/com/example/CodeHub/Configuration/CorrelationIdFilter.java"
click node_web_controllers "https://github.com/chetan202/codesnippet/blob/main/src/main/java/com/example/CodeHub/Controller/SnippetController.java"
click node_views "https://github.com/chetan202/codesnippet/blob/main/src/main/resources/templates/home.html"
click node_snippet_model "https://github.com/chetan202/codesnippet/blob/main/src/main/java/com/example/CodeHub/Entity/Snippet.java"
click node_user_admin "https://github.com/chetan202/codesnippet/blob/main/src/main/java/com/example/CodeHub/Controller/AdminController.java"
click node_identity_services "https://github.com/chetan202/codesnippet/blob/main/src/main/java/com/example/CodeHub/Services/JwtService.java"
click node_runtime_properties "https://github.com/chetan202/codesnippet/blob/main/src/main/resources/application.properties"
click node_gateway "https://github.com/chetan202/codesnippet/blob/main/microservices/gateway/src/main/java/com/codehub/gateway/GatewayApplication.java"
click node_auth_service "https://github.com/chetan202/codesnippet/blob/main/microservices/auth-service/src/main/java/com/codehub/auth/AuthServiceApplication.java"
click node_snippet_service_ms "https://github.com/chetan202/codesnippet/blob/main/microservices/snippet-service/src/main/java/com/codehub/snippet/SnippetServiceApplication.java"
click node_notification_admin "https://github.com/chetan202/codesnippet/blob/main/microservices/notification-admin-service/src/main/java/com/codehub/notificationadmin/AdminController.java"
click node_container_deployment "https://github.com/chetan202/codesnippet/blob/main/docker-compose.microservices.yml"
click node_ci "https://github.com/chetan202/codesnippet/blob/main/.github/workflows/ci.yml"

classDef toneNeutral fill:#f8fafc,stroke:#334155,stroke-width:1.5px,color:#0f172a
classDef toneBlue fill:#dbeafe,stroke:#2563eb,stroke-width:1.5px,color:#172554
classDef toneAmber fill:#fef3c7,stroke:#d97706,stroke-width:1.5px,color:#78350f
classDef toneMint fill:#dcfce7,stroke:#16a34a,stroke-width:1.5px,color:#14532d
classDef toneRose fill:#ffe4e6,stroke:#e11d48,stroke-width:1.5px,color:#881337
classDef toneIndigo fill:#e0e7ff,stroke:#4f46e5,stroke-width:1.5px,color:#312e81
classDef toneTeal fill:#ccfbf1,stroke:#0f766e,stroke-width:1.5px,color:#134e4a
class node_monolith_app,node_request_boundary,node_jwt_filter,node_correlation_filter,node_web_controllers,node_views toneBlue
class node_snippet_service,node_snippet_dto,node_snippet_model,node_snippet_repositories,node_user_admin,node_identity_services toneAmber
class node_gateway,node_auth_service,node_snippet_service_ms,node_notification_admin toneMint
class node_relational_db,node_runtime_properties,node_container_deployment,node_ci toneRose
```

## Components

### Spring Boot monolith

- [CodeHub application](https://github.com/chetan202/codesnippet/blob/main/src/main/java/com/example/CodeHub/CodeHubApplication.java): Spring Boot entry · Active server-rendered application. · `src/main/java/com/example/CodeHub/CodeHubApplication.java`
- [Security and request boundary](https://github.com/chetan202/codesnippet/blob/main/src/main/java/com/example/CodeHub/Configuration/securityConfig.java): Spring Security filters · Authentication, JWT, rate limiting, correlation, and error handling. · `src/main/java/com/example/CodeHub/Configuration/securityConfig.java`
- [JWT filter](https://github.com/chetan202/codesnippet/blob/main/src/main/java/com/example/CodeHub/Configuration/JwtAuthenticationFilter.java): request filter · `src/main/java/com/example/CodeHub/Configuration/JwtAuthenticationFilter.java`
- [Correlation ID filter](https://github.com/chetan202/codesnippet/blob/main/src/main/java/com/example/CodeHub/Configuration/CorrelationIdFilter.java): request filter · `src/main/java/com/example/CodeHub/Configuration/CorrelationIdFilter.java`
- [Web and auth controllers](https://github.com/chetan202/codesnippet/blob/main/src/main/java/com/example/CodeHub/Controller/SnippetController.java): MVC controllers · Home, authentication, and snippet routes. · `src/main/java/com/example/CodeHub/Controller/SnippetController.java`
- [Server-rendered views](https://github.com/chetan202/codesnippet/blob/main/src/main/resources/templates/home.html): HTML templates · User snippet and admin workflow surfaces. · `src/main/resources/templates/home.html`

### Domain services

- **Snippet service**: domain service · Applies snippet creation, editing, discovery, sharing, and viewing behavior.
- **Snippet DTO boundary**: DTOs · Separates web inputs and views from persistence entities.
- [Snippet lifecycle model](https://github.com/chetan202/codesnippet/blob/main/src/main/java/com/example/CodeHub/Entity/Snippet.java): JPA entities · Snippets, revisions, and bookmarks. · `src/main/java/com/example/CodeHub/Entity/Snippet.java`
- **Snippet repositories**: Spring Data · Queries snippets and revision history.
- [Users and administration](https://github.com/chetan202/codesnippet/blob/main/src/main/java/com/example/CodeHub/Controller/AdminController.java): MVC controllers · User dashboards, roles, and administrative management. · `src/main/java/com/example/CodeHub/Controller/AdminController.java`
- [Identity services](https://github.com/chetan202/codesnippet/blob/main/src/main/java/com/example/CodeHub/Services/JwtService.java): security services · Loads users and issues or validates JWTs. · `src/main/java/com/example/CodeHub/Services/JwtService.java`

### Extracted services

- [API gateway](https://github.com/chetan202/codesnippet/blob/main/microservices/gateway/src/main/java/com/codehub/gateway/GatewayApplication.java): Spring Boot gateway · Intended external routing entry point for extracted services. · `microservices/gateway/src/main/java/com/codehub/gateway/GatewayApplication.java`
- [Auth service](https://github.com/chetan202/codesnippet/blob/main/microservices/auth-service/src/main/java/com/codehub/auth/AuthServiceApplication.java): Spring Boot service · Owns authentication-facing endpoints. · `microservices/auth-service/src/main/java/com/codehub/auth/AuthServiceApplication.java`
- [Snippet service](https://github.com/chetan202/codesnippet/blob/main/microservices/snippet-service/src/main/java/com/codehub/snippet/SnippetServiceApplication.java): Spring Boot service · Owns snippet-facing endpoints. · `microservices/snippet-service/src/main/java/com/codehub/snippet/SnippetServiceApplication.java`
- [Notification admin service](https://github.com/chetan202/codesnippet/blob/main/microservices/notification-admin-service/src/main/java/com/codehub/notificationadmin/AdminController.java): admin service · Exposes administrative notification operations. · `microservices/notification-admin-service/src/main/java/com/codehub/notificationadmin/AdminController.java`

### Deployment and operations

- **Relational database**: JDBC database · Runtime-configured persistence for users and snippets.
- [Monolith runtime properties](https://github.com/chetan202/codesnippet/blob/main/src/main/resources/application.properties): application configuration · `src/main/resources/application.properties`
- [Docker and Render deployment](https://github.com/chetan202/codesnippet/blob/main/docker-compose.microservices.yml): deployment manifests · Supports monolith and multi-service deployments. · `docker-compose.microservices.yml`
- [GitHub Actions CI](https://github.com/chetan202/codesnippet/blob/main/.github/workflows/ci.yml): CI pipeline · `.github/workflows/ci.yml`

## Connections

- 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
