# kea-renov8/befly-fe architecture

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

- Interactive diagram: https://gitdiagram.com/kea-renov8/befly-fe
- Repository: https://github.com/kea-renov8/befly-fe

## Overview

##### Project type and purpose
- This is a front-end web application (ReNov8-FE) built with React and Vite.
- It provides a multi-page user interface: login/signup, home, chat, posts, profile, error handling.
- It uses React Router for navigation, React Query for data fetching, and a theme provider for styling. Storybook is included for isolated component development.

##### File structure
- Top-level tooling/config:
- vite.config.js, package.json, tsconfig/jsconfig, eslint.config.js, .prettierrc, .github/workflows.
- index.html (app shell) in the public folder.
- Source code (`src`):
- src/main.jsx: application entrypoint that mounts `<App />`.
- src/app: core of the application.
– App.jsx/App.css: root component and global styles.
– providers/: context providers (router, theme, query).
– layout/: page wrappers (RootLayout).
– routes/: route definitions and protected routes.
– styles/: design tokens and global-style.
- src/pages: feature folders (chat, home, login, post, profile, report, my, error). Each contains UI components, hooks (query/mutate), stores, and styles.
- src/shared: reusable assets, hooks, stores, components, utilities, plus Storybook stories in `.storybook` and `src/shared/stories` for isolated component development.
- No backend code here; this is purely a client that communicates with external APIs.

##### Extract insights from README
- Stacks: Git, Notion; implicit tech stack: React, Vite, React Router, React Query, Storybook.

