# zombiegenz/tank-food architecture

> Architecture diagram of the GitHub repository zombiegenz/tank-food, 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/zombiegenz/tank-food
- Repository: https://github.com/zombiegenz/tank-food

## Overview

##### Main Components

- Frontend (Client):
- Built with React, TypeScript, and styled with Tailwind CSS combined with UI frameworks such as Ant Design, Material-UI, and Mantine UI.
- Contains “pages” for different views (e.g., account management, order pages, product pages, etc.) and reusable components (e.g., navbar, loading components, real-time token verification).
- Uses React Router for navigation and Axios for communicating with backend APIs.

- Backend (Server):
- Built on Express.js in a Node.js runtime environment with TypeScript.
- Organized into controllers, services, middlewares, and models (schemas and request models) indicating an MVC-like architecture.
- Contains separate folders for routes, controllers, and services to handle specific business functionalities like account management, orders, products, categories, vouchers, and statistical reporting.

- Database:
- Uses MongoDB (a NoSQL database) which is likely abstracted via data models and schemas in the “server/src/models/schemas” folder.

- External Services & Integrations:
- Firebase for realtime database features, authentication, and cloud messaging.
- Socket.io for realtime communication.
- Nodemailer for email notifications.
- Discord Bot and possibly integrations with Payment Gateway (Sepay) for order/payment processing.
- Node-cron for scheduling background tasks (e.g., generating statistical reports, auto-unban accounts, backing up files).

##### Out the Relationships and Interaction Flow

- Client-to-Server Communication:
- The client makes RESTful API calls via Axios to the server’s API endpoints.
- React Router defines the navigation paths, translating user actions (e.g., placing an order, managing accounts) into API requests to the backend.

- Server Internal Architecture:
- Routes: They act as the entry point for incoming API requests and forward these to the corresponding controllers.
- Controllers: Handle the request logic by interacting with services.
- Services: Contain business logic and interact with data sources (the database via models/schemas, external APIs like Firebase) and utilities.
- Middlewares: Handle cross-cutting concerns such as authentication (using JWT), validation, error handling, and logging.
- Jobs: Scheduled tasks such as generating statistical reports or managing background processes are maintained in the “jobs” folder.
- Utils: Provide helper functions for date manipulations, encryption, logging, JWT handling, and more.

##### Architectural Patterns & Design Principles

- Layered Architecture: Separation between UI (client), business logic (controllers/services), data access (models/schemas), and cross-cutting concerns (middlewares and utilities).
- MVC-like Organization on the backend: Clear division between routes, controllers, and data models.
- Real-time Communication: Use of Firebase and Socket.io to provide real-time updates and notifications.
- Modular Structure: Both the client and server are modularized; for example, the client’s “views”, “components”, and “constants” are clearly separated, while the server splits responsibilities across controllers, services, and middlewares.

##### Relevant Technologies and Their Roles

- Frontend: React.js, Tailwind CSS, Ant Design, Material-UI, Mantine UI, Framer Motion, Recharts, React Router, Axios.
- Backend: Express.js, Node.js, TypeScript, nodemailer, node-cron, JWT, Express Validator.
- Database: MongoDB.
- External Services: Firebase (realtime, auth, cloud messaging), Socket.io (realtime communication), Discord Bot (system notifications), and Sepay (payment gateway).

## Diagram (Mermaid)

```mermaid
flowchart TD
    %% Frontend (Client)
    subgraph "Frontend (Client)"
        F_Pages["Pages (Views)"]:::frontend
        F_Components["Reusable Components"]:::frontend
        F_API["API Communication & Entry"]:::frontend
    end

    %% Backend (Server)
    subgraph "Backend (Server)"
        B_Routes["API Routes"]:::backend
        B_Controllers["Controllers"]:::backend
        B_Services["Services"]:::backend
        B_Middlewares["Middlewares"]:::backend
        B_Models["Data Models & Schemas"]:::backend
        B_RequestModels["Request Models"]:::backend
        B_Jobs["Job Schedulers"]:::backend
        B_Utils["Utility Modules"]:::backend
    end

    %% Database Layer
    subgraph "Database"
        DB["MongoDB"]:::database
    end

    %% External Services & Integrations
    subgraph "External Services"
        B_Firebase["Firebase"]:::external
        B_Socket["Socket.io"]:::external
        B_Payment["Payment Gateway"]:::external
        B_Discord["Discord Bot"]:::external
        B_Nodemailer["Nodemailer"]:::external
    end

    %% Frontend Internal Relations
    F_Pages -->|"triggers"| F_API
    F_Components -->|"used by"| F_Pages

    %% Client to Server Communication
    F_API -->|"REST_API_call"| B_Routes

    %% Backend Internal Architecture
    B_Routes -->|"to_controller"| B_Controllers
    B_Controllers -->|"delegates_to"| B_Services
    B_Routes -.->|"auth/validate"| B_Middlewares
    B_Services -->|"DB_access"| B_Models
    B_Models -->|"stores_data"| DB
    B_Services -->|"invokes_helpers"| B_Utils
    B_Jobs -->|"scheduled_tasks"| B_Services

    %% External Integrations from Services
    B_Services -->|"calls_Firebase"| B_Firebase
    B_Services -->|"calls_Socketio"| B_Socket
    B_Services -->|"payment_integration"| B_Payment
    B_Services -->|"sends_notifications"| B_Discord
    B_Services -->|"sends_emails"| B_Nodemailer

    %% Styles
    classDef frontend fill:#C6E2FF,stroke:#007AFF,stroke-width:2px;
    classDef backend fill:#D4EDDA,stroke:#28A745,stroke-width:2px;
    classDef external fill:#F8D7DA,stroke:#DC3545,stroke-width:2px;
    classDef database fill:#FFF3CD,stroke:#FFC107,stroke-width:2px;

    %% Click Events
    click F_Pages "https://github.com/zombiegenz/tank-food/tree/master/client/src/views/pages"
    click F_Components "https://github.com/zombiegenz/tank-food/tree/master/client/src/views/components"
    click F_API "https://github.com/zombiegenz/tank-food/blob/master/client/src/App.tsx"
    click F_API "https://github.com/zombiegenz/tank-food/blob/master/client/src/main.tsx"

    click B_Routes "https://github.com/zombiegenz/tank-food/tree/master/server/src/routes"
    click B_Controllers "https://github.com/zombiegenz/tank-food/tree/master/server/src/controllers"
    click B_Services "https://github.com/zombiegenz/tank-food/tree/master/server/src/services"
    click B_Middlewares "https://github.com/zombiegenz/tank-food/tree/master/server/src/middlewares"
    click B_Models "https://github.com/zombiegenz/tank-food/tree/master/server/src/models/schemas"
    click B_RequestModels "https://github.com/zombiegenz/tank-food/tree/master/server/src/models/requests"
    click B_Jobs "https://github.com/zombiegenz/tank-food/tree/master/server/src/jobs"
    click B_Utils "https://github.com/zombiegenz/tank-food/tree/master/server/src/utils"
    
    click B_Firebase "https://github.com/zombiegenz/tank-food/blob/master/server/src/services/firebase.services.ts"
    click B_Discord "https://github.com/zombiegenz/tank-food/blob/master/server/src/utils/discord.utils.ts"
    click B_Nodemailer "https://github.com/zombiegenz/tank-food/blob/master/server/src/utils/mail.utils.ts"
```
