# hoa-nguyen-bk/the_flying_bookstore_front_end architecture

> Architecture diagram of the GitHub repository hoa-nguyen-bk/the_flying_bookstore_front_end, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2025-03-28). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/hoa-nguyen-bk/the_flying_bookstore_front_end
- Repository: https://github.com/hoa-nguyen-bk/the_flying_bookstore_front_end

## Overview

##### Project Type and Purpose
- This is a full-stack web application built with Next.js, designed to serve both end users (bookstore visitors) and administrators (dashboard for managing book posts, orders, vouchers, etc.).
- The README and file structure also indicate that there is a separate backend (a Java/Gradle-based service deployed via Docker) which exposes API endpoints and handles core business logic, such as authentication, order processing, payment handling (with integration to external payment services like VNPay), and other services.

##### Main Components
a. Frontend Application (Next.js):
– Represent the Next.js server that handles rendering, routing, and client-side logic.
– Highlight key subdomains within the frontend:
- User-Facing Sections: Home page, search, detail pages, cart, checkout.
- Authentication Components: Login and sign-up flows.
- Policy pages, informational pages (privacy policies, book condition guides), and error-handling.
- Admin/Manager Section: Pages for managing posts, orders (both customer and seller orders), vouchers, profiles, etc.
– Include supporting client-side layers such as components (UI controls, forms, modals), hooks (for state and API calls), utilities (theme, config), and assets.

b. Backend API Service:
– Represent the Java-based backend service that the instructions indicate must be cloned and run separately.
– This component handles business logic, data persistence, authentication (possibly via endpoints like “/api/auth/loginService.tsx” and “/api/auth/registerService.tsx”), order management, and payment processing.
– Use Docker (as indicated by the local YAML configuration for containers, volumes, and images) as the deployment container and include a Gradle build process that produces the backend artifact.

c. External Services:
– Payment Gateway: Highlight integration with VNPay (as mentioned in the README for test payment data).
– Other potential external integrations (if applicable) like image services or voucher processing.

d. Data Stores:
– Although not directly visible in the file tree, show that the backend logically connects to a database system for storing books, orders, vouchers, and user profiles.

##### Relationships and Interactions
- Communication via API calls from the Next.js app to the backend service (Java/Gradle) for authentication, CRUD operations on books/posts, order creation, and payment.
- Calls or integrations from the backend to the External Payment Gateway.
- If applicable, indicate asynchronous operations or error-handling flows (for example, handling network errors via the “handleError” service in the API layer).

##### Important Architectural Patterns
- Next.js Routing and Folder-Based Dynamic Routing: This is evident in the file paths under src/app where various routes (e.g., nested folders for authentication and manager domains) clearly follow a modular scheme.
- Separation of Concerns (Frontend vs. Backend): The clear division between the client code (Next.js, components, hooks) and the backend service (Java, Docker, Gradle build).
- MVC/Layers within Frontend: Although Next.js abstracts much of this, the presence of organized components, hooks, and API services hints at an underlying model–view–controller (or component-driven) design.
- Modular services in the backend API: Each functionality such as authentication, checkout, book creation (in src/api/create) is encapsulated as separate modules/services.

## Diagram (Mermaid)

```mermaid
flowchart TD
    Brow("User Browser"):::ui
    FE("Next.js Frontend"):::frontend

    subgraph "User-Facing Sections"
        Home("Home Page"):::frontend
        Search("Search Page"):::frontend
        Detail("Detail Page"):::frontend
        Cart("Cart Page"):::frontend
        Checkout("Checkout Page"):::frontend
    end

    subgraph "Authentication Components"
        AuthPages("Auth Pages"):::auth
        AuthComp("Auth Components"):::auth
        AuthAPI("Auth API Services"):::api
    end

    subgraph "Admin/Manager Section"
        ManagerPages("Manager Pages"):::manager
        ManagerComp("Manager Components"):::manager
    end

    BE("Backend API Service (Java/Docker)"):::backend
    DB("Database"):::db
    Pay("VNPay Payment Gateway"):::integration

    Brow -->|"HTTP_Request"| FE

    FE -->|"renders"| Home
    FE -->|"renders"| Search
    FE -->|"renders"| Detail
    FE -->|"renders"| Cart
    FE -->|"renders"| Checkout
    FE -->|"renders"| AuthPages
    FE -->|"renders"| AuthComp
    FE -->|"renders"| AuthAPI
    FE -->|"renders"| ManagerPages
    FE -->|"renders"| ManagerComp

    FE -->|"API_calls"| BE
    BE -->|"CRUD_BusinessLogic"| DB
    BE -->|"Payment_Integration"| Pay

    %% Click Events for Frontend Components
    click FE "https://github.com/hoa-nguyen-bk/the_flying_bookstore_front_end/tree/main/src/app"
    click Home "https://github.com/hoa-nguyen-bk/the_flying_bookstore_front_end/blob/main/src/app/page.tsx"
    click Home "https://github.com/hoa-nguyen-bk/the_flying_bookstore_front_end/tree/main/src/components/home"
    click Search "https://github.com/hoa-nguyen-bk/the_flying_bookstore_front_end/tree/main/src/app/search"
    click Search "https://github.com/hoa-nguyen-bk/the_flying_bookstore_front_end/tree/main/src/components/search"
    click Detail "https://github.com/hoa-nguyen-bk/the_flying_bookstore_front_end/tree/main/src/app/detail"
    click Detail "https://github.com/hoa-nguyen-bk/the_flying_bookstore_front_end/tree/main/src/components/detail"
    click Cart "https://github.com/hoa-nguyen-bk/the_flying_bookstore_front_end/tree/main/src/app/cart"
    click Cart "https://github.com/hoa-nguyen-bk/the_flying_bookstore_front_end/tree/main/src/components/cart"
    click Checkout "https://github.com/hoa-nguyen-bk/the_flying_bookstore_front_end/tree/main/src/app/checkout"
    click Checkout "https://github.com/hoa-nguyen-bk/the_flying_bookstore_front_end/tree/main/src/components/checkout"
    
    %% Click Events for Authentication Components
    click AuthPages "https://github.com/hoa-nguyen-bk/the_flying_bookstore_front_end/tree/main/src/app/(auth)"
    click AuthComp "https://github.com/hoa-nguyen-bk/the_flying_bookstore_front_end/tree/main/src/components/auth"
    click AuthAPI "https://github.com/hoa-nguyen-bk/the_flying_bookstore_front_end/tree/main/src/api/auth"
    
    %% Click Events for Manager/Administration Components
    click ManagerPages "https://github.com/hoa-nguyen-bk/the_flying_bookstore_front_end/tree/main/src/app/(manager)"
    click ManagerComp "https://github.com/hoa-nguyen-bk/the_flying_bookstore_front_end/tree/main/src/components/managerPost"
    
    %% Click Event for Payment Processing Integration
    click Pay "https://github.com/hoa-nguyen-bk/the_flying_bookstore_front_end/blob/main/src/api/checkoutService.tsx"

    %% Styles
    classDef ui fill:#fcf,stroke:#333,stroke-width:2px
    classDef frontend fill:#bbf,stroke:#333,stroke-width:2px
    classDef auth fill:#ddf,stroke:#333,stroke-width:2px
    classDef manager fill:#fdd,stroke:#333,stroke-width:2px
    classDef backend fill:#fbb,stroke:#333,stroke-width:2px
    classDef integration fill:#bfb,stroke:#333,stroke-width:2px
    classDef db fill:#ffd,stroke:#333,stroke-width:2px
    classDef api fill:#efe,stroke:#333,stroke-width:2px
```
