# nguyendaithanh2805/angular-nodejs architecture

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

- Interactive diagram: https://gitdiagram.com/nguyendaithanh2805/angular-nodejs
- Repository: https://github.com/nguyendaithanh2805/angular-nodejs

## Overview

##### Main Components
- Backend Server (Node.js/Express):
- Entry points: app.js and server.js.
- Configurations: "config/db.js" for database configuration and "config/jwt.js" for JSON Web Token setup.
- Controllers: For handling requests related to Cart, Category, Login, Menu, Order, Product, and User.
- Services: Business logic separated into CartService, CategoryService, LoginService, OrderService, ProductService, and UserService.
- Repositories: Data access layer components (e.g., CartRepository, CategoryRepository, etc.).
- Middlewares: Authentication, Authorization, and image handling middleware.
- Routes: Defines API endpoints and routing for authentication and operations on carts, categories, orders, products, and users.
- Frontend Client (Angular):
- Admin section: Contains components for admin panel tasks including managing accounts, categories, orders, products, and users.
- User section: Contains components for user functionalities such as home page, login, registration, menus, shopping cart, orders, and handling forbidden pages.
- Shared modules: Common classes (e.g., ApiResponse and guards, interceptors, and services for authentication, cart, category, etc.).
- Assets: Includes styles, images, and third-party libraries.
- Database:
- Indicative file: "db_coffee.sql", which likely represents the database schema used by the backend.

##### Relationships and Interactions
- Client-to-Server Communication:
- The Angular client consumes RESTful APIs exposed by the Node.js backend.
- Server Internals:
- Controllers call corresponding Services to process business logic.
- Services interact with Repositories to perform CRUD operations on the database.
- Middlewares (for Authentication and Authorization) intercept incoming API requests to validate user access.
- The Configuration files (db.js and jwt.js) support these operations.
- External Services (optional):

##### Architectural Patterns and Design Principles to Highlight
- MVC (Model-View-Controller) aspects visible in the separation between Controllers, Services, and Repositories.
- Layered architecture: keeping separation of concerns (configuration, middleware, routing, business logic, data access).
- Use of RESTful API design principles in the backend with clearly segmented endpoints.
- Security patterns: Use of JWT for authentication and dedicated Authorization middleware for route protections.
- Angular module separation: Distinct modules for admin versus user functionalities.

##### Technologies, Frameworks, and Libraries
- Backend: Node.js with Express, JWT for authentication, and a relational database managed via the "db_coffee.sql" file.
- Frontend: Angular framework, Angular CLI (angular.json), and typical libraries for HTTP, routing, guards, and interceptors.
- Additional dependencies: Third-party plugins and assets on the client side (such as chart libraries, owl carousel, toastr, etc.) and styling frameworks possibly integrated into the design.

##### Elements
- Each component should have a clear and self-explanatory label (e.g., “LoginController”, “ProductService”, “Admin Dashboard”, “User Login Component”).
- From the Angular client (both admin and user modules) to the backend API endpoints.
- From Controllers to Services to Repositories.
- From the backend to the Database.
- Clearly demarcate the boundary between the client and server environments.

## Diagram (Mermaid)

