# goorm-sudo/raillo-backend architecture

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

- Interactive diagram: https://gitdiagram.com/goorm-sudo/raillo-backend
- Repository: https://github.com/goorm-sudo/raillo-backend

## Overview

##### Project Type and Purpose
- This is a backend monolithic application (Spring Boot) that implements a ticket reservation platform (“Raillo”).
- It’s organized into logical business domains (packages/modules): Member, Booking, Payment, Train, plus a Global/Common module.

##### High-Level Architectural Overview
- The entire system runs as one Spring Boot application deployed in Kubernetes.
- Externally it exposes a REST API consumed by clients (mobile/web).
- Internally it uses layered/hexagonal architecture:
- Controllers (presentation)
- Application services (use-case layer)
- Domain layer (business rules & entities)
- Infrastructure/adapters (JPA repositories, Redis, external HTTP clients)
- It relies on:
- Relational DB (JPA)
- Redis (distributed locks, logout tokens, caching)
- External Payment Gateways (e.g., KakaoPay, NaverPay)
- Email service (for authentication)
- Excel file inputs (train schedules & fares)
- It is deployed via Docker → Kubernetes, managed by ArgoCD, and monitored with Prometheus + Grafana.

##### Main Components
A. API Layer
- BookingController, MemberController, PaymentControllers, TrainControllers (Spring MVC)
B. Application Services (per module)
- BookingApplicationService, ReservationService, TicketService, etc.
- MemberAuthService, MemberService
- PaymentCreationService, PaymentExecutionService, MileageEarningApplicationService, etc.
- TrainScheduleService, SeatReservationService, StationService
C. Domain Layer
- Aggregates & Entities (Reservation, Ticket, Member, Payment, TrainSchedule, StationFare, etc.)
- Domain services & policies (e.g., RefundPolicyFactory)
- Domain events & listeners (BookingPaymentCompletedEvent, PaymentRefundedEvent, MileageEventListener)
D. Infrastructure Adapters
- Persistence adapters (Jpa…Repository implementations)
- RedisConfig & RedisUtil for caching/locking
- External HTTP clients & gateways (PgApiClient, KakaoPayGateway, MemberInfoAdapter)
- Excel parsers for initial data load
E. Supporting Infrastructure
- PostgreSQL (or chosen RDBMS)
- Redis Cluster
- Kubernetes cluster
- ArgoCD (GitOps)
- Prometheus + Grafana + node-exporter

##### Relationships & Data Flows
1) Client → HTTP(S) → API Gateway / Load Balancer in k8s
2) Requests routed to Spring Boot pod → Controller
3) Controller → Application Service → Domain Logic
4) Domain Logic → Repository Ports → JPA Adapter → Database
5) Some operations fire Domain Events → Event Listeners handle async tasks (e.g., refund alerts, mileage scheduling)
6) Payment flows call external PG Gateway via HTTP clients → back to application → persist transaction
7) Redis used for distributed locks (annotation @DistributedLock), token storage (logout)
8) Scheduled jobs (ReservationScheduler, MileageEarningScheduler) execute periodic tasks

##### Key Architectural Patterns & Principles
- Layered Architecture (presentation → application → domain → infrastructure)
- Hexagonal / Ports & Adapters (payment module defines ports/in/out for testability)
- Domain-Driven Design (bounded contexts for Booking, Payment, Member, Train)
- Event-Driven (internal Spring events for decoupling)
- Scheduled tasks for background processing
- GitOps for deployment (ArgoCD), CI pipelines via GitHub Actions

##### Summary
- Traffic ingress (Ingress/NLB → Spring Boot pod)
- Module boundaries (Booking, Payment, etc.)
- Data stores & caches (DB, Redis)
- External dependencies (PG gateways, email)
- CI/CD & GitOps layers (GitHub Actions, Docker registry, ArgoCD)
- Monitoring stack
- Aim for clarity: a viewer should immediately understand the major functional domains, data flows, and deployment topology of Raillo.

## Diagram (Mermaid)

