# shalabhgupta-aviz/community-site architecture

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

- Interactive diagram: https://gitdiagram.com/shalabhgupta-aviz/community-site
- Repository: https://github.com/shalabhgupta-aviz/community-site

## Overview

##### Project type and purpose
- This is a full-stack Next.js web application serving as a forum/discussion platform: users can register, log in, post questions, reply to questions, browse topics, and view their profile.

##### File structure
- Top-level Next.js config files: next.config.mjs, jsconfig.json, postcss.config.mjs, eslint.config.mjs.
- `/src/app`: Next.js “app router” folder containing route handlers (frontend pages) and API routes under `/api`.
- `/api/auth/[...nextauth]/route.js`: NextAuth authentication.
- `/api/login`, `/api/logout`, `/api/me`: custom REST endpoints.
- `/src/components`: React UI components (forms, cards, provider wrappers).
- `/src/lib`: data-access abstractions (fetching questions, replies, topics, authentication helpers).
- `/src/middleware`: custom Next.js middleware for logging.
- `/src/store`: Redux Toolkit slices and RTK Query setup for state & API integration (`wpApi.js` to call external WordPress API).
- `/src/plugins`: UI plugins (rich text editor, HTML decoder).
- `/public` & `/styles`: static assets and global CSS.

##### README for additional insights
- Bootstrapped via `create-next-app`.
- Uses Next.js app router, built-in Font optimization.
- Deployable on Vercel.

##### Architectural patterns
- Component-based frontend (React)
- API routes for backend logic in the same codebase (Next.js full-stack pattern)
- State management with Redux Toolkit and RTK Query for caching/fetching
- Middleware layer for cross-cutting concerns (logging)
- Headless CMS integration (WordPress)

##### Be detailed but focused
- Major Next.js app router directories that generate pages.
- Middleware and plugin steps in the server layer.
- Redux store interaction as a side-car to UI layer.
- NextAuth flow separately (login → token/session → protected routes).

## Diagram (Mermaid)