```mermaid
flowchart TD

    %% Backend Server Cluster
    subgraph "Backend Server"
        direction TB

        %% Entry Points Subgraph
        subgraph "Entry Points"
            direction TB
            BE_app("app.js"):::backend
            BE_server("server.js"):::backend
            BE_EP_Combined("Combined Entry Points"):::backend
            BE_app --> BE_EP_Combined
            BE_server --> BE_EP_Combined
        end

        %% Configuration Subgraph
        subgraph "Configuration"
            direction TB
            BE_db("db.js"):::backend
            BE_jwt("jwt.js"):::backend
            BE_Config_Combined("Combined Configuration"):::backend
            BE_db --> BE_Config_Combined
            BE_jwt --> BE_Config_Combined
        end

        BE_EP_Combined --> BE_Config_Combined

        %% Middlewares Node
        BE_mw("Middlewares: Authentication,Authorization,HandleImage"):::backend
        BE_Config_Combined --> BE_mw

        %% Routes Node
        BE_routes("Routes: Authentication,Cart,Category,Menu,Order(Admin),Order,Product,User"):::backend
        BE_mw --> BE_routes

        %% Controllers Node
        BE_ctrl("Controllers: Cart,Category,Login,Menu,Order,Product,User"):::backend
        BE_routes --> BE_ctrl

        %% Services Node
        BE_svc("Services: Cart,Category,Login,Order,Product,User"):::backend
        BE_ctrl --> BE_svc

        %% Repositories Node
        BE_repo("Repositories: Cart,Category,Order,OrderDetail,Product,User"):::backend
        BE_svc --> BE_repo

        %% Database Node
        Database("Database: db_coffee.sql"):::database
        BE_repo -->|"CRUDoperations"| Database
    end

    %% Frontend Client Cluster
    subgraph "Frontend Client"
        direction TB
        FE_admin("Admin Module"):::frontend
        FE_user("User Module"):::frontend
        FE_common("Common Modules"):::frontend
        FE_services("Shared Services"):::frontend
        FE_assets("Assets: CSS,Images,JSLibraries"):::frontend

        %% Frontend internal dependencies
        FE_common --> FE_admin
        FE_common --> FE_user
        FE_services --> FE_admin
        FE_services --> FE_user
        FE_assets --> FE_admin
        FE_assets --> FE_user
    end

    %% Communication between Frontend and Backend
    FE_admin ---|"HTTP_Request"| BE_routes
    FE_user ---|"HTTP_Request"| BE_routes

    %% Click Events for Backend Components
    click BE_app "https://github.com/nguyendaithanh2805/angular-nodejs/blob/main/Server/app.js"
    click BE_server "https://github.com/nguyendaithanh2805/angular-nodejs/blob/main/Server/server.js"
    click BE_db "https://github.com/nguyendaithanh2805/angular-nodejs/blob/main/Server/config/db.js"
    click BE_jwt "https://github.com/nguyendaithanh2805/angular-nodejs/blob/main/Server/config/jwt.js"
    click BE_ctrl "https://github.com/nguyendaithanh2805/angular-nodejs/tree/main/Server/controllers/"
    click BE_svc "https://github.com/nguyendaithanh2805/angular-nodejs/tree/main/Server/services/"
    click BE_repo "https://github.com/nguyendaithanh2805/angular-nodejs/tree/main/Server/repositories/"
    click BE_mw "https://github.com/nguyendaithanh2805/angular-nodejs/tree/main/Server/middlewares/"
    click BE_routes "https://github.com/nguyendaithanh2805/angular-nodejs/tree/main/Server/routes/"

    %% Click Event for Database Schema
    click Database "https://github.com/nguyendaithanh2805/angular-nodejs/blob/main/db_coffee.sql"

    %% Click Events for Frontend Components
    click FE_admin "https://github.com/nguyendaithanh2805/angular-nodejs/tree/main/client/src/app/admins/"
    click FE_user "https://github.com/nguyendaithanh2805/angular-nodejs/tree/main/client/src/app/users/"
    click FE_common "https://github.com/nguyendaithanh2805/angular-nodejs/tree/main/client/src/app/common/"
    click FE_services "https://github.com/nguyendaithanh2805/angular-nodejs/tree/main/client/src/app/services/"
    click FE_assets "https://github.com/nguyendaithanh2805/angular-nodejs/tree/main/client/src/assets/"

    %% Styles
    classDef backend fill:#f9e79f,stroke:#ff7f50,stroke-width:2px;
    classDef frontend fill:#aed6f1,stroke:#1f618d,stroke-width:2px;
    classDef database fill:#b9f6ca,stroke:#2e7d32,stroke-width:2px;
```
