# munyeol-yoon/ticketnest-pub architecture

> Architecture diagram of the GitHub repository munyeol-yoon/ticketnest-pub, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2025-01-20). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/munyeol-yoon/ticketnest-pub
- Repository: https://github.com/munyeol-yoon/ticketnest-pub

## Overview

##### Main Components

a. Client Layer:
- Frontend Application (React/Next.js implied from separate FE repository)
- Connection to Load Balancer (HAProxy)

b. Load Balancing Layer:
- HAProxy for application load balancing
- Pgpool-II for database load balancing

c. Application Layer:
- Multiple NestJS server instances
- Core modules:
- Auth Module (JWT-based authentication)
- Booking Module (ticket reservation system)
- Goods Module (ticket inventory management)
- Redis Module (caching and Pub/Sub)

d. Data Layer:
- PostgreSQL database cluster
- Redis instances (separate for caching and Pub/Sub)

e. Monitoring Layer:
- Elastic APM
- Kibana dashboard

##### Key Relationships to Highlight

a. Traffic Flow:
- Load distribution patterns

b. Data Flow:
- Redis Pub/Sub message flow for booking operations
- Cache hit/miss patterns
- Database read/write operations through Pgpool-II

c. Monitoring Flow:
- APM data collection paths
- Logging routes

##### Specific Implementation Details

a. Authentication Flow:
- JWT token validation path
- User authentication process

b. Booking Process:
- Redis-based queue system
- Concurrent booking handling
- Database transaction flow

##### Important Architectural Patterns to Emphasize

a. High Availability:
- Multiple instance deployment
- Failover configurations

b. Scalability:
- Horizontal scaling of application servers
- Database replication

c. Performance Optimization:
- Cache layer implementation
- Message queue system

##### Technical Details

- TypeORM integration
- Redis cache configuration
- PostgreSQL replication
- APM integration points
- Middleware placement

##### Monitoring Layer

This architecture should be drawn with emphasis on the scalability and performance optimizations implemented, as these are the core strengths of the system according to the project documentation.

## Diagram (Mermaid)

```mermaid
flowchart TB
    subgraph Client
        FE[Frontend Application]:::frontend
    end

    subgraph LoadBalancers
        HAP[HAProxy]:::loadbalancer
        PGP[Pgpool-II]:::loadbalancer
    end

    subgraph AppServers["Application Servers (NestJS)"]
        direction TB
        APP1["App Instance 1"]:::app
        APP2["App Instance 2"]:::app
        APP3["App Instance 3"]:::app

        subgraph CoreModules["Core Modules"]
            direction TB
            AUTH["Auth Module"]:::module
            BOOK["Booking Module"]:::module
            GOOD["Goods Module"]:::module
            RMOD["Redis Module"]:::module
        end
    end

    subgraph Cache["Caching Layer"]
        RC["Redis Cache"]:::cache
        RPS["Redis Pub/Sub"]:::cache
    end

    subgraph Database["Database Layer"]
        PG1["PostgreSQL Primary"]:::database
        PG2["PostgreSQL Replica 1"]:::database
        PG3["PostgreSQL Replica 2"]:::database
    end

    subgraph Monitoring
        APM["Elastic APM"]:::monitoring
        KIB["Kibana Dashboard"]:::monitoring
    end

    %% Connections
    FE --> HAP
    HAP --> APP1
    HAP --> APP2
    HAP --> APP3
    APP1 & APP2 & APP3 --> CoreModules
    AUTH & BOOK & GOOD --> PGP
    RMOD --> RC
    RMOD --> RPS
    PGP --> PG1
    PG1 --> PG2
    PG1 --> PG3
    APP1 & APP2 & APP3 --> APM
    APM --> KIB

    %% Click Events
    click AUTH "https://github.com/munyeol-Yoon/TicketNest-Pub/tree/main/src/auth/"
    click BOOK "https://github.com/munyeol-Yoon/TicketNest-Pub/tree/main/src/booking/"
    click GOOD "https://github.com/munyeol-Yoon/TicketNest-Pub/tree/main/src/goods/"
    click RMOD "https://github.com/munyeol-Yoon/TicketNest-Pub/tree/main/src/redis/"

    %% Styles
    classDef frontend fill:#3498db,stroke:#2980b9,color:white
    classDef loadbalancer fill:#95a5a6,stroke:#7f8c8d,color:white
    classDef app fill:#2ecc71,stroke:#27ae60,color:white
    classDef module fill:#27ae60,stroke:#219a52,color:white
    classDef cache fill:#f1c40f,stroke:#f39c12,color:white
    classDef database fill:#e74c3c,stroke:#c0392b,color:white
    classDef monitoring fill:#9b59b6,stroke:#8e44ad,color:white

    %% Legend
    subgraph Legend
        L1[Client Layer]:::frontend
        L2[Load Balancers]:::loadbalancer
        L3[Application Services]:::app
        L4[Cache Layer]:::cache
        L5[Database Layer]:::database
        L6[Monitoring]:::monitoring
    end
```
