# arunshar2725/smart-contact-manager architecture

> Architecture diagram of the GitHub repository arunshar2725/smart-contact-manager, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2026-06-01). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/arunshar2725/smart-contact-manager
- Repository: https://github.com/arunshar2725/smart-contact-manager

## Overview

1. **Overall shape**
   - This is a single Spring Boot monolith: one JVM backend serves both HTML pages and application endpoints.
   - There is no separate frontend service or SPA runtime; UI is rendered server-side with Thymeleaf and enhanced with static JS/CSS.

2. **Presentation layer**
   - Request entry points are split across controllers such as `PageController`, `RootController`, `AuthController`, `UserController`, `ContactController`, `AdminController`, `ApiController`, and `ContactExportController`.
   - Templates live under `src/main/resources/templates`, with shared layout fragments like `base.html`, `navbar.html`, and `user/sidebar.html`, plus role-specific pages for admin and user flows.
   - Static assets are served from `src/main/resources/static` and include Tailwind-generated CSS plus small client scripts for interactions on contact/admin pages.

3. **Core domain model**
   - The main business entities are `User` and `Contact`, with supporting models like `SocialLink` and `Providers`.
   - The README indicates a strict one-to-many relationship: one user owns many contacts, and JPA cascade/mapped-by semantics keep child lifecycle tied to the parent.
   - Form objects such as `UserForm`, `ContactForm`, `ContactSearchForm`, `FeedbackForm`, and `SendMessage` separate web input from persistence entities.

4. **Persistence layer**
   - Data access is handled through Spring Data repositories: `UserRepo`, `ContactRepo`, `FeedbackRepo`, and `SendMessageRepo`.
   - The app is backed by a relational database; the README specifies MySQL.
   - Large text content is modeled explicitly with JPA `@Lob`/text-style storage, likely for bios, descriptions, and long profile fields.

5. **Service layer**
   - Business logic is concentrated in `UserService`, `ContactService`, `EmailService`, and `ImageService`, with implementations in `.../impl`.
   - `UserServiceImpl` and `ContactServiceImpl` likely orchestrate validation, ownership checks, persistence, and search/update workflows.
   - `EmailServiceImpl` provides outbound messaging, while `ImageServiceImpl` handles profile/contact image processing and storage concerns.

6. **Security and identity**
   - `SecurityConfig` defines the authentication/authorization boundary for the app.
   - The app supports both standard login and OAuth2 sign-in; the README calls out Google and GitHub providers.
   - `SecurityCustomUserDetailService` integrates application users with Spring Security’s authentication model, while custom handlers manage login success/failure flows.

7. **Role-based areas**
   - The UI and controller structure suggest at least two main roles: normal users and admins.
   - User-facing pages cover dashboard, profile, contact CRUD, search, feedback, and account editing.
   - Admin pages expose user management and dashboard views, implying privileged access over platform-wide records.

8. **API and non-HTML endpoints**
   - `ApiController` suggests there are JSON or programmatic endpoints in addition to the server-rendered pages.
   - `ContactExportController` is a separate boundary for exporting contact data, distinct from the normal CRUD UI.
   - `EmailService` and the send-message/feedback forms indicate outbound communication flows separate from direct browser navigation.

9. **Validation and error handling**
   - Input validation is split between standard form validation and custom file validation via `FileValidator` / `ValidFile`.
   - `GlobalExceptionHandler` and `ResourceNotFoundException` centralize failure handling so controllers don’t duplicate error rendering logic.
   - `Message`, `MessageType`, `SessionHelper`, and `Helper` support user feedback, session-scoped alerts, and shared utility behavior.

10. **Frontend build and styling**
   - The UI uses Tailwind CSS, with a local `tailwind.config.js` and generated CSS artifacts under `static/css`.
   - The README mentions Flowbite, so the visual system is utility-first with component-style enhancements rather than a large custom frontend framework.
   - The presence of `package.json` and `node_modules` indicates a frontend asset build step exists, but it feeds into a traditional Spring Boot static asset pipeline.

11. **Request/data flow**
   - Typical flow: browser request → Spring MVC controller → service layer → repository/JPA → MySQL → service/controller → Thymeleaf template or JSON response.
   - Security filters run before controller logic, determining whether the request becomes an authenticated user session, an OAuth2 callback, or a blocked redirect.
   - File/image and email operations branch out from the main CRUD path into specialized services.

