# hcmut-tesell/tesell architecture

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

- Interactive diagram: https://gitdiagram.com/hcmut-tesell/tesell
- Repository: https://github.com/hcmut-tesell/tesell

## Overview

1. BackEnd – which serves as the API server and business logic layer (using controllers, models, and routes organized in a typical MVC pattern, along with Mongoose for database connectivity indicating a MongoDB setup).
2. Frontend – a client-facing application built with React (using Vite for development, Tailwind CSS for styling, and a route-based structure for pages like LandingPage, ProductDetail, etc.).
3. Admin_Page – an administration interface also built with React (with its own structure, components, and configurations similar to the frontend).

A. Identify the Main Components:
- Backend Application:
- Components: API endpoints (defined in the routes directory), business logic controllers, database interaction models (via Mongoose), utility functions (in the utils folder), and configuration (db configuration).
- Technologies: Node.js, Express (inferred by structure), Docker (noticeable by the Dockerfile), and MongoDB (via Mongoose).
- Frontend Application:
- Components: UI components (in src/components), pages (in src/pages), context for state management, assets, and routing.
- Technologies: React, Vite, Tailwind CSS, and other related libraries.
- Admin Interface:
- Components: Admin-specific pages (e.g., AuthPage, OrderDetail, etc.), UI layout components (like Navbar and OrderCard), and state/context management.
- Technologies: React, Vite, Tailwind CSS, Docker.
- Shared/External Components:
- Database: Likely a MongoDB instance (managed through Mongoose in the backend).
- CI/CD: Jenkins is used as indicated by Jenkinsfile.
- Containerization: Docker and docker-compose are present for deploying the different services.
- Git versioning and workflow as described in the README.

B. Determine the Relationships and Interactions:
- Frontend and Admin_Page both interact with the Backend API:
- They send HTTP requests to various routes (e.g., product, order, user endpoints) defined in the backend controllers.
- Data flows from the backend to these clients, and vice versa (for operations like placing orders or updating user information).
- Backend interacts with the Database:
- The models and the Mongoose utility (in BackEnd/utils/Mongoose.js) show the connection and interaction with MongoDB.
- The Dockerfiles in all three main folders and the docker-compose.yml file indicate containerization where each component may run in its own isolated container/environment.
- Jenkins is used to automate builds, tests, or deployment pipelines.
- Git workflow ties the entire development process together with branches and commit conventions.

C. Highlight Important Architectural Patterns and Design Principles:
- MVC Pattern in Backend: Controllers, Models, and Routes are clearly defined, promoting separation of concerns.
- Component-Driven UI for Frontend and Admin_Page: React components are organized logically (with separate directories for pages, components, assets, etc.).
- Containerization and CI/CD: Use of Docker and Jenkins illustrate modern dev-ops practices.
- Separation between client applications and the backend creating a clear API contract.

D. Include Relevant Technologies, Frameworks, and Libraries:
- Backend: Node.js, Express (implied), Mongoose (for MongoDB), Docker.
- Frontend/Admin_Page: React, Vite, Tailwind CSS, and ESLint for code quality.
- Development Tools: Git and Jenkins for source control and continuous integration.

- Under "Backend," list out controllers, models, and routes as sub-components; indicate their interactions with the Database component.
- Under "Frontend," show pages and component hierarchies; indicate its communication with the backend API.
- Under "Admin_Page," similarly display its UI components, state management, and API interactions.
- API calls from the frontend and admin interfaces to the backend.
- Data flow from the backend to the database and vice versa.
- Communication flows in deployment (using Docker containers, etc.).
5. Ancillary elements:
- A component for CI/CD (mentioning Jenkins and possibly Docker Compose).
- Version control (Git), reflecting the commit and branching workflow described in the README.

F. Additional Diagramming Tips:
- Top-level nodes for Backend, Frontend, and Admin_Page.
- Docker as a container wrapper for each service.

## Diagram (Mermaid)

