# makkenzo/codehorizon-api architecture

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

- Interactive diagram: https://gitdiagram.com/makkenzo/codehorizon-api
- Repository: https://github.com/makkenzo/codehorizon-api

## Overview

##### Project Type & Purpose
- The project is a backend REST API designed for an educational platform. Its primary goal is to manage and deliver educational materials such as courses, lessons, assignments, and related content.
- It uses Kotlin with Spring Boot (running on JDK 21) and integrates features like JWT-based security, Swagger API documentation, external service integrations (such as Cloudflare R2 and Stripe), and progress tracking.

##### Main Architectural Components
a. API Layer (Controllers):
– Include components for various controllers like AuthController, CourseController, PaymentController, ProfileController, etc.
– This layer exposes REST endpoints for client interactions.
b. Service Layer:
– Display services that implement the business logic (e.g., CourseService, UserService, PaymentService, StripeService, EmailService, CloudflareService).
– Show that these services handle application logic and interact with other layers.
c. Data Access Layer:
– Represent repositories such as CourseRepository, UserRepository, ProfileRepository, and others.
– This layer abstracts database interactions and data persistence.
d. Domain Models & DTOs:
e. Security & Configurations:
– Highlight components handling JWT security, CORS configurations, Swagger setup, and authentication (e.g., SecurityConfig, JwtUtils, CookieAuthAspect, CookieConfig, AuthenticationEntryPoint).
f. External Integrations:
- Cloudflare R2 (CloudflareR2Config and CloudflareService)
- Stripe (StripeService, StripeCheckoutSession)
- Email service (EmailService)
g. Additional Layers:
– Include utility classes, aspects (for example, CookieAuthAspect for handling cookie-based auth encryption or verification), and configuration artifacts.

- A flow from Controllers → Service Layer → Repository/Data Access Layer.
- Security “guard” components (e.g., JWT filters, AuthenticationEntryPoint) intercepting requests.

##### Architectural Patterns & Design Principles
- MVC/Multi-Layered Pattern: Emphasize that the project cleanly separates the concerns of Controllers, Services, and Repositories.
- Configuration Driven: Capture how Spring Boot configuration files and properties (application.properties, application-dev.properties, etc.) provide environment-specific settings.
- Aspect-Oriented Programming: Note the use of aspects (e.g., for managing cookie-based authentication).

## Diagram (Mermaid)

