# ziruiwang1996/textbook-exchange-platform architecture

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

- Interactive diagram: https://gitdiagram.com/ziruiwang1996/textbook-exchange-platform
- Repository: https://github.com/ziruiwang1996/textbook-exchange-platform

## Overview

##### Project type and purpose
- This is a web-based textbook exchange platform built on a microservices architecture.
- It provides user authentication, cart management, order processing, and payment handling, communicating via RabbitMQ events.

##### File structure
- Top-level Spring Boot application (BookstoreApplication.java) under src/main/java/com/cse687/zirui/bookstore
- Four logical “service” folders:
- auth/ (authentication)
- cart/ (cart management)
- order/ (order processing & inventory)
- payment/ (payment processing)
- Each service folder follows the same substructure:
- controller/ (REST endpoints)
- domain/ (commands, events, models)
- messaging/ (RabbitMQ producers, consumers, config)
- repository/ (JPA repositories)
- service/ (business logic)
- Shared resources: Thymeleaf templates (src/main/resources/templates), application.properties, Docker Compose, pom.xml

##### README for additional insights
- Confirms microservices: auth, cart, order, payment
- Event-driven communication via RabbitMQ routing keys (e.g., auth.evt.loggedIn, cart.evt.orderPlaced, payment.evt.succeeded)
- Uses Java 21 + Spring Boot, MySQL, JPA/Hibernate, RabbitMQ, Thymeleaf

##### Detail
- Break each service into sub-components if space allows (Controller, Service, Repository, Messaging)
- JWT token generation in Auth Service and usage header in downstream calls
- Don’t over-simplify—capture all four services, the message broker, the database, and the UI in one cohesive view

## Diagram (Mermaid)