```mermaid
flowchart TD
    %% Ingress and CI/CD
    CI_GH["GitHub Actions"]:::ci
    CI_DOCKER["Docker Registry"]:::ci
    CI_ARO["ArgoCD (GitOps)"]:::ci
    Ingress["Ingress / NLB\n(k8s)"]:::external
    K8s_Svc["Kubernetes\nDeployment & Service"]:::external
    Monitor["Prometheus + Grafana\n+ node-exporter"]:::external

    CI_GH -->|build & push| CI_DOCKER
    CI_DOCKER -->|deploy| CI_ARO
    CI_ARO -->|sync| K8s_Svc
    Ingress -->|HTTP/HTTPS| K8s_Svc
    K8s_Svc -->|metrics| Monitor

    %% Application Container
    subgraph "Raillo Application\n(Spring Boot)" 
        direction TB

        subgraph "Booking Module"
            direction TB
            BC["BookingController\n(Spring MVC)"]:::internal
            BAS["BookingApplicationService"]:::internal
            BD["Booking Domain\n(Entities & Aggregates)"]:::internal
            BRepo["Booking Repository\n(JPA Adapter)"]:::internal
            BEvent["Booking Events & Listeners"]:::internal
            BSched["ReservationScheduler\n(periodic)"]:::internal
        end

        subgraph "Member Module"
            direction TB
            MC["MemberController\n(Spring MVC)"]:::internal
            MAS["MemberService\n(Auth & Use-cases)"]:::internal
            MD["Member Domain\n(Entity & VO)"]:::internal
            MRepo["Member Repo Adapter\n(JPA)"]:::internal
        end

        subgraph "Payment Module"
            direction TB
            PC["PaymentController\n(Spring MVC)"]:::internal
            PAS["PaymentApplicationServices\n(ports/in/out)"]:::internal
            PPort["Payment Ports\n(In/Out)"]:::internal
            PDomain["Payment Domain\n(Entities & Policies)"]:::internal
            PRepo["Payment Persistence Adapter"]:::internal
            PGWs["PG Gateways Adapters"]:::internal
        end

        subgraph "Train Module"
            direction TB
            TC["TrainController\n(Spring MVC)"]:::internal
            TAS["TrainServices & Scheduler"]:::internal
            TD["Train Domain\n(Entities & VTs)"]:::internal
            TExcel["Excel Parsers"]:::internal
            TRepo["Train JDBC & Repos"]:::internal
        end

        subgraph "Global/Common"
            direction TB
            GCfg["GlobalConfig\n(Redis, CORS, Swagger)"]:::internal
            GRedis["RedisUtil & Annotations"]:::internal
            GJWT["JWT Security"]:::internal
            GHC["HealthController"]:::internal
        end
    end

    %% Datastores and External
    DB["PostgreSQL\n(JDBC)"]:::datastore
    Redis["Redis Cluster\n(caches, locks)"]:::datastore
    Email["Email Service"]:::external
    PG["External PG Gateways\n(KakaoPay, NaverPay)"]:::external
    Files["Static Data Files\n(train_schedule.xlsx,\nstation_fare.xls)"]:::external

    %% Flow: Clients
    Ingress --> BC
    Ingress --> MC
    Ingress --> PC
    Ingress --> TC
    Ingress --> GHC

    %% Booking flow
    BC -->|call| BAS
    BAS -->|use| BD
    BD -->|persist via| BRepo
    BRepo -->|JDBC| DB
    BD -->|event| BEvent
    BSched -.->|async task| BAS

    %% Member flow
    MC -->|call| MAS
    MAS -->|use| MD
    MD -->|persist via| MRepo
    MRepo -->|JDBC| DB

    %% Payment flow
    PC -->|call| PAS
    PAS -->|invoke| PPort
    PAS -->|use| PDomain
    PDomain -->|persist via| PRepo
    PRepo -->|JDBC| DB
    PAS -->|HTTP| PG
    PPort -->|adapter| PGWs

    %% Train flow
    TC -->|call| TAS
    TAS -->|use| TD
    TAS -->|persist via| TRepo
    TRepo -->|JDBC| DB
    TAS -->|load| TExcel
    TAS -.->|scheduled| TAS

    %% Global
    GCfg --> GRedis
    GCfg --> GJWT
    GRedis -->|cache/lock| Redis
    GHC -->|healthcheck| DB
    GHC -->|healthcheck| Redis

    %% External services
    Email -->|SMTP| MC
    Email -->|SMTP| PC

    %% Click Events
    click BC "https://github.com/goorm-sudo/raillo-backend/tree/develop/src/main/java/com/sudo/railo/booking/presentation"
    click BAS "https://github.com/goorm-sudo/raillo-backend/tree/develop/src/main/java/com/sudo/railo/booking/application"
    click BD "https://github.com/goorm-sudo/raillo-backend/tree/develop/src/main/java/com/sudo/railo/booking/domain"
    click BRepo "https://github.com/goorm-sudo/raillo-backend/tree/develop/src/main/java/com/sudo/railo/booking/infra"
    click BEvent "https://github.com/goorm-sudo/raillo-backend/tree/develop/src/main/java/com/sudo/railo/booking/application/event"
    click BSched "https://github.com/goorm-sudo/raillo-backend/tree/develop/src/main/java/com/sudo/railo/booking/application/ReservationScheduler"
    click MC "https://github.com/goorm-sudo/raillo-backend/tree/develop/src/main/java/com/sudo/railo/member/presentation"
    click MAS "https://github.com/goorm-sudo/raillo-backend/tree/develop/src/main/java/com/sudo/railo/member/application"
    click MD "https://github.com/goorm-sudo/raillo-backend/tree/develop/src/main/java/com/sudo/railo/member/domain"
    click MRepo "https://github.com/goorm-sudo/raillo-backend/tree/develop/src/main/java/com/sudo/railo/member/infra"
    click PC "https://github.com/goorm-sudo/raillo-backend/tree/develop/src/main/java/com/sudo/railo/payment/presentation/controller"
    click PAS "https://github.com/goorm-sudo/raillo-backend/tree/develop/src/main/java/com/sudo/railo/payment/application/service"
    click PPort "https://github.com/goorm-sudo/raillo-backend/tree/develop/src/main/java/com/sudo/railo/payment/application/port"
    click PGWs "https://github.com/goorm-sudo/raillo-backend/tree/develop/src/main/java/com/sudo/railo/payment/infrastructure/adapter/out"
    click PDomain "https://github.com/goorm-sudo/raillo-backend/tree/develop/src/main/java/com/sudo/railo/payment/domain"
    click PRepo "https://github.com/goorm-sudo/raillo-backend/tree/develop/src/main/java/com/sudo/railo/payment/infrastructure/adapter/out/persistence"
    click TC "https://github.com/goorm-sudo/raillo-backend/tree/develop/src/main/java/com/sudo/railo/train/presentation"
    click TAS "https://github.com/goorm-sudo/raillo-backend/tree/develop/src/main/java/com/sudo/railo/train/application"
    click TD "https://github.com/goorm-sudo/raillo-backend/tree/develop/src/main/java/com/sudo/railo/train/domain"
    click TExcel "https://github.com/goorm-sudo/raillo-backend/tree/develop/src/main/java/com/sudo/railo/train/infrastructure/excel"
    click TRepo "https://github.com/goorm-sudo/raillo-backend/tree/develop/src/main/java/com/sudo/railo/train/infrastructure/jdbc"
    click GCfg "https://github.com/goorm-sudo/raillo-backend/tree/develop/src/main/java/com/sudo/railo/global/config"
    click GRedis "https://github.com/goorm-sudo/raillo-backend/tree/develop/src/main/java/com/sudo/railo/global/redis"
    click GJWT "https://github.com/goorm-sudo/raillo-backend/tree/develop/src/main/java/com/sudo/railo/global/security/jwt"
    click GHC "https://github.com/goorm-sudo/raillo-backend/blob/develop/src/main/java/com/sudo/railo/global/presentation/HealthController.java"
    click Files "https://github.com/goorm-sudo/raillo-backend/blob/develop/files/train_schedule.xlsx"
    click Files "https://github.com/goorm-sudo/raillo-backend/blob/develop/files/station_fare.xls"

    %% Styles
    classDef internal fill:#D6E9F8,stroke:#31708F
    classDef external fill:#FDF8E4,stroke:#8A6D3B
    classDef datastore fill:#DFF0D8,stroke:#3C763D
    classDef ci fill:#EEEEEE,stroke:#CCCCCC
```
