# devaspirant0510/aicoding-backend architecture

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

- Interactive diagram: https://gitdiagram.com/devaspirant0510/aicoding-backend
- Repository: https://github.com/devaspirant0510/aicoding-backend

## Overview

##### Project Type and Purpose
- This is a backend service built in Kotlin (using Gradle) that appears to be part of an “AI Coding” solution. It exposes REST API endpoints (via controllers), implements business logic (in services and domain models), and interacts with a data persistence layer (using repositories and entities).
- The “AICoding-Backend” likely serves as the API server in a full-stack ecosystem, responsible for managing account services, code review processes, coding tests, quizzes, content, and dashboard functionality while incorporating security (JWT, security configurations) and API documentation (Swagger).

##### File Structure for Architectural Layers
- The project is clearly organized into distinct layers:
- Configuration: In src/main/kotlin/ngod/dev/aicoding/configuration, you have several configuration classes (PropertyConfig, SecurityConfig, SwaggerConfig, WebConfig) that set up properties, security, API documentation, and web-specific settings.
- Controller Layer: All controllers are under src/main/kotlin/ngod/dev/aicoding/controller. There are subdirectories for “account”, “codeReview”, “codingTest”, “content”, “dashboard”, and “quiz”; each exposing specific API endpoints along with their DTOs.
- Core and Utility: The “core” directory contains common utilities like ApiResult for uniform responses, JWT and Bcrypt providers for security, global exception handling, filters, and models for tokens.
- Domain/Service Layer: Business logic is implemented in the “domain/service” package, where each major feature (accounts, code reviews, coding tests, etc.) has its own service class.
- Data Persistence Layer: The “data” directory holds entity models, enumerations, repositories, and projections. This layer interacts with the underlying database.
- Tests: There is a parallel structure in src/test to ensure that services and core functionalities are properly validated.

A. Main Components to Include:
- Client / API Consumers: Represent external clients (e.g., frontend applications, mobile apps, or third-party integrations) that interact with the backend via HTTP requests.
- API Gateway/Controller Layer: A block signifying the controllers (AccountController, CodeReviewController, etc.). These components receive requests and forward them to the service layer.
- Data Access Layer: Aggregate repository interfaces and the underlying data stores. Indicate how repository classes (AccountRepository, CodeReviewRepository, etc.) work with data entities to perform CRUD operations.
- Cross-cutting Concerns & Infrastructure:
- Security Component: Include JWT Provider, Bcrypt usage, and the Security and Filter configuration.
- Configuration & Documentation: Represent the Swagger configuration and other property-based configurations.
- Exception Handling: Highlight the GlobalExceptionHandler and related core components.

B. Relationships and Interactions:
- Services to the Data Access layer (Repositories) to signify database interactions.
- Optionally, if external services or API integrations exist (e.g., for AI code review), illustrate these external calls as separate nodes linked to the appropriate service (likely the GptService).

C. Architectural Patterns and Technologies:
- Typical layered architecture (Controller → Service → Repository).
- That the project follows the MVC (Model-View-Controller) approach in its API design.
- Mention the use of JWT-based authentication for security.
- Kotlin and Gradle as the development tools, and indicate use of Swagger for API documentation.

- Use clear, descriptive labels (e.g., “Account Controller”, “CodeReview Service”, “JWT Filter”, “Database – Repositories”) for each component.

##### Essential Elements
- Client → API Gateway/Controllers → Service Layer
- Service Layer → Data Access (Repositories/Database)
- Security flow: Request → JwtAuthenticationFilter → Controller
- Error handling: Controllers → GlobalExceptionHandler

## Diagram (Mermaid)