```mermaid
flowchart TD
    %% Client and API Layer
    subgraph "Client & API"
        ExternalClients["External Clients"]:::external
        APIControllers["API Controllers"]:::controllers
    end

    %% Business Logic Layer
    subgraph "Business Logic"
        ServiceLayer["Service Layer"]:::service
    end

    %% Data Management Layer
    subgraph "Data Management"
        Repositories["Data Access (Repositories)"]:::repo
        DomainModels["Domain Models"]:::domain
        DTOs["DTOs"]:::dto
    end

    %% Security & Configurations
    subgraph "Security & Configurations"
        SecConfig["SecurityConfig"]:::security
        AuthEntry["AuthenticationEntryPoint"]:::security
        JwtUtil["JwtUtils"]:::security
        CorsConf["CorsConfig"]:::security
        SwaggerConf["SwaggerConfig"]:::security
        CookieAuth["CookieAuth"]:::security
        CookieConf["CookieConfig"]:::security
        CookieAspect["CookieAuthAspect"]:::security
        ReqLog["RequestResponseLoggingFilter"]:::security
        SecGroup["Security & Configurations"]:::securityGroup
    end

    %% External Integrations
    subgraph "External Integrations"
        CFConfig["Cloudflare R2 Config"]:::externalIntegration
        CFService["Cloudflare Service"]:::externalIntegration
        StripeService["Stripe Service"]:::externalIntegration
        EmailService["Email Service"]:::externalIntegration
    end

    %% Utilities
    subgraph "Utilities"
        Utils["Utils"]:::utility
    end

    %% Connections
    ExternalClients -->|"HTTP_Request"| SecGroup
    SecGroup -->|"Validated"| APIControllers
    APIControllers -->|"Calls"| ServiceLayer
    ServiceLayer -->|"Executes"| Repositories
    ServiceLayer -->|"Uses"| Utils
    Repositories -->|"Persists_to"| DomainModels
    ServiceLayer -->|"Transforms_With"| DTOs
    ServiceLayer -->|"Calls"| CFService
    CFService -->|"Uses_Config"| CFConfig
    ServiceLayer -->|"Calls"| StripeService
    StripeService -->|"Uses_Model"| DomainModels
    ServiceLayer -->|"Calls"| EmailService

    %% Click Events for Component Mapping
    click APIControllers "https://github.com/makkenzo/codehorizon-api/tree/master/src/main/kotlin/com/makkenzo/codehorizon/controllers"
    click ServiceLayer "https://github.com/makkenzo/codehorizon-api/tree/master/src/main/kotlin/com/makkenzo/codehorizon/services"
    click Repositories "https://github.com/makkenzo/codehorizon-api/tree/master/src/main/kotlin/com/makkenzo/codehorizon/repositories"
    click DomainModels "https://github.com/makkenzo/codehorizon-api/tree/master/src/main/kotlin/com/makkenzo/codehorizon/models"
    click DTOs "https://github.com/makkenzo/codehorizon-api/tree/master/src/main/kotlin/com/makkenzo/codehorizon/dtos"
    
    click SecConfig "https://github.com/makkenzo/codehorizon-api/blob/master/src/main/kotlin/com/makkenzo/codehorizon/configs/SecurityConfig.kt"
    click AuthEntry "https://github.com/makkenzo/codehorizon-api/blob/master/src/main/kotlin/com/makkenzo/codehorizon/configs/AuthenticationEntryPoint.kt"
    click JwtUtil "https://github.com/makkenzo/codehorizon-api/blob/master/src/main/kotlin/com/makkenzo/codehorizon/utils/JwtUtils.kt"
    click CorsConf "https://github.com/makkenzo/codehorizon-api/blob/master/src/main/kotlin/com/makkenzo/codehorizon/configs/CorsConfig.kt"
    click SwaggerConf "https://github.com/makkenzo/codehorizon-api/blob/master/src/main/kotlin/com/makkenzo/codehorizon/configs/SwaggerConfig.kt"
    click CookieAuth "https://github.com/makkenzo/codehorizon-api/blob/master/src/main/kotlin/com/makkenzo/codehorizon/annotations/CookieAuth.kt"
    click CookieConf "https://github.com/makkenzo/codehorizon-api/blob/master/src/main/kotlin/com/makkenzo/codehorizon/configs/CookieConfig.kt"
    click CookieAspect "https://github.com/makkenzo/codehorizon-api/blob/master/src/main/kotlin/com/makkenzo/codehorizon/aspects/CookieAuthAspect.kt"
    click ReqLog "https://github.com/makkenzo/codehorizon-api/blob/master/src/main/kotlin/com/makkenzo/codehorizon/configs/RequestResponseLoggingFilter.kt"
    
    click CFConfig "https://github.com/makkenzo/codehorizon-api/blob/master/src/main/kotlin/com/makkenzo/codehorizon/configs/CloudflareR2Config.kt"
    click CFService "https://github.com/makkenzo/codehorizon-api/blob/master/src/main/kotlin/com/makkenzo/codehorizon/services/CloudflareService.kt"
    click StripeService "https://github.com/makkenzo/codehorizon-api/blob/master/src/main/kotlin/com/makkenzo/codehorizon/services/StripeService.kt"
    click EmailService "https://github.com/makkenzo/codehorizon-api/blob/master/src/main/kotlin/com/makkenzo/codehorizon/services/EmailService.kt"
    
    click Utils "https://github.com/makkenzo/codehorizon-api/tree/master/src/main/kotlin/com/makkenzo/codehorizon/utils"

    %% Styles
    classDef external fill:#ffcc00,stroke:#333,stroke-width:2px;
    classDef controllers fill:#a4d7f5,stroke:#333,stroke-width:2px;
    classDef service fill:#c5f7c0,stroke:#333,stroke-width:2px;
    classDef repo fill:#f7d6bf,stroke:#333,stroke-width:2px;
    classDef domain fill:#d7aefb,stroke:#333,stroke-width:2px;
    classDef dto fill:#bfaaf7,stroke:#333,stroke-width:2px;
    classDef security fill:#f5a4a4,stroke:#333,stroke-width:2px;
    classDef securityGroup fill:#f5a4a4,stroke:#333,stroke-dasharray: 5,5,stroke-width:2px;
    classDef externalIntegration fill:#a1f5d6,stroke:#333,stroke-width:2px;
    classDef utility fill:#f5e4a4,stroke:#333,stroke-width:2px;
```
