# chandru2002-2/campusflow-backend architecture

> Architecture diagram of the GitHub repository chandru2002-2/campusflow-backend, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2026-05-13). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/chandru2002-2/campusflow-backend
- Repository: https://github.com/chandru2002-2/campusflow-backend

## Overview

1. **Overall shape**
   - This is a single Spring Boot 3 backend service built with Maven and Java 17.
   - It exposes REST APIs for campus user management, with authentication, authorization, and database-backed CRUD.

2. **Entry point and runtime**
   - `CampusFlowBackendApplication` is the Spring Boot bootstrap class.
   - `application.properties` is the main runtime configuration surface, likely holding MySQL connection details and security-related settings.

3. **Request boundary: controllers**
   - The API layer is split into `AuthController`, `UserController`, and `AdminController`.
   - These controllers form the external HTTP boundary and map requests into service calls.
   - The README indicates `/auth/*` handles login/register, while `/users/*` handles CRUD with role-based access.

4. **Application business layer**
   - `UserService` is the main business logic layer.
   - It sits between controllers and persistence, handling user registration, login-related workflows, and user CRUD behavior.
   - The service layer is the natural place where validation, role checks, password handling, and DTO mapping are coordinated.

5. **Persistence boundary**
   - `UserRepository` is the Spring Data JPA interface for database access.
   - `User` is the JPA entity representing the `users` table described in the README.
   - The database is MySQL, and the repository is the only direct persistence abstraction visible in the tree.

6. **API contract and data shaping**
   - The `dto` package contains `LoginDTO`, `UserRequestDTO`, and `UserResponseDTO`.
   - This indicates the API does not expose entities directly; instead, requests and responses are normalized through DTOs.
   - That creates a clean boundary between external payloads and internal persistence models.

7. **Authentication flow**
   - `AuthController` likely accepts login/register requests, delegates to the service, and returns JWT-bearing responses.
   - `JwtUtil` is responsible for token creation and validation.
   - `JwtFilter` sits in the Spring Security filter chain and validates incoming bearer tokens before protected endpoints execute.

8. **Authorization model**
   - `SecurityConfig` defines the security rules for public and protected routes.
   - The README describes two roles: `ADMIN` and `USER`.
   - Access control is endpoint-level: user read/update APIs are available to both roles, while delete is admin-only.

9. **Error handling and API resilience**
   - `GlobalExceptionHandler` centralizes exception-to-response translation.
   - This suggests controllers/services throw domain or validation exceptions that are converted into consistent HTTP error responses rather than leaking stack details.

10. **Data flow across the system**
   - A typical request enters a controller, is authorized by Spring Security/JWT filter, then processed by the service, which uses the repository to read/write MySQL.
   - Responses are converted into DTOs before leaving the service/controller boundary.
   - Registration hashes passwords with BCrypt, and login produces a JWT that becomes the caller’s credential for future requests.

11. **Operational and delivery tooling**
   - The repo includes the Maven wrapper and a GitHub Actions workflow under `.github/workflows/maven.yml`, so it is set up for repeatable builds and CI.
   - Tests exist under `src/test`, though only the Spring Boot context test is visible in the tree.

12. **Architecture diagram boundaries to draw**
   - External clients: curl/Postman/frontend calling REST endpoints.
   - Security boundary: JWT bearer token validation and role enforcement.
   - Application boundary: controllers → service → repository.
   - Infrastructure boundary: MySQL database, Maven build, and CI workflow.

