# jumpei527/ticketing_app architecture

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

- Interactive diagram: https://gitdiagram.com/jumpei527/ticketing_app
- Repository: https://github.com/jumpei527/ticketing_app

## Overview

##### Project type and purpose
- This is a learning-oriented ticketing e-commerce system built as a microservices application.
- It comprises six independent Node.js/TypeScript services (Auth, Tickets, Orders, Payments, Expiration, Client) plus a shared “common” library, all deployed in Kubernetes and communicating via an event bus (NATS Streaming).

##### File structure
- Top-level folders correspond to each service (auth, tickets, orders, payments, expiration, client), an infra directory with Kubernetes manifests, and a common shared codebase.
- Each service has its own Dockerfile, package.json, src folder (Express app, routes, models, event publishers/listeners, NATS wrapper).
- The client folder contains a Next.js/React app (pages, components, hooks).
- infra/k8s holds Deployments, Services and an Ingress for traffic routing.
- Skaffold.yaml suggests a full CI/CD deployment pipeline.

##### Extract additional insights from README
- Six microservices deployed behind a Kubernetes Ingress Controller.
- Externally, users interact only with the Client (React) via HTTP.
- Inter-service communication is asynchronous via Pub-Sub on NATS Streaming.
- Each domain service persists its own data in a dedicated MongoDB (and Expiration uses Redis for job queueing).
- Payments uses Stripe SDK.

##### Main components and their interactions
a. Client (Next.js/React)
– Renders UI and issues HTTP calls to Auth, Tickets, Orders, Payments.
b. Kubernetes Ingress Controller
– Exposes routes (auth, tickets, orders, payments) and performs load-balancing.
c. Auth Service
– Handles signup, signin, JWT, current-user middleware, stores users in MongoDB.
d. Tickets Service
– CRUD on tickets, emits ticket:created and ticket:updated events, stores tickets in its MongoDB.
e. Orders Service
– CRUD on orders, listens for ticket events, emits order:created and order:cancelled, stores orders in its MongoDB.
f. Payments Service
– Receives order IDs, calls Stripe, emits payment:created, stores payments in its MongoDB.
g. Expiration Service
– Listens for order:created, schedules expiration jobs in Redis-backed queue, emits expiration:complete.
h. NATS Streaming Server (Event Bus)
– All services publish to and subscribe from named subjects (ticket:created, order:created, etc.).
i. Datastores
– Six MongoDB instances (one per stateful service), one Redis instance for job queueing.

##### Architectural patterns and design principles
- Microservices with single-responsibility, bounded contexts.
- Event-driven, asynchronous Pub-Sub via NATS.
- Each service has its own database (database per service).
- Shared “common” library for DTOs, error handling, middlewares, event base classes.
- HTTP API façade (Express) for synchronous requests; asynchronous workflows via events.
- Infrastructure as code via Kubernetes YAMLs and Skaffold.

## Diagram (Mermaid)

```mermaid
graph TB
    Users(("Users")):::external
    Users -->|HTTP| Client
    Client["Client (Next.js/React)"]:::frontend
    Client -->|HTTP| Ingress

    subgraph "Kubernetes Cluster"
        direction TB
        Ingress["Ingress Controller"]:::infra

        subgraph "Services"
            direction TB
            Auth["Auth Service"]:::backend
            Tickets["Tickets Service"]:::backend
            Orders["Orders Service"]:::backend
            Payments["Payments Service"]:::backend
            Expiration["Expiration Service"]:::backend
        end

        NATS["NATS Streaming (Event Bus)"]:::messageBus
    end

    Ingress -->|/auth, /signup, etc.| Auth
    Ingress -->|/tickets| Tickets
    Ingress -->|/orders| Orders
    Ingress -->|/payments| Payments

    Tickets -->|"ticket:created<br/>ticket:updated"| NATS
    NATS -->|"ticket:created"| Orders

    Orders -->|"order:created<br/>order:cancelled"| NATS
    NATS -->|"order:created"| Expiration

    Payments -->|"payment:created"| NATS

    Expiration -->|"expiration:complete"| NATS

    Auth -->|Reads/Writes| AuthDB
    Tickets -->|Reads/Writes| TicketsDB
    Orders -->|Reads/Writes| OrdersDB
    Payments -->|Reads/Writes| PaymentsDB
    Expiration -->|Enqueues/Dequeues| Redis

    Payments -->|API Calls| Stripe

    Skaffold -.-> Ingress

    subgraph "Datastores"
        direction TB
        AuthDB["Auth MongoDB"]:::datastore
        TicketsDB["Tickets MongoDB"]:::datastore
        OrdersDB["Orders MongoDB"]:::datastore
        PaymentsDB["Payments MongoDB"]:::datastore
        Redis["Redis (Job Queue)"]:::datastore
    end

    click Client "https://github.com/jumpei527/ticketing_app/tree/main/client/"
    click Ingress "https://github.com/jumpei527/ticketing_app/blob/main/infra/k8s/ingress-srv.yaml"
    click Auth "https://github.com/jumpei527/ticketing_app/tree/main/auth/"
    click Tickets "https://github.com/jumpei527/ticketing_app/tree/main/tickets/"
    click Orders "https://github.com/jumpei527/ticketing_app/tree/main/orders/"
    click Payments "https://github.com/jumpei527/ticketing_app/tree/main/payments/"
    click Expiration "https://github.com/jumpei527/ticketing_app/tree/main/expiration/"
    click NATS "https://github.com/jumpei527/ticketing_app/blob/main/infra/k8s/nats-depl.yaml"
    click AuthDB "https://github.com/jumpei527/ticketing_app/blob/main/infra/k8s/auth-mongo-depl.yaml"
    click TicketsDB "https://github.com/jumpei527/ticketing_app/blob/main/infra/k8s/tickets-mongo-depl.yaml"
    click OrdersDB "https://github.com/jumpei527/ticketing_app/blob/main/infra/k8s/orders-mongo-depl.yaml"
    click PaymentsDB "https://github.com/jumpei527/ticketing_app/blob/main/infra/k8s/payments-mongo-depl.yaml"
    click Redis "https://github.com/jumpei527/ticketing_app/blob/main/infra/k8s/expiration-redis-depl.yaml"
    click Skaffold "https://github.com/jumpei527/ticketing_app/blob/main/skaffold.yaml"

    classDef frontend fill:#cce5ff,stroke:#1f78b4,color:#1f78b4
    classDef backend fill:#d5f5d5,stroke:#28a745,color:#28a745
    classDef messageBus fill:#ffe5b4,stroke:#ff8c00,color:#ff8c00
    classDef datastore fill:#f0f0f0,stroke:#666666,color:#666666
    classDef external fill:#f3e5ff,stroke:#6a1b9a,color:#6a1b9a
    classDef infra fill:#e0e0e0,stroke:#495057,color:#495057
```
