# egjohnc02/alphabook-cpl_04_group05 architecture

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

- Interactive diagram: https://gitdiagram.com/egjohnc02/alphabook-cpl_04_group05
- Repository: https://github.com/egjohnc02/alphabook-cpl_04_group05

## Overview

##### Project Type and Purpose
- The project is a single-page application (SPA) built using React with TypeScript. It recreates and extends features of the Alphabooks.vn website by providing various pages like Home, Book Catalogue, About, News & Events, Account management (both Customer and Admin), and several utility components (Navbar, Footer, Header, etc.).
- The README confirms that the site involves multiple pages (e.g., “Trang chủ”, “Tủ sách”, “Tin tức - Sự kiện”, “Đăng Nhập và Đăng Ký”) and that many pages are “Done,” while some (search and cart) are pending. It thus follows a full-stack frontend architecture (the backend may be handled externally via a database or via Firebase, as seen in the src/firebase folder and apiService.ts).

##### File Structure
- Top-Level Files/Folders: Notice the presence of Vite configuration files (vite.config.ts) and other configuration files like .env, package.json, etc. These indicate a Vite-based React development environment.
- src Directory: This holds the core application code. It includes:
- Components: Contains reusable UI components (Account, Navbar, Footer, Login, etc.) separated by logical subfolders (e.g., Account has Admin and Customer subdirectories).
- Pages: Contains individual pages for each site view with directories like /page/Book, /page/Home, /page/Account, etc. This shows an MVC-like separation between routing/views and components.
- Assets: Contains images, styles, and resource files for various pages.
- Utility Modules: Modules like apiService.ts for API calls, firebase configuration in src/firebase/firebase.tsx, and additional utility code.
- Dist Folder: Indicates the production build output, meaning the structure’s built artifacts are separate from source code.

##### README Insights
- The README provides an “Introduce” and structured list of pages and components. It outlines which pages are completed and gives functional notes (e.g., “List and filter book follow categories, price,” “Take data from database and verify”).
- The provided structure sample also confirms the high-level separation between Pages, Components, and Assets.

##### Main Architectural Components
a. Frontend UI Layer:
- Client Entry Point: index.html, main.tsx, and App.tsx (main React component).
- Routing and Navigation: Components such as ProtectedRoute, Navbar, Header, and Footer manage navigation and conditional access.
b. Page Rendering Layer:
- Pages Folder: Contains pages like Home, Book, Account, News, etc., each representing a unique view. Represent them as individual modules.
c. Reusable Component Library:
- Components: UI elements such as Login, Cart, Account management pages, and subcomponents like BookManagement in Admin.
d. Service and Data Access Layer:
- apiService.ts: Handles API calls. This module represents your bridge to external data (likely a backend or Firebase).
- src/firebase directory: Illustrates use of Firebase for authentication or database operations.
e. Assets & Static Resources:
f. Build and Deployment:
- Vite configuration files and dist directory showing the process from development to production.

##### Architectural Patterns Noted
- Component-Based Architecture: The use of React with its modular components.
- Routing/Navigation: The inclusion of a ProtectedRoute indicates role-based routing and segmenting pages requiring authentication.
- Separation of Concerns: Dividing UI (components/pages) from service logic (apiService, Firebase integration) and assets.
- External Service Integration: Firebase and possibly external database endpoints for fetching data.

## Diagram (Mermaid)