```mermaid
flowchart TD

    subgraph "Backend Application"
        B_Routes["API Endpoints & Routes"]:::backend
        B_Controllers["Business Logic Controllers"]:::backend
        B_Models["Database Interaction Models"]:::backend
        B_Config["Database Config & Mongoose Setup"]:::backend
        B_Entry["Entry Point & Server Setup"]:::backend
        B_Docker["Docker Container"]:::infrastructure
        DB["MongoDB Database"]:::database
    end

    subgraph "Frontend Application"
        F_Components["UI Components & Pages"]:::frontend
        F_Assets["Assets & Public Resources"]:::frontend
        F_Main["Main Application Entry"]:::frontend
        F_Config["Dev Tool Configurations"]:::frontend
        F_Hooks["Hooks & Context"]:::frontend
        F_Docker["Docker Container"]:::infrastructure
    end

    subgraph "Admin Interface"
        A_Components["Admin Pages & Components"]:::admin
        A_Assets["Admin Assets & Context"]:::admin
        A_Main["Main Application Entry"]:::admin
        A_Config["Dev Tool Configurations"]:::admin
        A_Docker["Docker Container"]:::infrastructure
    end

    subgraph "Infrastructure"
        CI_CD["CI/CD Pipeline (Jenkins)"]:::infra
        Git["Git Version Control"]:::infra
        DockerCompose["docker-compose"]:::infra
    end

    %% Backend internal interactions
    B_Routes -->|"calls"| B_Controllers
    B_Controllers -->|"processes"| B_Models
    B_Config -->|"connects to"| DB

    %% Frontend and Admin interactions with Backend
    F_Components -->|"HTTP_API"| B_Routes
    F_Hooks -->|"HTTP_API"| B_Routes
    A_Components -->|"HTTP_API"| B_Routes

    %% Application entry to container mapping (dotted links)
    B_Entry -.-> B_Docker
    F_Main -.-> F_Docker
    A_Main -.-> A_Docker

    %% Docker containers integration with docker-compose
    B_Docker --> DockerCompose
    F_Docker --> DockerCompose
    A_Docker --> DockerCompose

    %% CI/CD and Git integration
    Git -->|"triggers"| CI_CD
    CI_CD -->|"deploys"| DockerCompose

    %% Styling Classes
    classDef backend fill:#FFCCCB,stroke:#333,stroke-width:2px;
    classDef frontend fill:#D5F5E3,stroke:#333,stroke-width:2px;
    classDef admin fill:#F9E79F,stroke:#333,stroke-width:2px;
    classDef infrastructure fill:#D6EAF8,stroke:#333,stroke-width:2px;
    classDef infra fill:#E8DAEF,stroke:#333,stroke-width:2px;
    classDef database fill:#FADBD8,stroke:#333,stroke-width:2px;

    %% Click Events for Backend Application
    click B_Routes "https://github.com/hcmut-tesell/tesell/tree/main/BackEnd/routes"
    click B_Controllers "https://github.com/hcmut-tesell/tesell/tree/main/BackEnd/controllers"
    click B_Models "https://github.com/hcmut-tesell/tesell/tree/main/BackEnd/models"
    click B_Config "https://github.com/hcmut-tesell/tesell/blob/main/BackEnd/config/db.js"
    click B_Entry "https://github.com/hcmut-tesell/tesell/blob/main/BackEnd/index.js"
    click B_Docker "https://github.com/hcmut-tesell/tesell/tree/main/BackEnd/Dockerfile"

    %% Click Events for Frontend Application
    click F_Components "https://github.com/hcmut-tesell/tesell/tree/main/frontend/src/components"
    click F_Assets "https://github.com/hcmut-tesell/tesell/tree/main/frontend/src/assets"
    click F_Main "https://github.com/hcmut-tesell/tesell/blob/main/frontend/index.html"
    click F_Config "https://github.com/hcmut-tesell/tesell/blob/main/frontend/vite.config.js"
    click F_Hooks "https://github.com/hcmut-tesell/tesell/blob/main/frontend/src/context/StoreContext.jsx"
    click F_Docker "https://github.com/hcmut-tesell/tesell/tree/main/frontend/Dockerfile"

    %% Click Events for Admin Interface
    click A_Components "https://github.com/hcmut-tesell/tesell/tree/main/admin_page/src/pages"
    click A_Assets "https://github.com/hcmut-tesell/tesell/tree/main/admin_page/src/assets"
    click A_Main "https://github.com/hcmut-tesell/tesell/blob/main/admin_page/index.html"
    click A_Config "https://github.com/hcmut-tesell/tesell/blob/main/admin_page/vite.config.js"
    click A_Docker "https://github.com/hcmut-tesell/tesell/tree/main/admin_page/Dockerfile"

    %% Click Events for Infrastructure
    click DockerCompose "https://github.com/hcmut-tesell/tesell/blob/main/docker-compose.yml"
    click CI_CD "https://github.com/hcmut-tesell/tesell/tree/main/Jenkinsfile"
    click Git "https://github.com/hcmut-tesell/tesell/blob/main/.gitignore"
```
