# taptapking/it4409-20241-151901-n14 architecture

> Architecture diagram of the GitHub repository taptapking/it4409-20241-151901-n14, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2025-03-30). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/taptapking/it4409-20241-151901-n14
- Repository: https://github.com/taptapking/it4409-20241-151901-n14

## Overview

##### Main Components
- Frontend Components:
- Two separate UI layers exist:
- One in the “frontend” directory (which includes components like “addProducts.jsx”, “SignIn.jsx”, “adminHome.jsx”) intended for administrative functions.
- Another in the “frontend_customer” directory focusing on the customer side (with pages like “Cart.jsx”, “Checkout.jsx”, “ItemDetails.jsx”).
- Backend API Server:
- The “backend” directory encapsulates the core server side elements:
- Entry point (app.js)
- Configuration files: e.g., “db.js” indicating database connectivity.
- Controllers (MediaController, authController, accountController, orderController, paymentController) that process business logic.
- Routes which map URL endpoints to the controllers.
- Models defined under “backend/models” (e.g., Account.js, Invoice.js, Order.js, etc.) that define the data schema.
- Middleware (authentication and file handling via multer) to process requests.
- Services that encapsulate additional logic like authentication.
- Additional Shared Components:
- There is also a “models” folder at the root and “services” folder that includes, for instance, a “paymentGateway.js”. These likely represent shared resources or bridges to external services integrated within the backend.
- External Systems:
- Optionally, an external payment service might be abstracted as part of the payment gateway in the “services” folder.

##### Relationships and Interactions
- Within the backend, illustrate how incoming requests are routed:
- Requests go through middleware (authentication, file upload handling via multer) before reaching specific controllers.
- From Controllers, requests interact with models (data layer) via service classes (e.g., authService, payment processing).
- Connection from the “backend/config” (db.js) to an external Database component.
- If applicable, indicate external calls (e.g., payment processing via external gateways integrated in “services/paymentGateway.js”).

##### Architectural Patterns and Design Principles
- The backend follows an MVC/MVCS (Model-View-Controller-Service) pattern, with controllers handling incoming requests, models representing the database schema, and services providing business logic.
- The separation between admin and customer UIs reinforces clean separation of concerns with dedicated interfaces for distinct user roles.
- Middleware is used to centralize cross-cutting concerns (like authentication and file management).

##### Technologies and Frameworks (as inferred)
- Node.js with Express for backend server logic.
- Likely a relational or NoSQL database as suggested by the db.js file.
- React-based frontend (evident from the presence of jsx files and the usage of Vite for a fast development setup).
- Tailwind CSS appears to be used in frontend styling (as indicated by tailwind.config.js).
- Use of modern bundlers like Vite and tools for linting (eslint).

## Diagram (Mermaid)

```mermaid
flowchart TD
    subgraph "Frontend"
        FE_Admin["Frontend (Admin UI)"]:::frontend
        FE_Customer["Frontend (Customer UI)"]:::frontend
    end

    subgraph "Backend (Express API)"
        API_Entry["Entry Point (app.js)"]:::backend
        Config["Configuration (db.js)"]:::backend
        Middleware["Middleware (Auth,Multer)"]:::backend
        Routes["Routes"]:::backend
        Controllers["Controllers (Media,Auth,Account,Order,Payment)"]:::backend
        Services["Services (AuthService)"]:::backend
        BackendModels["Backend Models"]:::backend
    end

    subgraph "Shared Components"
        SharedModels["Shared Models"]:::shared
        PaymentGateway["Payment Gateway"]:::shared
    end

    Database["Database"]:::db

    FE_Admin -->|"RESTcalls"| Routes
    FE_Customer -->|"RESTcalls"| Routes

    Routes -->|"uses"| Middleware
    Routes -->|"routesTo"| Controllers
    Middleware -->|"processes"| Controllers
    Controllers -->|"calls"| Services
    Controllers -->|"interactsWith"| BackendModels
    Services -->|"accesses"| BackendModels

    Config -->|"connectsTo"| Database

    Controllers -->|"mayUse"| SharedModels
    Services -->|"invokes"| PaymentGateway

    click FE_Admin "https://github.com/taptapking/it4409-20241-151901-n14/tree/main/frontend/"
    click FE_Customer "https://github.com/taptapking/it4409-20241-151901-n14/tree/main/frontend_customer/"
    click API_Entry "https://github.com/taptapking/it4409-20241-151901-n14/blob/main/backend/app.js"
    click Config "https://github.com/taptapking/it4409-20241-151901-n14/blob/main/backend/config/db.js"
    click Controllers "https://github.com/taptapking/it4409-20241-151901-n14/tree/main/backend/controllers/"
    click Routes "https://github.com/taptapking/it4409-20241-151901-n14/tree/main/backend/routes/"
    click Middleware "https://github.com/taptapking/it4409-20241-151901-n14/tree/main/backend/middleware/"
    click BackendModels "https://github.com/taptapking/it4409-20241-151901-n14/tree/main/backend/models/"
    click Services "https://github.com/taptapking/it4409-20241-151901-n14/tree/main/backend/services/"
    click SharedModels "https://github.com/taptapking/it4409-20241-151901-n14/tree/main/models/"
    click PaymentGateway "https://github.com/taptapking/it4409-20241-151901-n14/blob/main/services/paymentGateway.js"

    classDef frontend fill:#FFDD93,stroke:#333,stroke-width:2px;
    classDef backend fill:#AEDFF7,stroke:#333,stroke-width:2px;
    classDef shared fill:#C2EABD,stroke:#333,stroke-width:2px;
    classDef db fill:#F7C7F7,stroke:#333,stroke-width:2px;
```
