# nhan295/ct313h01-m01 architecture

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

- Interactive diagram: https://gitdiagram.com/nhan295/ct313h01-m01
- Repository: https://github.com/nhan295/ct313h01-m01

## Overview

- A backend API built using Node.js (likely with Express) that follows an MVC-like architecture (with folders for controllers, models, routes, and configuration) and utilizes a SQL database (as evidenced by database.sql and configuration files such as knexfile.js).
- A frontend built with Vue.js (using Vite as indicated by vite.config.js), organizing views, components, and stores for managing state (e.g., useCart.js and useProducts.js).

##### Main Components
a. Frontend:
- Components: Views (e.g., HomePage.vue, BookDetail.vue, CartPage.vue, UserPage.vue), Base components (e.g., Book_Cart.vue, ListBook.vue), and layout components (e.g., HomePage_Header.vue, UserPage_Header.vue).
- Router: The file router.js indicates navigation between various views.
- State Management: Stores like useCart.js and useProducts.js.
b. Backend API:
- Server Entry Point: server.js that bootstraps the application.
- Application Logic: app.js which ties the configuration and middleware.
- Controllers: For handling business logic (userController.js).
- Models: Handling data interactions and business object representations (userModel.js).
- Routes: API endpoints provided by userRoute.js mapping requests to controllers.
- Database Configuration: db.js and knexfile.js provide database connection and query management.
c. Database:
- The SQL file (database.sql) indicates the project uses a relational database to store bookshop data (e.g., user data, books, orders).

##### Relationships and Interactions
- The Frontend communicates with the Backend API via HTTP requests (using the API endpoints defined in the backend).
- The Backend API processes these requests using its controllers and models, and interacts with the SQL database to perform CRUD operations.
- Data flow from the frontend to the backend (user actions triggering HTTP requests).
- Backend service interactions with the SQL database.
- Optionally, include internal calls within the backend (e.g., configuration loading, middleware invocation) if detail is desired.

##### Architectural Patterns and Design Principles
- MVC or similar separation in the backend (Routes → Controllers → Models).
- Clear separation of concerns between the client (frontend) and the server (backend).
- Use of state management in the frontend (Vue stores) to handle shopping cart or product list state.
- Separation of configuration (environment files like .env, knexfile.js) suggesting flexible deployment.

##### Mention Relevant Technologies and Frameworks
- Frontend:
- Vue.js with a Vite-powered build system.
- Component-based design (with single-file components like App.vue, BookDetail.vue, etc.).
- Backend:
- Node.js, Express (inferred from file organization such as server.js, controllers, routes).
- Knex (for SQL query building as indicated in knexfile.js).
- Database:
- A SQL-based system as initialized by database.sql.

## Diagram (Mermaid)

```mermaid
flowchart TD
    %% Frontend Subgraph
    subgraph "Vue Frontend"
        subgraph "UI Layer"
            FViews("Views"):::frontendUi
            FComponents("Components"):::frontendUi
        end
        FRouter("Router"):::frontendRouter
        FStores("State Stores"):::frontendStore
    end

    %% Backend Subgraph
    subgraph "Node/Express Backend"
        Fserver("Server (server.js)"):::backendServer
        Fapp("Application (app.js)"):::backendApp
        FRoutes("Routes (userRoute.js)"):::backendRoutes
        FController("Controller (userController.js)"):::backendController
        FModels("Model (userModel.js)"):::backendModels
        subgraph "Configuration"
            FConfigDB("DB Config (db.js)"):::backendConfig
            FConfigKnex("Knex Config (knexfile.js)"):::backendConfig
        end
    end

    %% Database Node
    SQL("SQL Database"):::database

    %% Connections between Frontend nodes
    FViews -->|"uses"| FRouter
    FComponents -->|"renders within"| FViews
    FStores -->|"manages state for"| FViews

    %% Connection from Frontend to Backend
    FRouter -->|"HTTP_request"| Fserver

    %% Backend internal flow
    Fserver --> Fapp
    Fapp --> FConfigDB
    Fapp --> FRoutes
    FRoutes --> FController
    FController --> FModels
    FModels -->|"queries"| SQL

    %% Styles and Colors
    classDef frontendUi fill:#FDEDEC,stroke:#C0392B,stroke-width:2px;
    classDef frontendRouter fill:#EBF5FB,stroke:#2980B9,stroke-width:2px;
    classDef frontendStore fill:#E8F8F5,stroke:#27AE60,stroke-width:2px;
    classDef backendServer fill:#FEF9E7,stroke:#F39C12,stroke-width:2px;
    classDef backendApp fill:#F9EBEA,stroke:#C0392B,stroke-width:2px;
    classDef backendRoutes fill:#F5EEF8,stroke:#8E44AD,stroke-width:2px;
    classDef backendController fill:#FDFEFE,stroke:#566573,stroke-width:2px;
    classDef backendModels fill:#FDEBD0,stroke:#D35400,stroke-width:2px;
    classDef backendConfig fill:#EBF5FB,stroke:#2471A3,stroke-width:2px;
    classDef database fill:#EBF5FB,stroke:#1F618D,stroke-width:2px;

    %% Click Events for Frontend
    click FViews "https://github.com/nhan295/ct313h01-m01/tree/master/frontend/src/view"
    click FComponents "https://github.com/nhan295/ct313h01-m01/tree/master/frontend/src/components"
    click FRouter "https://github.com/nhan295/ct313h01-m01/blob/master/frontend/src/router.js"
    click FStores "https://github.com/nhan295/ct313h01-m01/tree/master/frontend/src/stores"

    %% Click Events for Backend
    click Fserver "https://github.com/nhan295/ct313h01-m01/blob/master/backend-api/server.js"
    click Fapp "https://github.com/nhan295/ct313h01-m01/blob/master/backend-api/src/app.js"
    click FRoutes "https://github.com/nhan295/ct313h01-m01/blob/master/backend-api/src/routes/userRoute.js"
    click FController "https://github.com/nhan295/ct313h01-m01/blob/master/backend-api/src/controllers/userController.js"
    click FModels "https://github.com/nhan295/ct313h01-m01/blob/master/backend-api/src/models/userModel.js"
    click FConfigDB "https://github.com/nhan295/ct313h01-m01/blob/master/backend-api/src/config/db.js"
    click FConfigKnex "https://github.com/nhan295/ct313h01-m01/blob/master/backend-api/src/config/knexfile.js"

    %% Click Event for Database Schema
    click SQL "https://github.com/nhan295/ct313h01-m01/blob/master/database.sql"
```