a. Main components
- Build & Dev Environment: Vite (Dev Server, HMR, Production Build)
- Browser (Client)
- React Application
– Entry Point (main.jsx)
– App Component
– Context Providers (Router, Query, Theme)
– Routing Layer (React Router)
– Feature Modules (pages/*)
· UI Components
· Business Logic Hooks (useQuery/useMutation)
· Local Stores (zustand or context)
– Shared Components & Utilities
– Style System (global-style, design tokens)
– Storybook (isolated component dev)
- External Services (REST or GraphQL API endpoints)
- Static Assets (public folder)

b. Relationships & interactions
- Vite bundles sources → serves to Browser
- Browser loads index.html → initializes React via main.jsx
- App component wraps children in Providers → provides routing, theming, data-fetching contexts
- React Router resolves URL → renders specific Page module
- Page modules invoke hooks (React Query) to fetch/update data from External API
- Local Stores hold transient UI state
- Shared components imported by pages for consistency
- Storybook reads components in isolation (no API)

c. Architectural patterns/design principles
- Component-based UI (React)
- Context/API-driven state management (React Query, custom Providers)
- Domain-driven folder structure (group by feature/page)
- Single Page Application with client-side routing
- Separation of concerns: UI, styles, data fetching, routing
- Reusability via shared modules and Storybook

d. Key technologies/frameworks
- Vite (build & dev server)
- React 18
- React Router v6
- React Query
- Storybook
- CSS modules / styled components pattern via global-style and tokens

## Diagram (Mermaid)

```mermaid
flowchart TD
    %% Tools Layer
    subgraph "Tooling" 
        direction TB
        Vite["Vite Dev Server & Bundler"]:::tools
        Storybook["Storybook"]:::tools
        PublicAssets["Public Folder"]:::tools
    end

    Vite -->|"serves bundle & HMR"| Browser
    Storybook -->|"isolated component dev"| SharedComponents
    PublicAssets -->|"static assets (index.html, images)"| Browser

    click Vite "https://github.com/kea-renov8/befly-fe/blob/develop/vite.config.js"
    click Storybook "https://github.com/kea-renov8/befly-fe/blob/develop/.storybook/main.js"
    click Storybook "https://github.com/kea-renov8/befly-fe/blob/develop/.storybook/preview.js"
    click Storybook "https://github.com/kea-renov8/befly-fe/blob/develop/.storybook/vitest.setup.js"
    click PublicAssets "https://github.com/kea-renov8/befly-fe/tree/develop/public/"

    %% Runtime Layer
    Browser["Browser / Client"]:::runtime
    Browser -->|"load index.html & init React"| Entry

    subgraph "React Application" 
        direction TB

        Entry["Entry Point<br>src/main.jsx"]:::runtime
        click Entry "https://github.com/kea-renov8/befly-fe/blob/develop/src/main.jsx"
        Entry --> AppComponent

        AppComponent["App Component<br>src/app/App.jsx"]:::runtime
        click AppComponent "https://github.com/kea-renov8/befly-fe/blob/develop/src/app/App.jsx"
        AppComponent --> AppCSS

        AppCSS["Global Styles<br>src/app/App.css"]:::runtime
        click AppCSS "https://github.com/kea-renov8/befly-fe/blob/develop/src/app/App.css"
        AppComponent --> Providers

        subgraph "Providers" 
            direction TB
            RouterProv["Router Provider"]:::runtime
            click RouterProv "https://github.com/kea-renov8/befly-fe/blob/develop/src/app/providers/AppRouterProvider.jsx"
            ThemeProv["Theme Provider"]:::runtime
            click ThemeProv "https://github.com/kea-renov8/befly-fe/blob/develop/src/app/providers/AppThemeProvider.jsx"
            QueryProv["React Query Provider"]:::runtime
            click QueryProv "https://github.com/kea-renov8/befly-fe/blob/develop/src/app/providers/QueryProvider.jsx"
            ProvidersIndex["Providers Index"]:::runtime
            click ProvidersIndex "https://github.com/kea-renov8/befly-fe/blob/develop/src/app/providers/index.js"
        end
        Providers --> RouterProv --> ThemeProv --> QueryProv --> Routing

        subgraph "Routing Layer" 
            direction TB
            MainRouter["Main Router"]:::runtime
            click MainRouter "https://github.com/kea-renov8/befly-fe/blob/develop/src/app/routes/router.jsx"
            ProtectedRouter["Protected Router"]:::runtime
            click ProtectedRouter "https://github.com/kea-renov8/befly-fe/blob/develop/src/app/routes/ProtectedRouter.jsx"
            RoutesIndex["Routes Index"]:::runtime
            click RoutesIndex "https://github.com/kea-renov8/befly-fe/blob/develop/src/app/routes/index.js"
        end
        QueryProv --> MainRouter --> ProtectedRouter --> RoutesIndex --> Pages

        subgraph "Style System" 
            direction TB
            Colors["Colors Token<br>src/app/styles/colors.js"]:::runtime
            click Colors "https://github.com/kea-renov8/befly-fe/blob/develop/src/app/styles/colors.js"
            Fonts["Fonts Token<br>src/app/styles/fonts.js"]:::runtime
            click Fonts "https://github.com/kea-renov8/befly-fe/blob/develop/src/app/styles/fonts.js"
            ThemeTokens["Theme Tokens<br>src/app/styles/theme.js"]:::runtime
            click ThemeTokens "https://github.com/kea-renov8/befly-fe/blob/develop/src/app/styles/theme.js"
            GlobalStyle["Global Style<br>src/app/styles/global-style.js"]:::runtime
            click GlobalStyle "https://github.com/kea-renov8/befly-fe/blob/develop/src/app/styles/global-style.js"
            StylesIndex["Styles Index<br>src/app/styles/index.js"]:::runtime
            click StylesIndex "https://github.com/kea-renov8/befly-fe/blob/develop/src/app/styles/index.js"
        end
        ThemeProv --> StyleSystem
    end

    %% Features Layer
    subgraph "Feature Modules" 
        direction TB
        Chat["Chat Module<br>src/pages/chat/"]:::feature
        click Chat "https://github.com/kea-renov8/befly-fe/tree/develop/src/pages/chat/"
        Home["Home Module<br>src/pages/home/"]:::feature
        click Home "https://github.com/kea-renov8/befly-fe/tree/develop/src/pages/home/"
        Login["Login Module<br>src/pages/login/"]:::feature
        click Login "https://github.com/kea-renov8/befly-fe/tree/develop/src/pages/login/"
        Post["Posts Module<br>src/pages/post/"]:::feature
        click Post "https://github.com/kea-renov8/befly-fe/tree/develop/src/pages/post/"
        Profile["Profile Module<br>src/pages/profile/"]:::feature
        click Profile "https://github.com/kea-renov8/befly-fe/tree/develop/src/pages/profile/"
        My["My Module<br>src/pages/my/"]:::feature
        click My "https://github.com/kea-renov8/befly-fe/tree/develop/src/pages/my/"
        Report["Report Module<br>src/pages/report/"]:::feature
        click Report "https://github.com/kea-renov8/befly-fe/tree/develop/src/pages/report/"
        ErrorPage["Error Page<br>src/pages/error/ErrorPage.jsx"]:::feature
        click ErrorPage "https://github.com/kea-renov8/befly-fe/blob/develop/src/pages/error/ErrorPage.jsx"
    end

    Pages["Pages Container"]:::runtime
    Pages --> Chat
    Pages --> Home
    Pages --> Login
    Pages --> Post
    Pages --> Profile
    Pages --> My
    Pages --> Report
    Pages --> ErrorPage

    Pages -->|"useReactQuery hooks"| ExternalAPI
    Pages -->|"import shared components/utilities"| SharedComponents

    %% Shared Modules
    subgraph "Shared Modules" 
        direction TB
        SharedComponents["UI Components"]:::shared
        click SharedComponents "https://github.com/kea-renov8/befly-fe/tree/develop/src/shared/ui/"
        SharedStories["Stories"]:::shared
        click SharedStories "https://github.com/kea-renov8/befly-fe/tree/develop/src/shared/stories/"
        SharedHooks["Hooks"]:::shared
        click SharedHooks "https://github.com/kea-renov8/befly-fe/tree/develop/src/shared/hooks/"
        SharedStore["Store"]:::shared
        click SharedStore "https://github.com/kea-renov8/befly-fe/tree/develop/src/shared/store/"
        SharedUtils["Utilities"]:::shared
        click SharedUtils "https://github.com/kea-renov8/befly-fe/tree/develop/src/shared/utils/"
        SharedAssets["Assets"]:::shared
        click SharedAssets "https://github.com/kea-renov8/befly-fe/tree/develop/src/shared/assets/"
    end

    %% External
    ExternalAPI["External API Endpoints"]:::external

    %% Styles
    classDef tools fill:#d3d3d3,stroke:#333,stroke-width:1px
    classDef runtime fill:#add8e6,stroke:#333,stroke-width:1px
    classDef feature fill:#90ee90,stroke:#333,stroke-width:1px
    classDef shared fill:#dda0dd,stroke:#333,stroke-width:1px
    classDef external fill:#ffcc99,stroke:#333,stroke-width:1px
```
