# tusharkkp/ecotravel architecture

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

- Interactive diagram: https://gitdiagram.com/tusharkkp/ecotravel
- Repository: https://github.com/tusharkkp/ecotravel

## Overview

##### Project type and purpose
- This is a full-stack web application (“Eco-Travel Planner”) with a React-based Single Page Application (SPA) on the client side and a Node.js/Express REST API on the server side.
- Purpose: Let users compare and book eco-friendly travel options, calculate carbon footprints, earn and spend “EcoCoins,” and track personal eco-impact.

##### File structure
- Top-level directories:
- client/ – React frontend: public assets, source code (components, pages, services, context, styles).
- server/ – Express backend: routes, controllers (business logic), models (Mongoose schemas), middleware (authentication), configuration.
- Other files:
- DEPLOYMENT.md, deploy.js – deployment instructions/scripts.
- .env.sample files in each folder – environment variable requirements.
- Notice MVC pattern in server (models/controllers/routes), and component-based organization in client (UI components, pages, context/providers, API wrappers).

##### README for additional insights
- Tech stack: React, Tailwind CSS, Chart.js, Leaflet on the frontend; Node.js, Express, MongoDB, JWT on the backend.
- External dependencies: Carbon Calculator API (configurable via REACT_APP_API_URL), third-party chatbot service, possibly mapping/geolocation services.
- Deployment targets: Netlify (client) and any Node hosting (server).

## Diagram (Mermaid)

