# oronsch/tour-advisor architecture

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

- Interactive diagram: https://gitdiagram.com/oronsch/tour-advisor
- Repository: https://github.com/oronsch/tour-advisor

## Overview

##### Main Components

A. Frontend Layer (Client):
- React Application Structure
- Components Module
- Pages Module
- Redux Store
- API Service Layer
- Utility & Validators

B. Backend Layer (Server):
- Express.js Server
- Controllers
- Routes
- Middleware
- Models

C. Database:
- MongoDB

**[Client Tier] <-> [Server Tier] <-> [Data Tier]**

##### Detailed Component Breakdown

Client Tier (Top Section):
- React Components
- Core Components (Header, Footer, etc.)
- Feature Components (CardTour, RelatedTour)
- Auth Components (PrivateRoute, LoadingToRedirect)

- Redux Store
- Auth Slice
- Tour Slice
- API Service

- Pages
- Public (Home, Login, Register)
- Protected (Dashboard, AddEditTour)

Server Tier (Middle Section):
- Express Server
- Auth Middleware
- Routes
- User Routes
- Tour Routes
- Controllers
- User Controller
- Tour Controller

Data Tier (Bottom Section):
- MongoDB
- User Model
- Tour Model

##### Key Elements to Highlight

A. Authentication Flow:
- JWT token flow between client and server
- Protected routes and public routes

B. Data Flow:
- API calls between frontend and backend
- Database operations
- Redux state management flow

##### Important Relationships

- Redux store interaction with React components
- API service layer communication with backend
- Controller interaction with database models
- Authentication middleware protection flow

- Use rectangles for components
- Use diamonds for decision points

## Diagram (Mermaid)

```mermaid
graph TB
    subgraph Client
        direction TB
        
        subgraph Components
            direction TB
            Core["Core Components"]
            Feature["Feature Components"]
            Auth["Auth Components"]
        end

        subgraph State
            direction TB
            Redux["Redux Store"]
            AuthSlice["Auth Slice"]
            TourSlice["Tour Slice"]
            API["API Service"]
        end

        subgraph Pages
            direction TB
            Public["Public Pages"]
            Protected["Protected Pages"]
            Validators["Form Validators"]
        end

        Redux --> AuthSlice & TourSlice
        AuthSlice & TourSlice --> API
        API --> Components
        Components --> Pages
        Validators --> Pages
    end

    subgraph Server
        direction TB
        Express["Express Server"]
        
        subgraph ServerModules
            direction TB
            AuthMW["Auth Middleware"]
            Routes["Routes"]
            Controllers["Controllers"]
        end

        Express --> AuthMW
        AuthMW --> Routes
        Routes --> Controllers
    end

    subgraph Database
        direction TB
        MongoDB[(MongoDB)]
        UserModel["User Model"]
        TourModel["Tour Model"]
        
        MongoDB --> UserModel & TourModel
    end

    API --> Express
    Controllers --> MongoDB

    %% Click events for component mapping
    click Core "https://github.com/oronsch/tour-advisor/blob/main/client/src/components/{Header.jsx,Footer.jsx}"
    click Feature "https://github.com/oronsch/tour-advisor/blob/main/client/src/components/{CardTour.jsx,RelatedTour.jsx}"
    click Auth "https://github.com/oronsch/tour-advisor/blob/main/client/src/components/{PrivateRoute.jsx,LoadingToRedirect.jsx}"
    click Redux "https://github.com/oronsch/tour-advisor/blob/main/client/src/redux/store.js"
    click AuthSlice "https://github.com/oronsch/tour-advisor/blob/main/client/src/redux/features/authSlice.js"
    click TourSlice "https://github.com/oronsch/tour-advisor/blob/main/client/src/redux/features/tourSlice.js"
    click API "https://github.com/oronsch/tour-advisor/blob/main/client/src/redux/api.js"
    click Public "https://github.com/oronsch/tour-advisor/blob/main/client/src/pages/{Home.jsx,Login.jsx,Register.jsx}"
    click Protected "https://github.com/oronsch/tour-advisor/blob/main/client/src/pages/{Dashboard.jsx,AddEditTour.jsx}"
    click Validators "https://github.com/oronsch/tour-advisor/blob/main/client/src/validators/formValidations.js"
    click Express "https://github.com/oronsch/tour-advisor/blob/main/server/index.js"
    click Controllers "https://github.com/oronsch/tour-advisor/blob/main/server/controllers/{tour.js,user.js}"
    click Routes "https://github.com/oronsch/tour-advisor/blob/main/server/routes/{tour.js,user.js}"
    click AuthMW "https://github.com/oronsch/tour-advisor/blob/main/server/middleware/auth.js"
    click UserModel "https://github.com/oronsch/tour-advisor/blob/main/server/models/user.js"
    click TourModel "https://github.com/oronsch/tour-advisor/blob/main/server/models/tour.js"

    %% Styling
    classDef frontend fill:#2374ab
    classDef backend fill:#2a9d8f
    classDef database fill:#e9c46a
    classDef auth fill:#e76f51

    class Core,Feature,Auth,Redux,AuthSlice,TourSlice,API,Public,Protected,Validators frontend
    class Express,AuthMW,Routes,Controllers backend
    class MongoDB,UserModel,TourModel database
    class AuthMW,Auth auth
```
