# team-moiza/moiza_server architecture

> Architecture diagram of the GitHub repository team-moiza/moiza_server, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2025-04-06). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/team-moiza/moiza_server
- Repository: https://github.com/team-moiza/moiza_server

## Overview

##### Project Type and Purpose
- This is clearly a backend server application written in Kotlin with Gradle as the build tool. It appears to be organized around domain-driven design with clearly separated modules for different business concerns (authentication, code management, likes, portfolios, and user management).
- The project leverages a layered architecture (presentation, service, and repository/domain layers) along with global concerns such as error handling, configuration, security, and external API integration (using Feign clients).

##### Break Down the File Structure into Main Architectural Components
- Application Entry Point:
- At the root of the business logic is the MoizaApplication.kt which bootstraps the Spring Boot application.
- Domain Modules (each in its own subpackage):
- Auth Module: Contains domain entities, repositories, exception handling, controllers, DTOs, and services (e.g., GoogleAuthService, ReissueService). This module also handles external token management (JWT) and integration with Google.
- Code Module: Manages “code” entities (Code, ProjectCode, PortfolioCode) along with corresponding repositories, exceptions, controllers, DTOs, and services.
- Like Module: Manages functionality for handling likes (entities, repositories, exceptions, controllers, DTOs, and services).
- Portfolio Module: Deals with portfolio-related entities (Portfolio, Award, Introduction, etc.), repositories, controllers, DTOs, and services (including creation, update, deletion, and queries).
- User Module: Manages user-related entities including repositories, services, controllers, and presentation DTOs.
- Global/Common Packages:
- Global Config: Configuration files (SecurityConfig, FeignConfig, RedisConfig, QuerydslConfig, etc.) and properties files that set up the environment for the application.
- Global Error Handling: Contains a unified error handling strategy (GlobalExceptionHandler, custom BusinessException and ErrorCode definitions).
- Global Security and JWT: Classes associated with JWT filter, token provider, and principal details for authentication.
- Global Feign Clients: Responsible for communicating with external services like Google (GoogleInformationClient) and Nextcloud (NextcloudShareClient, NextcloudUploadClient) for file sharing/uploads.
- Utility Packages: Utilities for nextcloud functionalities and Thymeleaf template processing (e.g., ProcessTemplateService).

##### Relationships and Interactions
- Client/API Layer → Controller:
- Clients (web or mobile) send HTTP requests which are routed by Spring controllers (e.g., AuthController, CodeController, LikeController, PortfolioController, UserController). Indicate these as “Presentation Layer” components.
- Controller → Service:
- Once a request is received, controllers delegate to service classes (e.g., GoogleAuthService, CreateCodeService, LikeService, CreatePortfolioService, RegisterProfileService, etc.) which implement the business logic.
- Service → Repository/Domain Layer:
- Services interact with repositories (e.g., UserRepository, CodeRepository, PortfolioRepository, RefreshTokenRepository) to perform data operations.
- External Integrations:
- Some services or global configurations interact with external APIs via Feign (GoogleInformationClient for authentication details and Nextcloud clients for file handling). These should be shown linking to external systems.
- Utility & Configurations:
- Global configurations (SecurityConfig, QuerydslConfig, RedisConfig, etc.) and error handling modules sit alongside these layers to provide cross-cutting concerns.

##### Important Architectural Patterns and Technologies
- Layered Architecture: Clear separation into presentation (controllers), service (business logic), and persistence (repository/domain) layers.
- Domain-Driven Design: Each feature (auth, code, like, portfolio, user) is self-contained with its own domain entities, business rules, and handling.
- External Integration via Feign: The project uses Feign clients for integrating with services like Google and Nextcloud.
- Security: JWT-based security (filters, token providers, and custom exceptions) are present.
- Config & Error Handling: Global configuration and error management are modular and reusable across layers.

##### Elements
- Clear labels for each component:
- Annotate:
- Brief notes (e.g., “Handles OAuth token reissue”, “Integrates with external Nextcloud API”) to capture critical functionality and interactions.

## Diagram (Mermaid)