```mermaid
flowchart TD
    %% Client Layer
    subgraph "Client SPA (React + Tailwind)" 
        direction TB
        ClientEntry["Index<br/>client/src/index.js"]:::frontend
        MainApp["App Component<br/>client/src/App.js"]:::frontend
        subgraph "Pages"
            direction TB
            Compare["CompareOptions.jsx"]:::frontend
            Calculator["CarbonCalculator.js"]:::frontend
            Wallet["WalletPage.jsx"]:::frontend
            Profile["ProfilePage.jsx"]:::frontend
            Contribute["ContributePage.jsx"]:::frontend
        end
        subgraph "Layout Components"
            direction TB
            Navbar["Navbar.jsx"]:::frontend
            Footer["Footer.jsx"]:::frontend
            MainLayout["MainLayout.js"]:::frontend
        end
        AuthContext["AuthContext.js"]:::frontend
        subgraph "Services / API Wrappers"
            direction TB
            AuthAPI["auth.js"]:::frontend
            EcoCoinService["EcoCoinService.js"]:::frontend
            ChatService["chatbotService.js"]:::frontend
            LeafToken["LeafTokenService.js"]:::frontend
        end
    end

    %% Backend Layer
    subgraph "Backend API (Express + Mongoose)"
        direction TB
        ServerEntry["server.js"]:::business
        AuthMiddleware["authMiddleware.js"]:::business
        subgraph "Routes"
            direction TB
            AuthRoutes["authRoutes.js"]:::business
            CarbonRoutes["carbonCalculatorRoutes.js"]:::business
            CertRoutes["certificationRoutes.js"]:::business
            ReviewRoutes["reviewRoutes.js"]:::business
            RewardsRoutes["rewardsRoutes.js"]:::business
            UserRoutes["userRoutes.js"]:::business
        end
        subgraph "Controllers"
            direction TB
            Controllers["*Controller.js"]:::business
        end
        subgraph "Models"
            direction TB
            Models["*Model.js"]:::data
        end
    end

    %% Data Layer
    Database["MongoDB Atlas"]:::data

    %% External Services
    subgraph "External Services"
        direction TB
        CarbonAPI["Carbon Calculator API"]:::ext
        ChatbotAPI["Chatbot Service API"]:::ext
    end

    %% Flows
    ClientEntry --> MainApp
    MainApp --> Compare
    MainApp --> Calculator
    MainApp --> Wallet
    MainApp --> Profile
    MainApp --> Contribute
    MainApp --> Navbar
    MainApp --> Footer
    MainApp --> MainLayout
    MainApp --> AuthContext
    MainApp --> AuthAPI
    MainApp --> EcoCoinService
    MainApp --> ChatService
    MainApp --> LeafToken

    MainApp -->|REST API calls| ServerEntry
    AuthAPI -->|auth requests| ServerEntry
    EcoCoinService -->|eco transactions| ServerEntry
    ChatService -->|chat messages| ChatbotAPI
    Calculator -->|GET estimates| CarbonAPI
    Calculator -->|fallback local| Calculator

    ServerEntry --> AuthMiddleware
    AuthMiddleware --> AuthRoutes
    AuthRoutes --> Controllers
    CarbonRoutes --> Controllers
    CertRoutes --> Controllers
    ReviewRoutes --> Controllers
    RewardsRoutes --> Controllers
    UserRoutes --> Controllers

    Controllers --> Models
    Models --> Database

    %% Click Events
    click ClientEntry "https://github.com/tusharkkp/ecotravel/blob/main/client/src/index.js"
    click MainApp "https://github.com/tusharkkp/ecotravel/blob/main/client/src/App.js"
    click Compare "https://github.com/tusharkkp/ecotravel/blob/main/client/src/pages/CompareOptions.jsx"
    click Calculator "https://github.com/tusharkkp/ecotravel/blob/main/client/src/pages/CarbonCalculator.js"
    click Wallet "https://github.com/tusharkkp/ecotravel/blob/main/client/src/pages/WalletPage.jsx"
    click Profile "https://github.com/tusharkkp/ecotravel/blob/main/client/src/pages/ProfilePage.jsx"
    click Contribute "https://github.com/tusharkkp/ecotravel/blob/main/client/src/pages/ContributePage.jsx"
    click Navbar "https://github.com/tusharkkp/ecotravel/blob/main/client/src/components/layout/Navbar.jsx"
    click Footer "https://github.com/tusharkkp/ecotravel/blob/main/client/src/components/layout/Footer.jsx"
    click MainLayout "https://github.com/tusharkkp/ecotravel/blob/main/client/src/components/layouts/MainLayout.js"
    click AuthContext "https://github.com/tusharkkp/ecotravel/blob/main/client/src/context/AuthContext.js"
    click AuthAPI "https://github.com/tusharkkp/ecotravel/blob/main/client/src/api/auth.js"
    click EcoCoinService "https://github.com/tusharkkp/ecotravel/blob/main/client/src/services/EcoCoinService.js"
    click ChatService "https://github.com/tusharkkp/ecotravel/blob/main/client/src/services/chatbotService.js"
    click LeafToken "https://github.com/tusharkkp/ecotravel/blob/main/client/src/services/LeafTokenService.js"
    click ServerEntry "https://github.com/tusharkkp/ecotravel/blob/main/server/server.js"
    click AuthMiddleware "https://github.com/tusharkkp/ecotravel/blob/main/server/middleware/authMiddleware.js"
    click AuthRoutes "https://github.com/tusharkkp/ecotravel/blob/main/server/routes/authRoutes.js"
    click CarbonRoutes "https://github.com/tusharkkp/ecotravel/blob/main/server/routes/carbonCalculatorRoutes.js"
    click CertRoutes "https://github.com/tusharkkp/ecotravel/blob/main/server/routes/certificationRoutes.js"
    click ReviewRoutes "https://github.com/tusharkkp/ecotravel/blob/main/server/routes/reviewRoutes.js"
    click RewardsRoutes "https://github.com/tusharkkp/ecotravel/blob/main/server/routes/rewardsRoutes.js"
    click UserRoutes "https://github.com/tusharkkp/ecotravel/blob/main/server/routes/userRoutes.js"

    %% Styles
    classDef frontend fill:#D0E7FF,stroke:#0366d6,stroke-width:1px
    classDef business fill:#D6F5D6,stroke:#228B22,stroke-width:1px
    classDef data fill:#FFE4B5,stroke:#DAA520,stroke-width:1px
    classDef ext fill:#E0E0E0,stroke:#808080,stroke-width:1px
```
