# elmo-riyani/cst8922_backend architecture

> Architecture diagram of the GitHub repository elmo-riyani/cst8922_backend, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2025-05-18). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/elmo-riyani/cst8922_backend
- Repository: https://github.com/elmo-riyani/cst8922_backend

## Overview

##### Project type and purpose
- This is a monolithic Spring Boot–based REST API (Java/Maven) that provides user authentication (signup, login), project and tag management, and validation workflows.
- It uses Spring MVC for controllers, Spring Security for auth, Spring Data JPA for persistence, Flyway for database migrations, and MySQL as the backing store.

##### File structure
- Top-level build and config: pom.xml, Maven wrapper, GitHub Actions workflow for Azure-MySQL deployment.
- src/main/java/com/algonquincollege/team7:
– Controllers (HTTP endpoints)
– DTOs (request/response models)
– Infra: exception handling, security configuration (CorsConfig, SecurityConfiguration)
– Model: JPA entities (User, Project, Tag, Validation, etc.)
– Repository: Spring Data interfaces
– Service: business logic and token management (AuthenticationService, TokenService, etc.)
- src/main/resources: application.properties, .env, and Flyway migrations under db/migration.
- Test harness under src/test.

##### Main components and interactions
a. External Client(s)
– Browser or mobile app calling the API over HTTP(S)
b. API Server (Spring Boot application)
– Security Module: CORS filter, JWT authentication filter, SecurityConfiguration
– Controllers: LoginController, SignupController, ProjectController, TagController, etc.
– Service Layer: AuthenticationService, ProjectService, TagService, ValidationService, TokenService
– Data Access Layer: Repositories (UserRepository, ProjectRepository, etc.)
c. Database
– MySQL, initialized via Flyway (V1–V4 migrations)
d. CI/CD (outside runtime)
– GitHub Actions workflow for building and deploying to Azure MySQL

Data-flow example (Login):
Client → HTTP POST /login → Spring Security filter → LoginController → AuthenticationService → UserRepository → MySQL → TokenService issues JWT → LoginResponse → Client

##### Architectural patterns and design principles
- Layered architecture: Presentation (Controllers/DTOs), Business (Services), Data (Repositories, Models)
- MVC-style REST controllers
- Repository pattern via Spring Data JPA
- Dependency Injection (Spring IoC)
- Global exception handling with @ControllerAdvice (ErrorHandler)
- Secure by default: JWT tokens, CORS configuration

– Security Layer (CorsConfig, SecurityConfiguration)
– Controllers (seven controllers handling REST endpoints)
– Service Layer (business logic, token generation)
– Data Layer (Repositories + Domain Models)
– Client → Security Layer → Controllers → Services → Repositories → Database
– Indicate TokenService inside Services issuing JWT back to Client
e. Outside of runtime, show “GitHub Actions CI” connecting to Azure MySQL in deployment.

## Diagram (Mermaid)