```mermaid
flowchart TD
    %% Client Layer
    subgraph "Client Layer"
        CLIENT("Client/API Consumer"):::external
    end

    %% Application Entry Point
    subgraph "Application Layer"
        APP("Moiza Application"):::global
    end

    %% Presentation Layer
    subgraph "Presentation Layer"
        AUTH_CTRL("Auth Controller"):::presentation
        CODE_CTRL("Code Controller"):::presentation
        LIKE_CTRL("Like Controller"):::presentation
        PORTFOLIO_CTRL("Portfolio Controller"):::presentation
        USER_CTRL("User Controller"):::presentation
    end

    %% Service Layer
    subgraph "Service Layer"
        AUTH_SVC("Auth Service"):::service
        CODE_SVC("Code Service"):::service
        LIKE_SVC("Like Service"):::service
        PORTFOLIO_SVC("Portfolio Service"):::service
        USER_SVC("User Service"):::service
    end

    %% Repository/Domain Layer
    subgraph "Repository/Domain Layer"
        AUTH_REPO("Auth Repository"):::repository
        CODE_REPO("Code Repository"):::repository
        LIKE_REPO("Like Repository"):::repository
        PORTFOLIO_REPO("Portfolio Repository"):::repository
        USER_REPO("User Repository"):::repository
    end

    %% Global & Configurations
    subgraph "Global & Configurations"
        GLOBAL_CONFIG("Global Config"):::global
        GLOBAL_ERROR("Global Error Handling"):::global
        GLOBAL_SECURITY("Global Security (JWT)"):::global
        FEIGN_CLIENTS("Global Feign Clients"):::global
        UTILITIES("Utility Packages"):::global
    end

    %% External Systems
    subgraph "External Systems"
        GOOGLE("Google API"):::external
        NEXTCLOUD("Nextcloud API"):::external
    end

    %% Relationships
    APP -->|"bootstraps"| CLIENT

    CLIENT -->|"HTTP-request"| AUTH_CTRL
    CLIENT -->|"HTTP-request"| CODE_CTRL
    CLIENT -->|"HTTP-request"| LIKE_CTRL
    CLIENT -->|"HTTP-request"| PORTFOLIO_CTRL
    CLIENT -->|"HTTP-request"| USER_CTRL

    AUTH_CTRL -->|"delegates"| AUTH_SVC
    CODE_CTRL -->|"delegates"| CODE_SVC
    LIKE_CTRL -->|"delegates"| LIKE_SVC
    PORTFOLIO_CTRL -->|"delegates"| PORTFOLIO_SVC
    USER_CTRL -->|"delegates"| USER_SVC

    AUTH_SVC -->|"calls"| AUTH_REPO
    CODE_SVC -->|"calls"| CODE_REPO
    LIKE_SVC -->|"calls"| LIKE_REPO
    PORTFOLIO_SVC -->|"calls"| PORTFOLIO_REPO
    USER_SVC -->|"calls"| USER_REPO

    %% External integrations via Feign Clients
    AUTH_SVC -->|"integrates"| FEIGN_CLIENTS
    CODE_SVC -->|"integrates"| FEIGN_CLIENTS
    PORTFOLIO_SVC -->|"integrates"| FEIGN_CLIENTS

    FEIGN_CLIENTS -->|"Google-auth"| GOOGLE
    FEIGN_CLIENTS -->|"Nextcloud-file"| NEXTCLOUD

    %% Global concerns connections
    AUTH_SVC -->|"uses"| GLOBAL_SECURITY
    USER_SVC -->|"uses"| GLOBAL_CONFIG
    PORTFOLIO_SVC -->|"uses"| GLOBAL_ERROR
    GLOBAL_CONFIG -->|"configures"| GLOBAL_SECURITY
    GLOBAL_CONFIG -->|"configures"| FEIGN_CLIENTS
    GLOBAL_CONFIG -->|"configures"| UTILITIES

    %% Error handling across services
    AUTH_SVC -->|"error-handling"| GLOBAL_ERROR
    CODE_SVC -->|"error-handling"| GLOBAL_ERROR
    LIKE_SVC -->|"error-handling"| GLOBAL_ERROR
    PORTFOLIO_SVC -->|"error-handling"| GLOBAL_ERROR
    USER_SVC -->|"error-handling"| GLOBAL_ERROR

    %% Click Events
    click APP "https://github.com/team-moiza/moiza_server/blob/develop/src/main/kotlin/com/example/moiza/MoizaApplication.kt"
    click AUTH_CTRL "https://github.com/team-moiza/moiza_server/tree/develop/src/main/kotlin/com/example/moiza/domain/auth"
    click CODE_CTRL "https://github.com/team-moiza/moiza_server/tree/develop/src/main/kotlin/com/example/moiza/domain/code"
    click LIKE_CTRL "https://github.com/team-moiza/moiza_server/tree/develop/src/main/kotlin/com/example/moiza/domain/like"
    click PORTFOLIO_CTRL "https://github.com/team-moiza/moiza_server/tree/develop/src/main/kotlin/com/example/moiza/domain/portfolio"
    click USER_CTRL "https://github.com/team-moiza/moiza_server/tree/develop/src/main/kotlin/com/example/moiza/domain/user"
    click GLOBAL_CONFIG "https://github.com/team-moiza/moiza_server/tree/develop/src/main/kotlin/com/example/moiza/global/config"
    click GLOBAL_ERROR "https://github.com/team-moiza/moiza_server/tree/develop/src/main/kotlin/com/example/moiza/global/error"
    click GLOBAL_SECURITY "https://github.com/team-moiza/moiza_server/tree/develop/src/main/kotlin/com/example/moiza/global/security"
    click FEIGN_CLIENTS "https://github.com/team-moiza/moiza_server/tree/develop/src/main/kotlin/com/example/moiza/global/feign"
    click UTILITIES "https://github.com/team-moiza/moiza_server/tree/develop/src/main/kotlin/com/example/moiza/global/utils"

%% Styling Classes
classDef presentation fill:#ADD8E6,stroke:#000,stroke-width:2px;
classDef service fill:#90EE90,stroke:#000,stroke-width:2px;
classDef repository fill:#FFB6C1,stroke:#000,stroke-width:2px;
classDef global fill:#FFD700,stroke:#000,stroke-width:2px;
classDef external fill:#DDA0DD,stroke:#000,stroke-width:2px;
```
