# monishatbaishnab/trektales-client architecture

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

- Interactive diagram: https://gitdiagram.com/monishatbaishnab/trektales-client
- Repository: https://github.com/monishatbaishnab/trektales-client

## Overview

##### Main System Components

a) Client Layer:
- Next.js Frontend (src/app directory structure)
- Public Routes ((root) group)
- Protected Routes (dashboard, user-profile)
- Authentication Routes ((auth) group)

b) Server Layer:
- Express.js Backend (referenced in README)
- REST API Endpoints
- JWT Authentication Service

c) External Services:
- Cloudinary (image storage)
- Aamarpay Payment Gateway
- MongoDB Database

##### Component Organization

a) Frontend Architecture:
- Route groups:
- Public Routes (home, blogs, authors)
- Auth Routes (login, register)
- Protected Routes (dashboard, user-profile)
- User Dashboard
- Admin Dashboard

b) Core Services (src/services):
- Auth Service
- Post Service
- Comment Service
- User Service

c) State Management:
- Context Providers (UserInfoProvider, FilterProvider)
- TanStack Query Integration

##### Data Flow Representation

- Client-Server Communication (via Axios)
- Authentication Flow
- Image Upload Flow to Cloudinary
- Payment Processing Flow

##### Specific Implementation Details

Specialized components:
- Form Components (src/components/form)
- UI Components (src/components/ui)
- Module Components (src/components/modules)

- Client Layer       |
- [Next.js Frontend]    |
- Public Routes     |
- Protected Routes  |
- Admin Dashboard   |

- ↕

- Service Layer       |
- [Express Backend]     |
- API Endpoints     |
- Auth Service      |

- ↕

- External Services    |
- MongoDB             |
- Cloudinary          |
- Aamarpay            |

##### Important Details

- Authentication flow with JWT
- Role-based access control (Admin vs Regular users)
- Premium content access flow
- Image upload and storage process
- Payment processing flow
- Data caching strategy with TanStack Query

## Diagram (Mermaid)

```mermaid
flowchart TB
    subgraph Client
        FE[Next.js Frontend]
        
        subgraph Routes
            PR["Public Routes"]:::routes
            AR["Auth Routes"]:::routes
            DR["Protected Routes"]:::routes
        end
        
        subgraph Components
            UI["UI Components"]:::component
            Forms["Form Components"]:::component
            Modules["Module Components"]:::component
            Nav["Navigation"]:::component
        end
        
        subgraph State
            CP["Context Providers"]:::state
            TQ["TanStack Query"]:::state
        end
        
        subgraph Features
            BD["Blog Details"]:::feature
            CS["Comment System"]:::feature
            UP["User Profile"]:::feature
        end
    end
    
    subgraph Server
        BE[Express Backend]
        
        subgraph Services
            AS["Auth Service"]:::service
            PS["Post Service"]:::service
            CS2["Comment Service"]:::service
            US["User Service"]:::service
        end
        
        subgraph Hooks
            AH["Auth Hooks"]:::hook
            PH["Post Hooks"]:::hook
            CH["Comment Hooks"]:::hook
            UH["User Hooks"]:::hook
        end
    end
    
    subgraph External
        DB[(MongoDB)]:::external
        CL["Cloudinary"]:::external
        AP["Aamarpay"]:::external
    end
    
    %% Relationships
    FE --> BE
    BE --> External
    Routes --> Components
    Components --> State
    State --> Services
    Services --> Hooks
    Hooks --> External
    
    %% Click Events
    click PR "https://github.com/monishatBaishnab/TrekTales-Client/tree/main/src/app/(root)"
    click AR "https://github.com/monishatBaishnab/TrekTales-Client/tree/main/src/app/(auth)"
    click DR "https://github.com/monishatBaishnab/TrekTales-Client/tree/main/src/app/dashboard"
    click UI "https://github.com/monishatBaishnab/TrekTales-Client/tree/main/src/components/ui"
    click Forms "https://github.com/monishatBaishnab/TrekTales-Client/tree/main/src/components/form"
    click Modules "https://github.com/monishatBaishnab/TrekTales-Client/tree/main/src/components/modules"
    click Nav "https://github.com/monishatBaishnab/TrekTales-Client/tree/main/src/components/modules/navbar"
    click CP "https://github.com/monishatBaishnab/TrekTales-Client/tree/main/src/context"
    click AS "https://github.com/monishatBaishnab/TrekTales-Client/tree/main/src/services/auth"
    click PS "https://github.com/monishatBaishnab/TrekTales-Client/tree/main/src/services/post"
    click CS2 "https://github.com/monishatBaishnab/TrekTales-Client/tree/main/src/services/comment"
    click US "https://github.com/monishatBaishnab/TrekTales-Client/tree/main/src/services/user"
    click AH "https://github.com/monishatBaishnab/TrekTales-Client/blob/main/src/hooks/auth.hooks.tsx"
    click PH "https://github.com/monishatBaishnab/TrekTales-Client/blob/main/src/hooks/post.hooks.tsx"
    click CH "https://github.com/monishatBaishnab/TrekTales-Client/blob/main/src/hooks/comment.hooks.tsx"
    click UH "https://github.com/monishatBaishnab/TrekTales-Client/blob/main/src/hooks/user.hooks.tsx"
    click BD "https://github.com/monishatBaishnab/TrekTales-Client/tree/main/src/app/(root)/blogs/[blogId]"
    click CS "https://github.com/monishatBaishnab/TrekTales-Client/blob/main/src/app/(root)/blogs/[blogId]/_components/Comments.tsx"
    click UP "https://github.com/monishatBaishnab/TrekTales-Client/tree/main/src/app/(root)/user-profile"
    
    %% Styles
    classDef routes fill:#6495ED
    classDef component fill:#98FB98
    classDef state fill:#DDA0DD
    classDef service fill:#F0E68C
    classDef hook fill:#FFA07A
    classDef external fill:#B8860B
    classDef feature fill:#20B2AA
```