12. **Operational boundaries**
   - The codebase is organized as a layered monolith with clear separation between web, service, persistence, and security concerns.
   - `Application.java` is the bootstrap entry point; `src/test/java/com/scm/ApplicationTests.java` provides minimal application-level test coverage.
   - Overall, the architecture is centered on secure contact management with server-rendered pages, relational persistence, and integrated social login.

Main entry points: [`src/main/java/com/scm/controller`](https://github.com/arunshar2725/smart-contact-manager/tree/main/src/main/java/com/scm/controller) (Web Controllers), [`src/main/java/com/scm/Application.java`](https://github.com/arunshar2725/smart-contact-manager/blob/main/src/main/java/com/scm/Application.java) (Application), [`src/main/java/com/scm/Services/UserService.java`](https://github.com/arunshar2725/smart-contact-manager/blob/main/src/main/java/com/scm/Services/UserService.java) (User Service), [`src/main/java/com/scm/Services/ContactService.java`](https://github.com/arunshar2725/smart-contact-manager/blob/main/src/main/java/com/scm/Services/ContactService.java) (Contact Service)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_presentation["Presentation"]
  node_controllers["Web Controllers<br/>MVC endpoints"]
  node_templates["Thymeleaf Views<br/>server templates"]
  node_static_assets["Static Assets<br/>css/js assets"]
end

subgraph group_application["Application"]
  node_user_service["User Service<br/>business service<br/>[UserService.java]"]
  node_contact_service["Contact Service<br/>business service"]
  node_email_service["Email Service<br/>outbound messaging<br/>[EmailService.java]"]
  node_image_service["Image Service<br/>media service<br/>[ImageService.java]"]
  node_forms["Form Models<br/>web DTOs"]
end

subgraph group_security["Security"]
  node_security_config["Security Config"]
  node_user_detail_service["User Details<br/>auth adapter"]
  node_auth_handlers["Auth Handlers<br/>login flow"]
end

subgraph group_persistence["Persistence"]
  node_entities[("Domain Entities<br/>JPA models")]
  node_repositories["Repositories<br/>Spring Data"]
  node_db[("MySQL<br/>relational database")]
end

subgraph group_infra["Infrastructure"]
  node_app(("Application<br/>Spring Boot app<br/>[Application.java]"))
  node_exception_handler["Exception Handler<br/>error boundary"]
  node_validators["Validators<br/>input validation"]
  node_helpers["Helpers<br/>shared utils"]
end

node_app -->|"configures"| node_security_config
node_app -->|"hosts"| node_controllers
node_app -->|"wires"| node_user_service
node_app -->|"wires"| node_contact_service
node_app -->|"wires"| node_email_service
node_app -->|"wires"| node_image_service
node_security_config -->|"uses"| node_user_detail_service
node_security_config -->|"delegates"| node_auth_handlers
node_controllers -->|"renders"| node_templates
node_controllers -->|"binds"| node_forms
node_controllers -->|"calls"| node_user_service
node_controllers -->|"calls"| node_contact_service
node_controllers -->|"triggers"| node_email_service
node_controllers -->|"triggers"| node_image_service
node_controllers -->|"handled by"| node_exception_handler
node_controllers -->|"validates"| node_validators
node_user_service -->|"persists via"| node_repositories
node_contact_service -->|"persists via"| node_repositories
node_user_service -->|"maps"| node_entities
node_contact_service -->|"maps"| node_entities
node_repositories -->|"stores in"| node_db
node_forms -->|"translates to"| node_entities
node_helpers -->|"supports"| node_controllers
node_helpers -->|"supports"| node_security_config
node_templates -->|"enhanced by"| node_static_assets

click node_app "https://github.com/arunshar2725/smart-contact-manager/blob/main/src/main/java/com/scm/Application.java"
click node_security_config "https://github.com/arunshar2725/smart-contact-manager/blob/main/src/main/java/com/scm/config/SecurityConfig.java"
click node_user_detail_service "https://github.com/arunshar2725/smart-contact-manager/blob/main/src/main/java/com/scm/Services/impl/SecurityCustomUserDetailService.java"
click node_auth_handlers "https://github.com/arunshar2725/smart-contact-manager/blob/main/src/main/java/com/scm/config/OAuthAuthenticationSuccessHandler.java"
click node_controllers "https://github.com/arunshar2725/smart-contact-manager/tree/main/src/main/java/com/scm/controller"
click node_templates "https://github.com/arunshar2725/smart-contact-manager/tree/main/src/main/resources/templates"
click node_static_assets "https://github.com/arunshar2725/smart-contact-manager/tree/main/src/main/resources/static"
click node_user_service "https://github.com/arunshar2725/smart-contact-manager/blob/main/src/main/java/com/scm/Services/UserService.java"
click node_contact_service "https://github.com/arunshar2725/smart-contact-manager/blob/main/src/main/java/com/scm/Services/ContactService.java"
click node_email_service "https://github.com/arunshar2725/smart-contact-manager/blob/main/src/main/java/com/scm/Services/EmailService.java"
click node_image_service "https://github.com/arunshar2725/smart-contact-manager/blob/main/src/main/java/com/scm/Services/ImageService.java"
click node_forms "https://github.com/arunshar2725/smart-contact-manager/tree/main/src/main/java/com/scm/forms"
click node_entities "https://github.com/arunshar2725/smart-contact-manager/tree/main/src/main/java/com/scm/entities"
click node_repositories "https://github.com/arunshar2725/smart-contact-manager/tree/main/src/main/java/com/scm/Repositories"
click node_exception_handler "https://github.com/arunshar2725/smart-contact-manager/blob/main/src/main/java/com/scm/handlers/GlobalExceptionHandler.java"
click node_validators "https://github.com/arunshar2725/smart-contact-manager/tree/main/src/main/java/com/scm/validators"
click node_helpers "https://github.com/arunshar2725/smart-contact-manager/tree/main/src/main/java/com/scm/helpers"

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_controllers,node_templates,node_static_assets toneBlue
class node_user_service,node_contact_service,node_email_service,node_image_service,node_forms toneAmber
class node_security_config,node_user_detail_service,node_auth_handlers toneMint
class node_entities,node_repositories,node_db toneRose
class node_app,node_exception_handler,node_validators,node_helpers toneIndigo
```

## Components

### Presentation

Server-rendered UI, controllers, templates, and static assets.

- [Web Controllers](https://github.com/arunshar2725/smart-contact-manager/tree/main/src/main/java/com/scm/controller): MVC endpoints · Entry points for pages, auth, user, admin, API, and export flows. · `src/main/java/com/scm/controller`
- [Thymeleaf Views](https://github.com/arunshar2725/smart-contact-manager/tree/main/src/main/resources/templates): server templates · HTML pages and shared fragments rendered on the server. · `src/main/resources/templates`
- [Static Assets](https://github.com/arunshar2725/smart-contact-manager/tree/main/src/main/resources/static): css/js assets · Tailwind output and small client scripts for UI behavior. · `src/main/resources/static`

### Application

Business services, forms, and shared helpers.

- [User Service](https://github.com/arunshar2725/smart-contact-manager/blob/main/src/main/java/com/scm/Services/UserService.java): business service · Coordinates profile, account, and user lifecycle operations. · `src/main/java/com/scm/Services/UserService.java`
- [Contact Service](https://github.com/arunshar2725/smart-contact-manager/blob/main/src/main/java/com/scm/Services/ContactService.java): business service · Handles contact CRUD, ownership, search, and updates. · `src/main/java/com/scm/Services/ContactService.java`
- [Email Service](https://github.com/arunshar2725/smart-contact-manager/blob/main/src/main/java/com/scm/Services/EmailService.java): outbound messaging · Sends application emails and message-based notifications. · `src/main/java/com/scm/Services/EmailService.java`
- [Image Service](https://github.com/arunshar2725/smart-contact-manager/blob/main/src/main/java/com/scm/Services/ImageService.java): media service · Processes and stores profile and contact images. · `src/main/java/com/scm/Services/ImageService.java`
- [Form Models](https://github.com/arunshar2725/smart-contact-manager/tree/main/src/main/java/com/scm/forms): web DTOs · Separates request input from persistence entities. · `src/main/java/com/scm/forms`

### Security

Authentication, OAuth2, and access control boundary.

- [Security Config](https://github.com/arunshar2725/smart-contact-manager/blob/main/src/main/java/com/scm/config/SecurityConfig.java): security config · Defines login, OAuth2, and authorization rules. · `src/main/java/com/scm/config/SecurityConfig.java`
- [User Details](https://github.com/arunshar2725/smart-contact-manager/blob/main/src/main/java/com/scm/Services/impl/SecurityCustomUserDetailService.java): auth adapter · Bridges application users into Spring Security. · `src/main/java/com/scm/Services/impl/SecurityCustomUserDetailService.java`
- [Auth Handlers](https://github.com/arunshar2725/smart-contact-manager/blob/main/src/main/java/com/scm/config/OAuthAuthenticationSuccessHandler.java): login flow · Handles OAuth success and authentication failure paths. · `src/main/java/com/scm/config/OAuthAuthenticationSuccessHandler.java`

### Persistence

Entities and Spring Data repositories backed by MySQL.

- [Domain Entities](https://github.com/arunshar2725/smart-contact-manager/tree/main/src/main/java/com/scm/entities): JPA models · Core user, contact, social link, and provider models. · `src/main/java/com/scm/entities`
- [Repositories](https://github.com/arunshar2725/smart-contact-manager/tree/main/src/main/java/com/scm/Repositories): Spring Data · Data access for users, contacts, feedback, and messages. · `src/main/java/com/scm/Repositories`
- **MySQL**: relational database · Persistent backing store for users, contacts, and messages.

### Infrastructure

Bootstrap, configuration, validation, and error handling.

- [Application](https://github.com/arunshar2725/smart-contact-manager/blob/main/src/main/java/com/scm/Application.java): Spring Boot app · Bootstraps the monolith and wires the overall runtime. · `src/main/java/com/scm/Application.java`
- [Exception Handler](https://github.com/arunshar2725/smart-contact-manager/blob/main/src/main/java/com/scm/handlers/GlobalExceptionHandler.java): error boundary · Centralizes not-found and global exception rendering. · `src/main/java/com/scm/handlers/GlobalExceptionHandler.java`
- [Validators](https://github.com/arunshar2725/smart-contact-manager/tree/main/src/main/java/com/scm/validators): input validation · Validates uploaded files and custom form constraints. · `src/main/java/com/scm/validators`
- [Helpers](https://github.com/arunshar2725/smart-contact-manager/tree/main/src/main/java/com/scm/helpers): shared utils · Session messages, constants, and small cross-cutting helpers. · `src/main/java/com/scm/helpers`

## Connections

- Application → Security Config: configures · Application startup loads the security boundary.
- Application → Web Controllers: hosts · Bootstraps the MVC web layer.
- Application → User Service: wires · Creates the service layer beans.
- Application → Contact Service: wires · Creates the service layer beans.
- Application → Email Service: wires · Creates the service layer beans.
- Application → Image Service: wires · Creates the service layer beans.
- Security Config → User Details: uses · Authentication relies on custom user lookup.
- Security Config → Auth Handlers: delegates · Login success and failure are handled separately.
- Web Controllers → Thymeleaf Views: renders · Controllers resolve server-side HTML views.
- Web Controllers → Form Models: binds · Request bodies and form posts map into form objects.
- Web Controllers → User Service: calls · User-related requests are coordinated through services.
- Web Controllers → Contact Service: calls · Contact CRUD and search flow through the service layer.
- Web Controllers → Email Service: triggers · Feedback and message flows can send outbound email.
- Web Controllers → Image Service: triggers · Profile and contact image actions route here.
- Web Controllers → Exception Handler: handled by · Exceptions are centralized for consistent responses.
- Web Controllers → Validators: validates · Upload and custom input checks happen before persistence.
- User Service → Repositories: persists via · User workflows read and write through repositories.
- Contact Service → Repositories: persists via · Contact workflows read and write through repositories.
- User Service → Domain Entities: maps · User operations act on JPA entities.
- Contact Service → Domain Entities: maps · Contact operations act on JPA entities.
- Repositories → MySQL: stores in · Repositories persist data in MySQL.
- Form Models → Domain Entities: translates to · Forms isolate web input from JPA models.
- Helpers → Web Controllers: supports · Messaging and session helpers are used by web flows.
- Helpers → Security Config: supports · Shared auth-related utilities support security flows.
- Thymeleaf Views → Static Assets: enhanced by · Pages rely on local CSS and JS assets.