```mermaid
flowchart TD
    %% User Interaction
    user["User (Browser)"]:::client

    %% Client Layer
    subgraph "Client Layer"
        index_html["index.html"]:::client
        main_tsx["main.tsx"]:::client
        app_tsx["App.tsx"]:::client
    end

    %% Routing & Navigation Layer
    subgraph "Routing & Navigation"
        protected["ProtectedRoute"]:::routing
        navbar["Navbar"]:::routing
        header["Header"]:::routing
        footer["Footer"]:::routing
    end

    %% Page Rendering Layer
    subgraph "Page Rendering Layer"
        home["Home Page"]:::pages
        book["Book Catalogue Page"]:::pages
        account_admin["Account Management - Admin"]:::pages
        account_customer["Account Management - Customer"]:::pages
        news["News & Events"]:::pages
        contact["Contact Page"]:::pages
        footer_info["Footer Info"]:::pages
        subscribe["Subscribe Page"]:::pages
    end

    %% Reusable Components
    subgraph "Reusable Components"
        login["Login"]:::components
        cart["Cart"]:::components
        backtop["Backtop"]:::components
        contact_button["ContactButton"]:::components
    end

    %% Service & Data Access Layer
    subgraph "Service & Data Access"
        api["API Service"]:::service
        firebase["Firebase"]:::service
    end

    %% Assets & Build
    subgraph "Assets & Build"
        assets["Assets"]:::assets
        vite["Vite Config"]:::build
        dist["Dist Folder"]:::build
    end

    %% Connections for client entry flow
    user --> index_html
    index_html --> main_tsx
    main_tsx --> app_tsx

    %% Connections from App to Routing components
    app_tsx --> protected
    app_tsx --> navbar
    app_tsx --> header
    app_tsx --> footer

    %% Routing directing to Page Rendering
    protected -->|"routes"| home
    protected -->|"routes"| book
    protected -->|"routes"| account_admin
    protected -->|"routes"| account_customer
    protected -->|"routes"| news
    protected -->|"routes"| contact
    protected -->|"routes"| subscribe

    navbar -->|"links"| home
    navbar -->|"links"| book
    navbar -->|"links"| account_customer
    header -->|"displays"| home
    footer -->|"links"| footer_info

    %% Pages interacting with Services
    home -->|"fetches"| api
    book -->|"fetches"| api
    account_admin -->|"manages"| api
    account_customer -->|"fetches"| api
    news -->|"fetches"| api

    account_admin -->|"auth"| firebase
    account_customer -->|"auth"| firebase

    %% Pages embedding Reusable Components
    home -->|"uses"| login
    home -->|"uses"| cart
    book -->|"uses"| cart
    account_customer -->|"uses"| login

    %% Pages accessing Assets
    home --> assets
    book --> assets
    account_admin --> assets
    account_customer --> assets
    news --> assets
    contact --> assets
    subscribe --> assets
    footer_info --> assets

    %% Build and Deployment Flow
    app_tsx --> vite
    vite --> dist

    %% Click Events
    click index_html "https://github.com/egjohnc02/alphabook-cpl_04_group05/blob/main/index.html"
    click main_tsx "https://github.com/egjohnc02/alphabook-cpl_04_group05/blob/main/src/main.tsx"
    click app_tsx "https://github.com/egjohnc02/alphabook-cpl_04_group05/blob/main/src/App.tsx"
    click protected "https://github.com/egjohnc02/alphabook-cpl_04_group05/blob/main/src/ProtectedRoute/ProtectedRoute.tsx"
    click navbar "https://github.com/egjohnc02/alphabook-cpl_04_group05/blob/main/src/components/Navbar/Navbar.tsx"
    click header "https://github.com/egjohnc02/alphabook-cpl_04_group05/blob/main/src/components/Header/Header.tsx"
    click footer "https://github.com/egjohnc02/alphabook-cpl_04_group05/blob/main/src/components/Footer/Footer.tsx"
    click home "https://github.com/egjohnc02/alphabook-cpl_04_group05/blob/main/src/page/Home/Home.tsx"
    click book "https://github.com/egjohnc02/alphabook-cpl_04_group05/blob/main/src/page/Book/Book.tsx"
    click account_admin "https://github.com/egjohnc02/alphabook-cpl_04_group05/blob/main/src/page/Account/Admin/Admin.tsx"
    click account_customer "https://github.com/egjohnc02/alphabook-cpl_04_group05/blob/main/src/page/Account/Customer/Customer.tsx"
    click news "https://github.com/egjohnc02/alphabook-cpl_04_group05/tree/main/src/page/News/"
    click contact "https://github.com/egjohnc02/alphabook-cpl_04_group05/blob/main/src/page/Contact/Contact.tsx"
    click footer_info "https://github.com/egjohnc02/alphabook-cpl_04_group05/tree/main/src/page/Footer/"
    click subscribe "https://github.com/egjohnc02/alphabook-cpl_04_group05/blob/main/src/page/subscribe/Subscribe.tsx"
    click login "https://github.com/egjohnc02/alphabook-cpl_04_group05/blob/main/src/components/Login/LoginWith.tsx"
    click cart "https://github.com/egjohnc02/alphabook-cpl_04_group05/blob/main/src/components/Cart/Cart.tsx"
    click backtop "https://github.com/egjohnc02/alphabook-cpl_04_group05/blob/main/src/components/Backtop/Backtop.tsx"
    click contact_button "https://github.com/egjohnc02/alphabook-cpl_04_group05/blob/main/src/components/ContactButton/ContactButton.tsx"
    click api "https://github.com/egjohnc02/alphabook-cpl_04_group05/blob/main/src/apiService.ts"
    click firebase "https://github.com/egjohnc02/alphabook-cpl_04_group05/blob/main/src/firebase/firebase.tsx"
    click assets "https://github.com/egjohnc02/alphabook-cpl_04_group05/tree/main/src/assets"
    click vite "https://github.com/egjohnc02/alphabook-cpl_04_group05/blob/main/vite.config.ts"
    click dist "https://github.com/egjohnc02/alphabook-cpl_04_group05/tree/main/dist"

    %% Styles
    classDef client fill:#AED6F1,stroke:#1B4F72,stroke-width:2px;
    classDef routing fill:#FAD7A0,stroke:#D35400,stroke-width:2px;
    classDef pages fill:#D5F5E3,stroke:#1E8449,stroke-width:2px;
    classDef components fill:#F9E79F,stroke:#B9770E,stroke-width:2px;
    classDef service fill:#F5B7B1,stroke:#922B21,stroke-width:2px;
    classDef assets fill:#D7BDE2,stroke:#6C3483,stroke-width:2px;
    classDef build fill:#CCD1D1,stroke:#566573,stroke-width:2px;
```