Main entry points: [`src/main/java/com/example/CamplusFlow/service/UserService.java`](https://github.com/chandru2002-2/campusflow-backend/blob/main/src/main/java/com/example/CamplusFlow/service/UserService.java) (User service), [`src/main/java/com/example/CamplusFlow/config/SecurityConfig.java`](https://github.com/chandru2002-2/campusflow-backend/blob/main/src/main/java/com/example/CamplusFlow/config/SecurityConfig.java) (Security config), [`src/main/java/com/example/CamplusFlow/CampusFlowBackendApplication.java`](https://github.com/chandru2002-2/campusflow-backend/blob/main/src/main/java/com/example/CamplusFlow/CampusFlowBackendApplication.java) (Boot app), [`src/main/java/com/example/CamplusFlow/controller/AuthController.java`](https://github.com/chandru2002-2/campusflow-backend/blob/main/src/main/java/com/example/CamplusFlow/controller/AuthController.java) (Auth API)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_entry["HTTP API"]
  node_client(("API client<br/>caller"))
  node_auth_controller["Auth API<br/>controller"]
  node_user_controller["User API<br/>controller"]
  node_admin_controller["Admin API<br/>controller"]
end

subgraph group_app["Application"]
  node_user_service["User service<br/>[UserService.java]"]
  node_login_dto["Login DTO<br/>[LoginDTO.java]"]
  node_user_request_dto["User request<br/>dto"]
  node_user_response_dto["User response<br/>dto"]
  node_exception_handler["Exception handler<br/>api advice"]
end

subgraph group_sec["Security"]
  node_jwt_filter["JWT filter<br/>security filter<br/>[JwtFilter.java]"]
  node_jwt_util["JWT util<br/>token service<br/>[JwtUtil.java]"]
  node_security_config["Security config"]
end

subgraph group_infra["Infrastructure"]
  node_user_entity[("User entity<br/>jpa entity<br/>[User.java]")]
  node_user_repository["User repo<br/>spring data"]
  node_mysql[("MySQL<br/>database")]
  node_application{{"Boot app<br/>spring boot"}}
  node_runtime_config["App config<br/>runtime config"]
  node_maven_ci["Build & CI<br/>build pipeline"]
end

node_client -->|"allowed by"| node_security_config
node_client -->|"bearer token"| node_jwt_filter
node_jwt_filter -->|"verifies"| node_jwt_util
node_security_config -->|"permits"| node_auth_controller
node_security_config -->|"protects"| node_user_controller
node_security_config -->|"protects"| node_admin_controller
node_auth_controller -->|"delegates"| node_user_service
node_user_controller -->|"delegates"| node_user_service
node_admin_controller -->|"delegates"| node_user_service
node_user_service -->|"uses"| node_login_dto
node_user_service -->|"uses"| node_user_request_dto
node_user_service -->|"returns"| node_user_response_dto
node_user_service -->|"reads/writes"| node_user_repository
node_user_repository -->|"maps"| node_user_entity
node_user_entity -->|"stored in"| node_mysql
node_auth_controller -->|"errors to"| node_exception_handler
node_user_controller -->|"errors to"| node_exception_handler
node_user_service -->|"throws"| node_exception_handler
node_application -->|"loads"| node_runtime_config
node_application -->|"wires"| node_security_config
node_application -->|"starts with"| node_user_service
node_maven_ci -.->|"builds"| node_application

click node_auth_controller "https://github.com/chandru2002-2/campusflow-backend/blob/main/src/main/java/com/example/CamplusFlow/controller/AuthController.java"
click node_user_controller "https://github.com/chandru2002-2/campusflow-backend/blob/main/src/main/java/com/example/CamplusFlow/controller/UserController.java"
click node_admin_controller "https://github.com/chandru2002-2/campusflow-backend/blob/main/src/main/java/com/example/CamplusFlow/controller/AdminController.java"
click node_user_service "https://github.com/chandru2002-2/campusflow-backend/blob/main/src/main/java/com/example/CamplusFlow/service/UserService.java"
click node_login_dto "https://github.com/chandru2002-2/campusflow-backend/blob/main/src/main/java/com/example/CamplusFlow/dto/LoginDTO.java"
click node_user_request_dto "https://github.com/chandru2002-2/campusflow-backend/blob/main/src/main/java/com/example/CamplusFlow/dto/UserRequestDTO.java"
click node_user_response_dto "https://github.com/chandru2002-2/campusflow-backend/blob/main/src/main/java/com/example/CamplusFlow/dto/UserResponseDTO.java"
click node_user_entity "https://github.com/chandru2002-2/campusflow-backend/blob/main/src/main/java/com/example/CamplusFlow/model/User.java"
click node_user_repository "https://github.com/chandru2002-2/campusflow-backend/blob/main/src/main/java/com/example/CamplusFlow/repository/UserRepository.java"
click node_jwt_filter "https://github.com/chandru2002-2/campusflow-backend/blob/main/src/main/java/com/example/CamplusFlow/security/JwtFilter.java"
click node_jwt_util "https://github.com/chandru2002-2/campusflow-backend/blob/main/src/main/java/com/example/CamplusFlow/security/JwtUtil.java"
click node_security_config "https://github.com/chandru2002-2/campusflow-backend/blob/main/src/main/java/com/example/CamplusFlow/config/SecurityConfig.java"
click node_exception_handler "https://github.com/chandru2002-2/campusflow-backend/blob/main/src/main/java/com/example/CamplusFlow/exception/GlobalExceptionHandler.java"
click node_application "https://github.com/chandru2002-2/campusflow-backend/blob/main/src/main/java/com/example/CamplusFlow/CampusFlowBackendApplication.java"
click node_runtime_config "https://github.com/chandru2002-2/campusflow-backend/blob/main/src/main/resources/application.properties"

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_client,node_auth_controller,node_user_controller,node_admin_controller toneBlue
class node_user_service,node_login_dto,node_user_request_dto,node_user_response_dto,node_exception_handler toneAmber
class node_jwt_filter,node_jwt_util,node_security_config toneMint
class node_user_entity,node_user_repository,node_mysql,node_application,node_runtime_config,node_maven_ci toneRose
```

## Components

### HTTP API

External request boundary and REST controllers

- **API client**: caller · Frontend, curl, or Postman using the REST API
- [Auth API](https://github.com/chandru2002-2/campusflow-backend/blob/main/src/main/java/com/example/CamplusFlow/controller/AuthController.java): controller · Handles login and registration endpoints · `src/main/java/com/example/CamplusFlow/controller/AuthController.java`
- [User API](https://github.com/chandru2002-2/campusflow-backend/blob/main/src/main/java/com/example/CamplusFlow/controller/UserController.java): controller · Handles user CRUD endpoints · `src/main/java/com/example/CamplusFlow/controller/UserController.java`
- [Admin API](https://github.com/chandru2002-2/campusflow-backend/blob/main/src/main/java/com/example/CamplusFlow/controller/AdminController.java): controller · Admin-focused endpoints and privileged operations · `src/main/java/com/example/CamplusFlow/controller/AdminController.java`

### Application

Core service and shared API contracts

- [User service](https://github.com/chandru2002-2/campusflow-backend/blob/main/src/main/java/com/example/CamplusFlow/service/UserService.java): service · Coordinates registration, login, validation, and user CRUD · `src/main/java/com/example/CamplusFlow/service/UserService.java`
- [Login DTO](https://github.com/chandru2002-2/campusflow-backend/blob/main/src/main/java/com/example/CamplusFlow/dto/LoginDTO.java): dto · Login request payload · `src/main/java/com/example/CamplusFlow/dto/LoginDTO.java`
- [User request](https://github.com/chandru2002-2/campusflow-backend/blob/main/src/main/java/com/example/CamplusFlow/dto/UserRequestDTO.java): dto · Create and update payloads · `src/main/java/com/example/CamplusFlow/dto/UserRequestDTO.java`
- [User response](https://github.com/chandru2002-2/campusflow-backend/blob/main/src/main/java/com/example/CamplusFlow/dto/UserResponseDTO.java): dto · Public user response shape · `src/main/java/com/example/CamplusFlow/dto/UserResponseDTO.java`
- [Exception handler](https://github.com/chandru2002-2/campusflow-backend/blob/main/src/main/java/com/example/CamplusFlow/exception/GlobalExceptionHandler.java): api advice · Converts failures into HTTP responses · `src/main/java/com/example/CamplusFlow/exception/GlobalExceptionHandler.java`

### Security

JWT authentication and access control

- [JWT filter](https://github.com/chandru2002-2/campusflow-backend/blob/main/src/main/java/com/example/CamplusFlow/security/JwtFilter.java): security filter · Validates bearer tokens on protected requests · `src/main/java/com/example/CamplusFlow/security/JwtFilter.java`
- [JWT util](https://github.com/chandru2002-2/campusflow-backend/blob/main/src/main/java/com/example/CamplusFlow/security/JwtUtil.java): token service · Creates and validates JWTs · `src/main/java/com/example/CamplusFlow/security/JwtUtil.java`
- [Security config](https://github.com/chandru2002-2/campusflow-backend/blob/main/src/main/java/com/example/CamplusFlow/config/SecurityConfig.java): security config · Defines protected routes and role rules · `src/main/java/com/example/CamplusFlow/config/SecurityConfig.java`

### Infrastructure

Persistence, runtime config, and delivery tooling

- [User entity](https://github.com/chandru2002-2/campusflow-backend/blob/main/src/main/java/com/example/CamplusFlow/model/User.java): jpa entity · Database-backed user model · `src/main/java/com/example/CamplusFlow/model/User.java`
- [User repo](https://github.com/chandru2002-2/campusflow-backend/blob/main/src/main/java/com/example/CamplusFlow/repository/UserRepository.java): spring data · Persistence abstraction for users · `src/main/java/com/example/CamplusFlow/repository/UserRepository.java`
- **MySQL**: database · Primary persistent store
- [Boot app](https://github.com/chandru2002-2/campusflow-backend/blob/main/src/main/java/com/example/CamplusFlow/CampusFlowBackendApplication.java): spring boot · Application startup entry point · `src/main/java/com/example/CamplusFlow/CampusFlowBackendApplication.java`
- [App config](https://github.com/chandru2002-2/campusflow-backend/blob/main/src/main/resources/application.properties): runtime config · Main application properties and environment settings · `src/main/resources/application.properties`
- **Build & CI**: build pipeline · Maven wrapper and GitHub Actions workflow

## Connections

- API client → Security config: allowed by · Requests are governed by security rules before reaching controllers
- API client → JWT filter: bearer token · Authenticated calls present JWTs
- JWT filter → JWT util: verifies · Filter delegates token validation to JWT utility
- Security config → Auth API: permits · Public auth endpoints are exposed
- Security config → User API: protects · User routes require authentication and role checks
- Security config → Admin API: protects · Admin routes enforce privileged access
- Auth API → User service: delegates · Login and registration flow into application logic
- User API → User service: delegates · CRUD requests go through the service layer
- Admin API → User service: delegates · Admin operations reuse user management logic
- User service → Login DTO: uses · Consumes login payloads
- User service → User request: uses · Consumes user write payloads
- User service → User response: returns · Shapes responses for API consumers
- User service → User repo: reads/writes · Persists and loads users
- User repo → User entity: maps · Repository operates on the JPA entity
- User entity → MySQL: stored in · User records live in MySQL
- Auth API → Exception handler: errors to · Controller failures are normalized into responses
- User API → Exception handler: errors to · Controller failures are normalized into responses
- User service → Exception handler: throws · Business and validation exceptions are translated centrally
- Boot app → App config: loads · Bootstraps from runtime configuration
- Boot app → Security config: wires · Starts the security setup
- Boot app → User service: starts with · Application bootstraps the service graph
- Build & CI → Boot app: builds · CI and Maven wrapper compile and test the app