```mermaid
flowchart TB
    %% User Layer
    subgraph "User"
        UserBrowser["End User (Browser/Mobile)"]:::ui
    end

    %% Presentation Layer
    subgraph "Presentation Layer"
        Layout["Layout Component"]:::ui
        ClientProvider["ClientProvider"]:::ui
        Headers["Headers"]:::ui
        PageHome["Home Page"]:::ui
        PageCreateQuestion["Create Question Page"]:::ui
        PageCreateReply["Create Reply Page"]:::ui
        PageLogin["Login Page"]:::ui
        PageMyReplies["My Replies Page"]:::ui
        PageProfile["Profile Page"]:::ui
        PageQuestions["Questions Listing Page"]:::ui
        PageQuestionDetail["Question Detail Page"]:::ui
        PageTopics["Topics Listing Page"]:::ui
        PageTopicDetail["Topic Detail Page"]:::ui
    end

    %% Server Layer
    subgraph "Server Layer"
        AppServer["Next.js App Server"]:::server
        Middleware["Logger Middleware"]:::server
        NextAuthService["NextAuth Service"]:::server
        LoginAPI["Login API Route"]:::server
        LogoutAPI["Logout API Route"]:::server
        MeAPI["Current User API Route"]:::server
    end

    %% State & Data Access Layer
    subgraph "State & Data Access"
        ReduxStore["Redux Store & RTK Query"]:::state
        AuthSlice["Auth Slice"]:::state
        BadgeSlice["Badge Slice"]:::state
        NotificationSlice["Notification Slice"]:::state
        ProfileSlice["Profile Slice"]:::state
        UISlice["UI Slice"]:::state
        WPApi["WordPress CMS API (RTK Query)"]:::state
        AuthLib["Auth Helpers"]:::lib
        QuestionsLib["Questions API Helpers"]:::lib
        RepliesLib["Replies API Helpers"]:::lib
        TopicsLib["Topics API Helpers"]:::lib
        SearchLib["Search Helpers"]:::lib
    end

    %% UI Plugins
    subgraph "UI Plugins"
        RichTextEditor["Rich Text Editor"]:::ui
        HTMLEntDecoder["HTML Entities Decoder"]:::ui
    end

    %% External Services
    subgraph "External Services"
        WordPress["WordPress Headless CMS"]:::external
        AuthProvider["NextAuth Provider / DB"]:::external
    end

    %% Hosting
    subgraph "Hosting"
        Vercel["Vercel Platform"]:::external
    end

    %% Connections
    UserBrowser -->|interacts with| Layout
    Layout --> ClientProvider
    ClientProvider --> Headers
    Headers --> PageHome
    PageHome --> AppServer
    PageCreateQuestion --> AppServer
    PageCreateReply --> AppServer
    PageLogin --> AppServer
    PageMyReplies --> AppServer
    PageProfile --> AppServer
    PageQuestions --> AppServer
    PageQuestionDetail --> AppServer
    PageTopics --> AppServer
    PageTopicDetail --> AppServer

    AppServer --> Middleware
    Middleware --> NextAuthService
    Middleware --> LoginAPI
    Middleware --> LogoutAPI
    Middleware --> MeAPI

    NextAuthService <-->|auth sessions| AuthProvider
    LoginAPI --> AuthLib
    LogoutAPI --> AuthLib
    MeAPI --> AuthLib

    ClientProvider --> ReduxStore
    ReduxStore --> AuthSlice
    ReduxStore --> BadgeSlice
    ReduxStore --> NotificationSlice
    ReduxStore --> ProfileSlice
    ReduxStore --> UISlice
    ReduxStore --> WPApi

    WPApi --> TopicsLib
    WPApi --> QuestionsLib
    WPApi --> RepliesLib
    WPApi --> SearchLib
    WPApi --> AuthLib
    WPApi --> WordPress

    RichTextEditor --> PageCreateQuestion
    RichTextEditor --> PageCreateReply
    HTMLEntDecoder --> PageQuestionDetail
    HTMLEntDecoder --> PageTopicDetail

    AppServer -->|deployed on| Vercel

    %% Click Events
    click NextAuthService "https://github.com/shalabhgupta-aviz/community-site/blob/main/src/app/api/auth/[...nextauth]/route.js"
    click LoginAPI "https://github.com/shalabhgupta-aviz/community-site/blob/main/src/app/api/login/route.js"
    click LogoutAPI "https://github.com/shalabhgupta-aviz/community-site/blob/main/src/app/api/logout/route.js"
    click MeAPI "https://github.com/shalabhgupta-aviz/community-site/blob/main/src/app/api/me/route.js"
    click PageHome "https://github.com/shalabhgupta-aviz/community-site/blob/main/src/app/page.js"
    click PageCreateQuestion "https://github.com/shalabhgupta-aviz/community-site/blob/main/src/app/create-question/page.jsx"
    click PageCreateReply "https://github.com/shalabhgupta-aviz/community-site/blob/main/src/app/create-reply/page.jsx"
    click PageLogin "https://github.com/shalabhgupta-aviz/community-site/blob/main/src/app/login/page.jsx"
    click PageMyReplies "https://github.com/shalabhgupta-aviz/community-site/blob/main/src/app/my-replies/page.jsx"
    click PageProfile "https://github.com/shalabhgupta-aviz/community-site/blob/main/src/app/profile/page.jsx"
    click PageQuestions "https://github.com/shalabhgupta-aviz/community-site/blob/main/src/app/questions/page.jsx"
    click PageQuestionDetail "https://github.com/shalabhgupta-aviz/community-site/blob/main/src/app/questions/[id]/page.jsx"
    click PageTopics "https://github.com/shalabhgupta-aviz/community-site/blob/main/src/app/topics/page.jsx"
    click PageTopicDetail "https://github.com/shalabhgupta-aviz/community-site/blob/main/src/app/topics/[id]/page.jsx"
    click Layout "https://github.com/shalabhgupta-aviz/community-site/blob/main/src/layouts/Layout.jsx"
    click ClientProvider "https://github.com/shalabhgupta-aviz/community-site/blob/main/src/components/ClientProvider.jsx"
    click ForumCard "https://github.com/shalabhgupta-aviz/community-site/blob/main/src/components/ForumCard.jsx"
    click Headers "https://github.com/shalabhgupta-aviz/community-site/blob/main/src/components/Headers.jsx"
    click LoginForm "https://github.com/shalabhgupta-aviz/community-site/blob/main/src/components/LoginForm.jsx"
    click RegisterForm "https://github.com/shalabhgupta-aviz/community-site/blob/main/src/components/RegisterForm.jsx"
    click ReplyCard "https://github.com/shalabhgupta-aviz/community-site/blob/main/src/components/ReplyCard.jsx"
    click TopicCard "https://github.com/shalabhgupta-aviz/community-site/blob/main/src/components/TopicCard.jsx"
    click ProtectedRoute "https://github.com/shalabhgupta-aviz/community-site/blob/main/src/components/ProtectedRoute.jsx"
    click AuthLib "https://github.com/shalabhgupta-aviz/community-site/blob/main/src/lib/auth.js"
    click QuestionsLib "https://github.com/shalabhgupta-aviz/community-site/blob/main/src/lib/questions.js"
    click RepliesLib "https://github.com/shalabhgupta-aviz/community-site/blob/main/src/lib/replies.js"
    click SearchLib "https://github.com/shalabhgupta-aviz/community-site/blob/main/src/lib/search.js"
    click TopicsLib "https://github.com/shalabhgupta-aviz/community-site/blob/main/src/lib/topics.js"
    click Middleware "https://github.com/shalabhgupta-aviz/community-site/blob/main/src/middleware/loggerMiddleware.js"
    click ReduxStore "https://github.com/shalabhgupta-aviz/community-site/blob/main/src/store/index.js"
    click WPApi "https://github.com/shalabhgupta-aviz/community-site/blob/main/src/store/api/wpApi.js"
    click AuthSlice "https://github.com/shalabhgupta-aviz/community-site/blob/main/src/store/slices/authSlice.js"
    click BadgeSlice "https://github.com/shalabhgupta-aviz/community-site/blob/main/src/store/slices/badgeSlice.js"
    click NotificationSlice "https://github.com/shalabhgupta-aviz/community-site/blob/main/src/store/slices/notificationSlice.js"
    click ProfileSlice "https://github.com/shalabhgupta-aviz/community-site/blob/main/src/store/slices/profileSlice.js"
    click UISlice "https://github.com/shalabhgupta-aviz/community-site/blob/main/src/store/slices/uiSlice.js"
    click RichTextEditor "https://github.com/shalabhgupta-aviz/community-site/blob/main/src/plugins/richTextEditor.jsx"
    click HTMLEntDecoder "https://github.com/shalabhgupta-aviz/community-site/blob/main/src/plugins/decodeHTMLentities.js"
    click Vercel "https://github.com/shalabhgupta-aviz/community-site/tree/main/public/"

    %% Styles
    classDef ui fill:#ADD8E6,stroke:#333,stroke-width:1px
    classDef server fill:#8FBC8F,stroke:#333,stroke-width:1px
    classDef state fill:#D8BFD8,stroke:#333,stroke-width:1px
    classDef lib fill:#FFE4B5,stroke:#333,stroke-width:1px
    classDef external fill:#FFA500,stroke:#333,stroke-width:1px
```
