Skip to content

A microservice architecture that provides services for buyers and sellers of tickets for sports, concerts, theater and other live entertainment events.

License

Notifications You must be signed in to change notification settings

shreyshreyansh/ticketing-app

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

96 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Ticketing App

A microservice architecture that provides services for buyers and sellers of tickets for sports, concerts, theater and other live entertainment events.

Features

  • Production grade authentication service
  • Sellers can list their tickets
  • Sellers can update the price of the listed ticket
  • Buyers are buy tickets
  • Buyers will have a 15 minutes window to buy a ticket
  • During that 15 minutes window no one can buy the ticket
  • Handles the case when buyer buy the ticket and seller at the same time increases the price of the ticket
  • Production grade payment service

Design


Here common refers to a npm custom build library by us, which will be shared with all the services

Tech Stack

  • Next.js
  • Node.js
  • Express.js
  • Mongodb
  • Redis
  • NATS
  • Stripe.js
  • Typescript

Services

  • auth: Everything related to user signup/signin/signout
  • tickets: Tickets creation/editing. Knows whether a ticket can be updated
  • orders: Order creation/editing
  • expiration: Watches for order to be created, cancels them after 15 minutes
  • payments: Handles credit card payments. Cancels order if payments fails, completes if payment succeeds

Auth

Route Method Body Purpose
api/users/signup POST {email: string, password: string} Signup for an account
api/users/signin POST {email: string, password: string} Signin to an existing account
api/users/signout POST {} Signout of an account
api/users/currentuser GET - Return info about the user

Schema

  • User

    Name Type
    email string
    password string
  • Ticket

    Name Type
    title string
    price number
    userId Ref to User
    orderId Ref to Order
  • Order

    Name Type
    userId Ref to User
    status Created, Cancelled, Awaiting payment, Completed
    ticketId Ref to Ticket
    expiresAt Date
  • Charge

    Name Type
    orderId Ref to Order
    status Created, Failed, Completed
    amount number
    stripeId string
    stripeRefundId string

Events

  • UserCreated UserUpdated
  • OrderCreated OrderCancelled OrderExpired
  • TicketCreated TicketUpdated
  • ChargeCreated

GCP Integration

  • when we make changes in the synced files

  • when we make changes in the unsynced files

Error Handling!

  • we will make two classes RequestValidationError and DatabaseConnectionError which will extend to the Error class and so that they can add custom features to the Error class like reason of the error and message to show regarding the error
  • inside the error-handler middleware we will check if it is invoked due to the RequestValidationError or DatabaseConnectionError, and based on the error type it will send custom messages to the client

Error Response

  • All error response that we send out from our server will have this structure
{
  errors: {
    message: string,
    field?: string
  }[]
}

Custom Errors Verification

  • All the error classes like RequestValidationError and DatabaseConnectionError should contain a statusCode variable and a serializeErrors method.
  • To ensure all error classes stick to the rule we will make a CustomError Abstract Class
NOTE: on abstract class
- cannot be instantiated
- used to setup requirements for subclasses
- when we compile TS to JS, we end up with a class definition in JS from abstract class in TS unlike an interface as it does not exist in JS 

Signup Flow


MongoDB User Collection

  • Mongoose User Model represents the entire collection of users
  • Mongoose User Document represents one single user

Auth Mechanism

  • We will be using JWT with cookies for our auth mechanism

  • Because we're using Next.js, we're conducting server-side rendering, which means that if we want the client's initial request to include a JWT token, we'll have to rely on cookies

Storing secrets in K8s cluster

  • In our Kubernetes cluster, we build an object called secret that contains multiple key-value combinations and is shared across all pods through environment variables.

  • Creating a secret object (imperative)
kubectl create secret generic jwt-secret --from-literal=jwt=asdf

Signin Flow


Current User Flow

  • This route is used to check if the user accessing the resources is logged in

Testing

Workflow


Client

Component tree


About

A microservice architecture that provides services for buyers and sellers of tickets for sports, concerts, theater and other live entertainment events.

Topics

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published