# aas-chinmaya/whatsflow-tenant-client architecture

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

- Interactive diagram: https://gitdiagram.com/aas-chinmaya/whatsflow-tenant-client
- Repository: https://github.com/aas-chinmaya/whatsflow-tenant-client

## Overview

##### Main Components
- Client Application (Next.js Frontend)
- Public Module: Representing pages and layout starting from src/app/(public)/page.js and layout.js.
- Protected Module: Representing secured pages such as dashboard, agents, campaigns, customers, etc. These pages might rely on middleware (src/middlewares/authMiddleware.js) to enforce authentication rules.
- Layout & UI Components:
- Layout components (AdminLayout, Sidebar, TopNavbar in src/components/layouts) indicate the primary structure of the application.
- UI components like Button, Card, and Input (in src/components/ui) form the building blocks of the user interface.
- Container components (within src/components/containers) organize different domains (agents, billing, customer, subscription, etc.) by wrapping and composing UI components.
- State Management:
- Redux store configuration (found in src/store, including provider and slices like authSlice.js and notificationSlice.js) which is key for maintaining application state and handling data flow.
- API Services:
- The services layer (e.g., src/services/api.js) abstracts calls to external APIs or back-end services.

##### Relationships & Data Flow
- Use of middleware for authentication that intercepts requests to protected routes.
- Flow from UI components (rendered on pages) to container components that mediate business logic and then interact with the Redux store. From the store, actions are dispatched that eventually call the API services for backend communication.
- Integration points where API responses update the Redux store, which in turn updates the UI components.

##### Architectural Patterns & Design Principles
- File-Based Routing: Emphasize the Next.js approach where the folder structure (including designated folders for public and protected content) determines route paths.
- Container and Presentation Pattern: Note the separation between container components (handling complex state logic) and presentational/UI components (handling visual elements).
- State Management: Showcase the use of Redux (separate slices and a centralized store) to support application-wide state updates.

##### Technologies & Libraries
- Next.js: For server-side rendering and routing.
- React: As the base framework for building components.
- Redux: For state management, with defined slices for authentication and notifications.
- Additional Tools: ESLint (eslint.config.mjs), CSS and PostCSS (src/app/globals.css, postcss.config.mjs) for styling, and Next.js configurations.

## Diagram (Mermaid)