```mermaid
flowchart TD
    A["Client/API Consumer"]:::client
    A -->|"HTTP_request"| F["JWTAuthenticationFilter"]:::security

    subgraph "API Controllers"
        CT1["Account Controller"]:::controller
        CT2["CodeReview Controller"]:::controller
        CT3["CodingTest Controller"]:::controller
        CT4["Content Controller"]:::controller
        CT5["Dashboard Controller"]:::controller
        CT6["Quiz Controller"]:::controller
    end

    F --> CT1
    F --> CT2
    F --> CT3
    F --> CT4
    F --> CT5
    F --> CT6

    subgraph "Domain Services"
        S1["Account Service"]:::service
        S2["CodeReview Service"]:::service
        S3["CodingTest Service"]:::service
        S4["Content Service"]:::service
        S5["Dashboard Service"]:::service
        S6["Quiz Service"]:::service
        S7["Gpt Service"]:::service
    end

    CT1 -->|"calls"| S1
    CT2 -->|"calls"| S2
    CT3 -->|"calls"| S3
    CT4 -->|"calls"| S4
    CT5 -->|"calls"| S5
    CT6 -->|"calls"| S6

    S7 -->|"calls"| Ext["External AI Service"]:::external

    subgraph "Data Access Layer"
        R1["Account Repository"]:::repository
        R2["CodeReview Repository"]:::repository
        R3["CodingTest Repository"]:::repository
        R4["Quiz Repository"]:::repository
        R5["BaseContent Repository"]:::repository
        DB["Database (Data Entities)"]:::database
    end

    S1 -->|"CRUD"| R1
    S2 -->|"CRUD"| R2
    S3 -->|"CRUD"| R3
    S4 -->|"CRUD"| R5
    S6 -->|"CRUD"| R4

    R1 --> DB
    R2 --> DB
    R3 --> DB
    R4 --> DB
    R5 --> DB

    subgraph "Configuration & Infrastructure"
        C1["Property Config"]:::config
        C2["Security Config"]:::config
        C3["Swagger Config"]:::config
        C4["Web Config"]:::config
    end

    subgraph "Security & Core Utilities"
        SEC1["JWT Provider"]:::security
        SEC2["Bcrypt Provider"]:::security
        EH["Global Exception Handler"]:::security
        U1["ApiResult Utility"]:::utils
        U2["AccessTokenPayload"]:::utils
        U3["RefreshTokenPayload"]:::utils
    end

    %% Cross-cutting connections
    F --> EH
    CT1 --> EH
    CT2 --> EH
    CT3 --> EH
    CT4 --> EH
    CT5 --> EH
    CT6 --> EH

    S1 --"uses"--> SEC1
    S2 --"uses"--> SEC1
    S3 --"uses"--> SEC1
    S1 --"utilizes"--> U1

    %% Click Events for API Controllers
    click CT1 "https://github.com/devaspirant0510/aicoding-backend/blob/main/src/main/kotlin/ngod/dev/aicoding/controller/account/AccountController.kt"
    click CT2 "https://github.com/devaspirant0510/aicoding-backend/blob/main/src/main/kotlin/ngod/dev/aicoding/controller/codeReview/CodeReivewController.kt"
    click CT3 "https://github.com/devaspirant0510/aicoding-backend/blob/main/src/main/kotlin/ngod/dev/aicoding/controller/codingTest/CodingTestController.kt"
    click CT4 "https://github.com/devaspirant0510/aicoding-backend/blob/main/src/main/kotlin/ngod/dev/aicoding/controller/content/ContentController.kt"
    click CT5 "https://github.com/devaspirant0510/aicoding-backend/blob/main/src/main/kotlin/ngod/dev/aicoding/controller/dashboard/DashboardController.kt"
    click CT6 "https://github.com/devaspirant0510/aicoding-backend/blob/main/src/main/kotlin/ngod/dev/aicoding/controller/quiz/QuizController.kt"

    %% Click Events for Domain Services
    click S1 "https://github.com/devaspirant0510/aicoding-backend/blob/main/src/main/kotlin/ngod/dev/aicoding/domain/service/AccountService.kt"
    click S2 "https://github.com/devaspirant0510/aicoding-backend/blob/main/src/main/kotlin/ngod/dev/aicoding/domain/service/CodeReviewService.kt"
    click S3 "https://github.com/devaspirant0510/aicoding-backend/blob/main/src/main/kotlin/ngod/dev/aicoding/domain/service/CodingTestService.kt"
    click S4 "https://github.com/devaspirant0510/aicoding-backend/blob/main/src/main/kotlin/ngod/dev/aicoding/domain/service/ContentService.kt"
    click S5 "https://github.com/devaspirant0510/aicoding-backend/blob/main/src/main/kotlin/ngod/dev/aicoding/domain/service/DashboardService.kt"
    click S6 "https://github.com/devaspirant0510/aicoding-backend/blob/main/src/main/kotlin/ngod/dev/aicoding/domain/service/QuizService.kt"
    click S7 "https://github.com/devaspirant0510/aicoding-backend/blob/main/src/main/kotlin/ngod/dev/aicoding/domain/service/GptService.kt"

    %% Click Events for Data Access Layer
    click R1 "https://github.com/devaspirant0510/aicoding-backend/blob/main/src/main/kotlin/ngod/dev/aicoding/data/repository/AccountRepository.kt"
    click R2 "https://github.com/devaspirant0510/aicoding-backend/blob/main/src/main/kotlin/ngod/dev/aicoding/data/repository/CodeReviewRepository.kt"
    click R3 "https://github.com/devaspirant0510/aicoding-backend/blob/main/src/main/kotlin/ngod/dev/aicoding/data/repository/CodingTestRepository.kt"
    click R4 "https://github.com/devaspirant0510/aicoding-backend/blob/main/src/main/kotlin/ngod/dev/aicoding/data/repository/QuizRepository.kt"
    click R5 "https://github.com/devaspirant0510/aicoding-backend/blob/main/src/main/kotlin/ngod/dev/aicoding/data/repository/BaseContentRepository.kt"

    %% Click Events for Configuration & Infrastructure
    click C1 "https://github.com/devaspirant0510/aicoding-backend/blob/main/src/main/kotlin/ngod/dev/aicoding/configuration/PropertyConfig.kt"
    click C2 "https://github.com/devaspirant0510/aicoding-backend/blob/main/src/main/kotlin/ngod/dev/aicoding/configuration/SecurityConfig.kt"
    click C3 "https://github.com/devaspirant0510/aicoding-backend/blob/main/src/main/kotlin/ngod/dev/aicoding/configuration/SwaggerConfig.kt"
    click C4 "https://github.com/devaspirant0510/aicoding-backend/blob/main/src/main/kotlin/ngod/dev/aicoding/configuration/WebConfig.kt"

    %% Click Events for Security & Core Utilities
    click SEC1 "https://github.com/devaspirant0510/aicoding-backend/blob/main/src/main/kotlin/ngod/dev/aicoding/core/JwtProvider.kt"
    click SEC2 "https://github.com/devaspirant0510/aicoding-backend/blob/main/src/main/kotlin/ngod/dev/aicoding/core/BcryptProvider.kt"
    click F "https://github.com/devaspirant0510/aicoding-backend/blob/main/src/main/kotlin/ngod/dev/aicoding/core/filter/JwtAuthenticationFilter.kt"
    click EH "https://github.com/devaspirant0510/aicoding-backend/blob/main/src/main/kotlin/ngod/dev/aicoding/core/handler/GlobalExceptionHandler.kt"
    click U1 "https://github.com/devaspirant0510/aicoding-backend/blob/main/src/main/kotlin/ngod/dev/aicoding/core/ApiResult.kt"
    click U2 "https://github.com/devaspirant0510/aicoding-backend/blob/main/src/main/kotlin/ngod/dev/aicoding/core/model/AccessTokenPayload.kt"
    click U3 "https://github.com/devaspirant0510/aicoding-backend/blob/main/src/main/kotlin/ngod/dev/aicoding/core/model/RefreshTokenPayload.kt"

    classDef client fill:#FFD700,stroke:#333,stroke-width:2px
    classDef controller fill:#87CEFA,stroke:#333,stroke-width:2px
    classDef service fill:#90EE90,stroke:#333,stroke-width:2px
    classDef repository fill:#D3D3D3,stroke:#333,stroke-width:2px
    classDef database fill:#F4A460,stroke:#333,stroke-width:2px,stroke-dasharray: 5 5
    classDef config fill:#FFDEAD,stroke:#333,stroke-width:2px
    classDef security fill:#FFB6C1,stroke:#333,stroke-width:2px
    classDef utils fill:#E6E6FA,stroke:#333,stroke-width:2px
    classDef external fill:#DDA0DD,stroke:#333,stroke-width:2px
```