```mermaid
flowchart TB
    %% External Clients
    subgraph "External Clients" 
        direction TB
        Client["Browser / Mobile App"]:::external
    end

    %% API Server
    subgraph "Spring Boot API" 
        direction TB

        %% Security Layer
        subgraph "Security Layer" 
            direction TB
            CorsConfig["CorsConfig"]:::security
            SecurityConfiguration["SecurityConfiguration"]:::security
        end

        %% Controllers
        subgraph "Controllers (Presentation Layer)" 
            direction TB
            LoginController["LoginController"]:::controller
            SignupController["SignupController"]:::controller
            ProjectController["ProjectController"]:::controller
            TagController["TagController"]:::controller
            TagTypeController["TagTypeController"]:::controller
            TagValueController["TagValueController"]:::controller
            ValidationController["ValidationController"]:::controller
        end

        %% Exception Handling
        subgraph "Global Exception Handling" 
            direction TB
            ApiException["ApiException"]:::exception
            ErrorHandler["ErrorHandler"]:::exception
        end

        %% Service Layer
        subgraph "Service Layer" 
            direction TB
            AuthenticationService["AuthenticationService"]:::service
            TokenService["TokenService"]:::service
            UserService["UserService"]:::service
            ProjectService["ProjectService"]:::service
            TagService["TagService"]:::service
            TagTypeService["TagTypeService"]:::service
            TagValueService["TagValueService"]:::service
            ValidationService["ValidationService"]:::service
        end

        %% Data Access Layer
        subgraph "Repositories (Data Layer)" 
            direction TB
            UserRepository["UserRepository"]:::repo
            ProjectRepository["ProjectRepository"]:::repo
            TagRepository["TagRepository"]:::repo
            TagTypeRepository["TagTypeRepository"]:::repo
            TagValueRepository["TagValueRepository"]:::repo
            ValidationRepository["ValidationRepository"]:::repo
        end

        %% Domain Models & DTOs
        subgraph "Models & DTOs" 
            direction TB
            Models["JPA Entities & DTOs"]:::model
        end

    end

    %% Database
    Database["MySQL Database\n(Flyway Migrations)"]:::db

    %% CI/CD
    CI["GitHub Actions CI/CD"]:::cicd

    %% Connections
    Client -->|"HTTPS Request"| CorsConfig
    SecurityConfiguration -->|passes auth| LoginController
    CorsConfig --> LoginController
    LoginController -->|"calls"| AuthenticationService
    SignupController -->|"calls"| AuthenticationService
    ProjectController -->|"calls"| ProjectService
    TagController -->|"calls"| TagService
    TagTypeController -->|"calls"| TagTypeService
    TagValueController -->|"calls"| TagValueService
    ValidationController -->|"calls"| ValidationService

    AuthenticationService -->|"accesses"| UserRepository
    ProjectService -->|"accesses"| ProjectRepository
    TagService -->|"accesses"| TagRepository
    TagTypeService -->|"accesses"| TagTypeRepository
    TagValueService -->|"accesses"| TagValueRepository
    ValidationService -->|"accesses"| ValidationRepository

    UserRepository --> Database
    ProjectRepository --> Database
    TagRepository --> Database
    TagTypeRepository --> Database
    TagValueRepository --> Database
    ValidationRepository --> Database

    AuthenticationService -->|"issues JWT"| TokenService
    TokenService -->|return token| Client

    any -->|throws ApiException| ErrorHandler
    ErrorHandler -->|HTTP Response| Client

    CI -->|"deploys to"| Database

    %% Click Events
    click Client "https://github.com/elmo-riyani/cst8922_backend/tree/main/n/a"
    click CorsConfig "https://github.com/elmo-riyani/cst8922_backend/blob/main/src/main/java/com/algonquincollege/team7/CorsConfig.java"
    click SecurityConfiguration "https://github.com/elmo-riyani/cst8922_backend/blob/main/src/main/java/com/algonquincollege/team7/infra/security/SecurityConfiguration.java"
    click ApiException "https://github.com/elmo-riyani/cst8922_backend/blob/main/src/main/java/com/algonquincollege/team7/infra/exception/ApiException.java"
    click ErrorHandler "https://github.com/elmo-riyani/cst8922_backend/blob/main/src/main/java/com/algonquincollege/team7/infra/exception/ErrorHandler.java"
    click LoginController "https://github.com/elmo-riyani/cst8922_backend/blob/main/src/main/java/com/algonquincollege/team7/controller/LoginController.java"
    click SignupController "https://github.com/elmo-riyani/cst8922_backend/blob/main/src/main/java/com/algonquincollege/team7/controller/SignupController.java"
    click ProjectController "https://github.com/elmo-riyani/cst8922_backend/blob/main/src/main/java/com/algonquincollege/team7/controller/ProjectController.java"
    click TagController "https://github.com/elmo-riyani/cst8922_backend/blob/main/src/main/java/com/algonquincollege/team7/controller/TagController.java"
    click TagTypeController "https://github.com/elmo-riyani/cst8922_backend/blob/main/src/main/java/com/algonquincollege/team7/controller/TagTypeController.java"
    click TagValueController "https://github.com/elmo-riyani/cst8922_backend/blob/main/src/main/java/com/algonquincollege/team7/controller/TagValueController.java"
    click ValidationController "https://github.com/elmo-riyani/cst8922_backend/blob/main/src/main/java/com/algonquincollege/team7/controller/ValidationController.java"
    click AuthenticationService "https://github.com/elmo-riyani/cst8922_backend/blob/main/src/main/java/com/algonquincollege/team7/service/AuthenticationService.java"
    click TokenService "https://github.com/elmo-riyani/cst8922_backend/blob/main/src/main/java/com/algonquincollege/team7/service/TokenService.java"
    click UserService "https://github.com/elmo-riyani/cst8922_backend/blob/main/src/main/java/com/algonquincollege/team7/service/UserService.java"
    click ProjectService "https://github.com/elmo-riyani/cst8922_backend/blob/main/src/main/java/com/algonquincollege/team7/service/ProjectService.java"
    click TagService "https://github.com/elmo-riyani/cst8922_backend/blob/main/src/main/java/com/algonquincollege/team7/service/TagService.java"
    click TagTypeService "https://github.com/elmo-riyani/cst8922_backend/blob/main/src/main/java/com/algonquincollege/team7/service/TagTypeService.java"
    click TagValueService "https://github.com/elmo-riyani/cst8922_backend/blob/main/src/main/java/com/algonquincollege/team7/service/TagValueService.java"
    click ValidationService "https://github.com/elmo-riyani/cst8922_backend/blob/main/src/main/java/com/algonquincollege/team7/service/ValidationService.java"
    click UserRepository "https://github.com/elmo-riyani/cst8922_backend/blob/main/src/main/java/com/algonquincollege/team7/repository/UserRepository.java"
    click ProjectRepository "https://github.com/elmo-riyani/cst8922_backend/blob/main/src/main/java/com/algonquincollege/team7/repository/ProjectRepository.java"
    click TagRepository "https://github.com/elmo-riyani/cst8922_backend/blob/main/src/main/java/com/algonquincollege/team7/repository/TagRepository.java"
    click TagTypeRepository "https://github.com/elmo-riyani/cst8922_backend/blob/main/src/main/java/com/algonquincollege/team7/repository/TagTypeRepository.java"
    click TagValueRepository "https://github.com/elmo-riyani/cst8922_backend/blob/main/src/main/java/com/algonquincollege/team7/repository/TagValueRepository.java"
    click ValidationRepository "https://github.com/elmo-riyani/cst8922_backend/blob/main/src/main/java/com/algonquincollege/team7/repository/ValidationRepository.java"
    click Database "https://github.com/elmo-riyani/cst8922_backend/blob/main/src/main/resources/db/migration/V1__create-user-table.sql"
    click CI "https://github.com/elmo-riyani/cst8922_backend/blob/main/.github/workflows/azure-mysql-connection.yml"

    %% Styles
    classDef external fill:#f9f,stroke:#333,stroke-width:1px
    classDef security fill:#bbdefb,stroke:#0d47a1,stroke-width:1px
    classDef controller fill:#bbdefb,stroke:#1e88e5,stroke-width:1px
    classDef service fill:#c8e6c9,stroke:#2e7d32,stroke-width:1px
    classDef repo fill:#ffe0b2,stroke:#ef6c00,stroke-width:1px
    classDef exception fill:#ffcdd2,stroke:#b71c1c,stroke-width:1px
    classDef model fill:#e1bee7,stroke:#4a148c,stroke-width:1px
    classDef db fill:#a5d6a7,stroke:#1b5e20,stroke-width:1px,shape:cylinder
    classDef cicd fill:#eeeeee,stroke:#424242,stroke-width:1px
```