```mermaid
flowchart TD
    %% User Interaction
    U["User"]:::user

    %% Routing Layer
    subgraph "Routing"
        subgraph "Public Module"
            P1["Page"]:::public
            P2["Layout"]:::public
        end
        subgraph "Protected Module"
            Prot["Secured Pages"]:::protected
        end
    end

    %% Authentication Middleware
    AM["Auth Middleware"]:::middleware

    %% Presentation Layer - Layout Components
    subgraph "Layout Components"
        AL["Admin Layout"]:::layout
        SB["Sidebar"]:::layout
        TN["Top Navbar"]:::layout
    end

    %% Presentation Layer - UI Components
    subgraph "UI Components"
        BT["Button"]:::ui
        CR["Card"]:::ui
        IN["Input"]:::ui
    end

    %% Container Components
    subgraph "Container Components"
        DC["Dashboard Container"]:::container
        AC["Agents Container"]:::container
        CC["Campaign Container"]:::container
        CUST["Customer Container"]:::container
        BC["Billing Container"]:::container
        SC["Subscription Container"]:::container
        TC["Template Container"]:::container
        AFC["Auth Form Container"]:::container
        OC["APIConfigContainer"]:::container
        HC["HomeContainer"]:::container
        PSC["profileSettingsContainer"]:::container
    end

    %% State Management
    subgraph "State Management"
        Store["Redux Store"]:::state
        AS["Auth Slice"]:::state
        NS["Notification Slice"]:::state
    end

    %% API Service Layer
    API["API Service"]:::service

    %% Connections
    U -->|"accesses"| P1
    U -->|"accesses"| P2
    U -->|"navigates to"| Prot

    %% Public Module flows into Protected Module (e.g., login leads to secure pages)
    P1 -->|"triggers auth"| AFC
    AFC -->|"dispatches"| Store

    %% Protected Module Protected by Middleware
    Prot -->|"guarded by"| AM
    AM -->|"grants access to"| AL
    AM -->|"grants access to"| SB
    AM -->|"grants access to"| TN

    %% Layout Components provide structure to Container Components
    AL --> DC
    AL --> AC
    AL --> CC
    AL --> CUST
    AL --> BC
    AL --> SC
    AL --> TC
    AL --> PSC
    SB --> DC
    TN --> AFC

    %% Container Components use UI Components for presentation
    DC --> BT
    DC --> CR
    AC --> IN
    CC --> BT
    CUST --> CR
    BC --> IN
    SC --> BT
    TC --> CR
    AFC --> IN
    OC --> BT
    HC --> CR
    PSC --> IN

    %% Container Components dispatch actions to State Management
    DC -->|"dispatches"| Store
    AC -->|"dispatches"| Store
    CC -->|"dispatches"| Store
    CUST -->|"dispatches"| Store
    BC -->|"dispatches"| Store
    SC -->|"dispatches"| Store
    TC -->|"dispatches"| Store
    AFC -->|"dispatches"| Store
    OC -->|"dispatches"| Store
    HC -->|"dispatches"| Store
    PSC -->|"dispatches"| Store

    %% State Management integration
    Store -->|"calls/update"| API
    API -->|"updates"| Store
    Store --> AS
    Store --> NS

    %% Click Events for component mapping
    click P1 "https://github.com/aas-chinmaya/whatsflow-tenant-client/blob/main/src/app/(public)/page.js"
    click P2 "https://github.com/aas-chinmaya/whatsflow-tenant-client/blob/main/src/app/(public)/layout.js"
    click Prot "https://github.com/aas-chinmaya/whatsflow-tenant-client/tree/main/src/app/(protected)"
    click AM "https://github.com/aas-chinmaya/whatsflow-tenant-client/blob/main/src/middlewares/authMiddleware.js"
    click AL "https://github.com/aas-chinmaya/whatsflow-tenant-client/blob/main/src/components/layouts/AdminLayout.js"
    click SB "https://github.com/aas-chinmaya/whatsflow-tenant-client/blob/main/src/components/layouts/Sidebar.js"
    click TN "https://github.com/aas-chinmaya/whatsflow-tenant-client/blob/main/src/components/layouts/TopNavbar.js"
    click BT "https://github.com/aas-chinmaya/whatsflow-tenant-client/blob/main/src/components/ui/Button.js"
    click CR "https://github.com/aas-chinmaya/whatsflow-tenant-client/blob/main/src/components/ui/Card.js"
    click IN "https://github.com/aas-chinmaya/whatsflow-tenant-client/blob/main/src/components/ui/Input.js"
    click DC "https://github.com/aas-chinmaya/whatsflow-tenant-client/blob/main/src/components/containers/DashboardContainer.js"
    click AC "https://github.com/aas-chinmaya/whatsflow-tenant-client/blob/main/src/components/containers/AgentsContainer.js"
    click CC "https://github.com/aas-chinmaya/whatsflow-tenant-client/blob/main/src/components/containers/CampaignContainer.js"
    click CUST "https://github.com/aas-chinmaya/whatsflow-tenant-client/blob/main/src/components/containers/CustomerContainer.js"
    click BC "https://github.com/aas-chinmaya/whatsflow-tenant-client/blob/main/src/components/containers/BillingContainer.js"
    click SC "https://github.com/aas-chinmaya/whatsflow-tenant-client/blob/main/src/components/containers/SubscriptionContainer.js"
    click TC "https://github.com/aas-chinmaya/whatsflow-tenant-client/blob/main/src/components/containers/TemplateContainer.js"
    click AFC "https://github.com/aas-chinmaya/whatsflow-tenant-client/blob/main/src/components/containers/AuthFormContainer.js"
    click OC "https://github.com/aas-chinmaya/whatsflow-tenant-client/blob/main/src/components/containers/APIConfigContainer.js"
    click HC "https://github.com/aas-chinmaya/whatsflow-tenant-client/blob/main/src/components/containers/HomeContainer.js"
    click PSC "https://github.com/aas-chinmaya/whatsflow-tenant-client/blob/main/src/components/containers/profileSettingsContainer.js"
    click Store "https://github.com/aas-chinmaya/whatsflow-tenant-client/blob/main/src/store/store.js"
    click AS "https://github.com/aas-chinmaya/whatsflow-tenant-client/blob/main/src/store/features/authSlice.js"
    click NS "https://github.com/aas-chinmaya/whatsflow-tenant-client/blob/main/src/store/features/notificationSlice.js"
    click API "https://github.com/aas-chinmaya/whatsflow-tenant-client/blob/main/src/services/api.js"

    %% Styles
    classDef user fill:#f4d03f,stroke:#d4ac0d,stroke-width:2px;
    classDef public fill:#aed6f1,stroke:#3498db,stroke-width:2px;
    classDef protected fill:#abebc6,stroke:#27ae60,stroke-width:2px;
    classDef middleware fill:#f9e79f,stroke:#f1c40f,stroke-width:2px;
    classDef layout fill:#f5cba7,stroke:#e67e22,stroke-width:2px;
    classDef ui fill:#d2b4de,stroke:#8e44ad,stroke-width:2px;
    classDef container fill:#fcf3cf,stroke:#f39c12,stroke-width:2px;
    classDef state fill:#d5f5e3,stroke:#28b463,stroke-width:2px;
    classDef service fill:#fadbd8,stroke:#e74c3c,stroke-width:2px;
```