```mermaid
flowchart TD
    %% UI
    UI["Browser UI\n(Thymeleaf Templates)"]:::ui
    click UI "https://github.com/ziruiwang1996/textbook-exchange-platform/blob/main/src/main/resources/templates/index.html"
    click UI "https://github.com/ziruiwang1996/textbook-exchange-platform/blob/main/src/main/resources/templates/customerPage.html"
    click UI "https://github.com/ziruiwang1996/textbook-exchange-platform/blob/main/src/main/resources/templates/sellPage.html"

    %% Docker Compose Boundary
    subgraph "Docker Compose" 
        direction TB

        %% Auth Service
        subgraph "Auth Service" 
            direction TB
            AuthController["AuthController"]:::service
            AuthService["AuthService"]:::service
            JwtService["JwtService"]:::service
            CustomerRepository["CustomerRepository"]:::service
            AuthRabbitMQConfig["AuthRabbitMQConfig"]:::service
            AuthProducer["AuthProducer"]:::service
            AuthConsumer["AuthConsumer"]:::service

            AuthController -->|HTTP| AuthService
            AuthService --> CustomerRepository
            AuthService --> JwtService
            AuthService -->|publish auth.evt.loggedIn| AuthProducer
            AuthProducer -->|auth.evt.loggedIn| RabbitMQ
            AuthConsumer -->|consumes auth.evt.loggedIn| AuthService
        end
        click AuthController "https://github.com/ziruiwang1996/textbook-exchange-platform/blob/main/src/main/java/com/cse687/zirui/bookstore/auth/controller/AuthController.java"
        click AuthService "https://github.com/ziruiwang1996/textbook-exchange-platform/blob/main/src/main/java/com/cse687/zirui/bookstore/auth/service/AuthService.java"
        click JwtService "https://github.com/ziruiwang1996/textbook-exchange-platform/blob/main/src/main/java/com/cse687/zirui/bookstore/auth/service/JwtService.java"
        click CustomerRepository "https://github.com/ziruiwang1996/textbook-exchange-platform/blob/main/src/main/java/com/cse687/zirui/bookstore/auth/repository/CustomerRepository.java"
        click AuthRabbitMQConfig "https://github.com/ziruiwang1996/textbook-exchange-platform/blob/main/src/main/java/com/cse687/zirui/bookstore/auth/messaging/AuthRabbitMQConfig.java"
        click AuthProducer "https://github.com/ziruiwang1996/textbook-exchange-platform/blob/main/src/main/java/com/cse687/zirui/bookstore/auth/messaging/AuthProducer.java"
        click AuthConsumer "https://github.com/ziruiwang1996/textbook-exchange-platform/blob/main/src/main/java/com/cse687/zirui/bookstore/auth/messaging/AuthConsumer.java"

        %% Cart Service
        subgraph "Cart Service" 
            direction TB
            CartController["CartController"]:::service
            CartService["CartService"]:::service
            CartRepository["CartRepository"]:::service
            CartRabbitMQConfig["CartRabbitMQConfig"]:::service
            CartProducer["CartProducer"]:::service
            CartConsumer["CartConsumer"]:::service

            CartConsumer -->|consumes auth.evt.loggedIn| CartService
            CartController -->|HTTP| CartService
            CartService --> CartRepository
            CartService -->|publish cart.evt.orderPlaced| CartProducer
            CartProducer -->|cart.evt.orderPlaced| RabbitMQ
        end
        click CartController "https://github.com/ziruiwang1996/textbook-exchange-platform/blob/main/src/main/java/com/cse687/zirui/bookstore/cart/controller/CartController.java"
        click CartService "https://github.com/ziruiwang1996/textbook-exchange-platform/blob/main/src/main/java/com/cse687/zirui/bookstore/cart/service/CartService.java"
        click CartRepository "https://github.com/ziruiwang1996/textbook-exchange-platform/blob/main/src/main/java/com/cse687/zirui/bookstore/cart/repository/CartRepository.java"
        click CartRabbitMQConfig "https://github.com/ziruiwang1996/textbook-exchange-platform/blob/main/src/main/java/com/cse687/zirui/bookstore/cart/messaging/CartRabbitMQConfig.java"
        click CartProducer "https://github.com/ziruiwang1996/textbook-exchange-platform/blob/main/src/main/java/com/cse687/zirui/bookstore/cart/messaging/CartProducer.java"
        click CartConsumer "https://github.com/ziruiwang1996/textbook-exchange-platform/blob/main/src/main/java/com/cse687/zirui/bookstore/cart/messaging/CartConsumer.java"

        %% Order Service
        subgraph "Order Service" 
            direction TB
            OrderController["OrderController"]:::service
            OrderService["OrderService"]:::service
            BookFetcher["BookFetcher"]:::service
            BookRepository["BookRepository"]:::service
            OrderRabbitMQConfig["OrderRabbitMQConfig"]:::service
            OrderProducer["OrderProducer"]:::service
            OrderConsumer["OrderConsumer"]:::service

            OrderConsumer -->|consumes cart.evt.orderPlaced| OrderService
            OrderController -->|HTTP| OrderService
            OrderService --> BookRepository
            OrderService --> BookFetcher
            OrderService -->|publish order.evt.bought/order.evt.sold| OrderProducer
            OrderProducer -->|order.evt.bought| RabbitMQ
            OrderProducer -->|order.evt.sold| RabbitMQ
        end
        click OrderController "https://github.com/ziruiwang1996/textbook-exchange-platform/blob/main/src/main/java/com/cse687/zirui/bookstore/order/controller/OrderController.java"
        click OrderService "https://github.com/ziruiwang1996/textbook-exchange-platform/blob/main/src/main/java/com/cse687/zirui/bookstore/order/service/OrderService.java"
        click BookFetcher "https://github.com/ziruiwang1996/textbook-exchange-platform/blob/main/src/main/java/com/cse687/zirui/bookstore/order/service/BookFetcher.java"
        click BookRepository "https://github.com/ziruiwang1996/textbook-exchange-platform/blob/main/src/main/java/com/cse687/zirui/bookstore/order/repository/BookRepository.java"
        click OrderRabbitMQConfig "https://github.com/ziruiwang1996/textbook-exchange-platform/blob/main/src/main/java/com/cse687/zirui/bookstore/order/messaging/OrderRabbitMQConfig.java"
        click OrderProducer "https://github.com/ziruiwang1996/textbook-exchange-platform/blob/main/src/main/java/com/cse687/zirui/bookstore/order/messaging/OrderProducer.java"
        click OrderConsumer "https://github.com/ziruiwang1996/textbook-exchange-platform/blob/main/src/main/java/com/cse687/zirui/bookstore/order/messaging/OrderConsumer.java"

        %% Payment Service
        subgraph "Payment Service"
            direction TB
            PaymentService["PaymentService"]:::service
            InvoiceRepository["InvoiceRepository"]:::service
            PaymentRabbitMQConfig["PaymentRabbitMQConfig"]:::service
            PaymentProducer["PaymentProducer"]:::service
            PaymentConsumer["PaymentConsumer"]:::service

            PaymentConsumer -->|consumes order.evt.bought| PaymentService
            PaymentService --> InvoiceRepository
            PaymentService -->|publish payment.evt.succeeded/payment.evt.failed| PaymentProducer
            PaymentProducer -->|payment.evt.succeeded| RabbitMQ
            PaymentProducer -->|payment.evt.failed| RabbitMQ
        end
        click PaymentService "https://github.com/ziruiwang1996/textbook-exchange-platform/blob/main/src/main/java/com/cse687/zirui/bookstore/payment/service/PaymentService.java"
        click InvoiceRepository "https://github.com/ziruiwang1996/textbook-exchange-platform/blob/main/src/main/java/com/cse687/zirui/bookstore/payment/repository/InvoiceRepository.java"
        click PaymentRabbitMQConfig "https://github.com/ziruiwang1996/textbook-exchange-platform/blob/main/src/main/java/com/cse687/zirui/bookstore/payment/messaging/PaymentRabbitMQConfig.java"
        click PaymentProducer "https://github.com/ziruiwang1996/textbook-exchange-platform/blob/main/src/main/java/com/cse687/zirui/bookstore/payment/messaging/PaymentProducer.java"
        click PaymentConsumer "https://github.com/ziruiwang1996/textbook-exchange-platform/blob/main/src/main/java/com/cse687/zirui/bookstore/payment/messaging/PaymentConsumer.java"

        %% RabbitMQ Broker
        RabbitMQ["RabbitMQ Broker"]:::broker

        %% MySQL
        MySQL["MySQL Database"]:::db

        %% Config & EntryPoint
        BookstoreApp["BookstoreApplication.java"]:::service
        click BookstoreApp "https://github.com/ziruiwang1996/textbook-exchange-platform/blob/main/src/main/java/com/cse687/zirui/bookstore/BookstoreApplication.java"
        DockerCompose["docker-compose.yml"]:::service
        click DockerCompose "https://github.com/ziruiwang1996/textbook-exchange-platform/blob/main/docker-compose.yml"
        AppProps["application.properties"]:::service
        click AppProps "https://github.com/ziruiwang1996/textbook-exchange-platform/blob/main/src/main/resources/application.properties"

        %% Connections to infrastructure
        AuthRabbitMQConfig --> RabbitMQ
        CartRabbitMQConfig --> RabbitMQ
        OrderRabbitMQConfig --> RabbitMQ
        PaymentRabbitMQConfig --> RabbitMQ

        AuthService --> MySQL
        CartService --> MySQL
        OrderService --> MySQL
        PaymentService --> MySQL

        BookstoreApp --> AuthService
        BookstoreApp --> CartService
        BookstoreApp --> OrderService
        BookstoreApp --> PaymentService
        BookstoreApp --> RabbitMQ
        BookstoreApp --> MySQL
    end

    %% HTTP Flows
    UI -->|login/register| AuthController
    UI -->|add/remove/place order| CartController
    UI -->|view/process order| OrderController

    %% Styles
    classDef service fill:#add8e6,stroke:#000,stroke-width:1px
    classDef db fill:#ffa500,stroke:#000,stroke-width:1px
    classDef broker fill:#9370db,stroke:#000,stroke-width:1px
    classDef ui fill:#d3d3d3,stroke:#000,stroke-width:1px
```
