# inbest-inc/inbest-frontend architecture

> Architecture diagram of the GitHub repository inbest-inc/inbest-frontend, 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/inbest-inc/inbest-frontend
- Repository: https://github.com/inbest-inc/inbest-frontend

## Overview

##### Project type and purpose
- This is a Next.js 13 “app”-directory front-end application (“inbest-frontend”) that delivers a stock-portfolio tracking UI, user authentication flows, social features (followers, opinions, posts), and serverless endpoints for generating assets (e.g. logos).
- It is deployed via Cloudflare Pages/Workers (wrangler.toml), uses Tailwind CSS, and stages Vue-style React components for charts, tables, modals, etc.

##### File structure
- Top-level files:
- next.config.mjs, tsconfig.json, tailwind.config.js → Next.js and build configuration
- wrangler.toml → Cloudflare Workers deployment
- src/app/ → Next.js route handlers and UI pages (app-directory routing)
- /api/getLogo/route.ts → serverless API route
- nested dynamic routes ([username], [portfolio], [postId]) for rendering and management pages
- auth flows: login, register, forgot/reset/verify password and verification pages
- src/components/ → reusable UI building blocks (charts, tables, modals, headers, footers, tooltips)
- src/services/ → modules that wrap REST calls to external backend APIs (userService, portfolioService, followService, socialService, fileUploadService)
- src/lib/ and src/utils/ → utility and helper functions (chart utilities, window resize hook, password/quantity/stock helpers)
- src/config/env.ts → environment variable loader

##### README for additional insights
- Basic build and dev instructions (pnpm build, pnpm run dev)
- Key public routes for pages and dynamic user/portfolio URLs
- No direct mention of the external backend, implying the frontend’s services point to a separate API domain

a. Main Components
- Client (Browser)
- Next.js App Server (Serverless runtime on Cloudflare Workers)
– Routing & SSR/SSG using the /src/app directory
– API Routes (getLogo)
- CDN / Static Assets (public folder served via Cloudflare)
- External Backend API Services
– Authentication Service
– Portfolio Management Service
– Social / Follow Service
– File Upload / Media Storage Service
- Database(s) (managed by the backend—user store, portfolio store, posts store)
b. Relationships & Interactions
- Client ↔ Next.js Server via HTTPS for page requests, SSR data fetching, CSR hydration
- Next.js Server ↔ External Backend API via REST calls from src/services
- Next.js Serverless API Route (getLogo) ↔ File Upload / Image-Generation Service or CDN
- Client ↔ CDN for static assets (CSS, JS bundles, images)
c. Architectural Patterns & Principles
- Serverless micro-endpoints for on-demand SSR and asset generation
- “App” directory nested routing pattern for domain-centric URL design
- Separation of concerns:
– UI layer (components)
– Data-access layer (services)
– Configuration & utilities (lib, utils, config)
d. Technologies & Frameworks
- Next.js 13 (app router, React, SSR/SSG)
- Cloudflare Workers (wrangler.toml)
- Tailwind CSS for utility-first styling
- pnpm package manager, TypeScript
- External REST APIs for core business logic & persistence

##### Elements
– Browser → Next.js (page render)
– Next.js → External API (data fetches via services)
– Browser → CDN (static asset fetch)
– Next.js API route → File Upload/Image Service
– Client-side components (Browser, Components library)
– Serverless runtime (Next.js + API routes)
– External services & databases
– Infrastructure (CDN, Cloudflare Workers)

## Diagram (Mermaid)

```mermaid
flowchart TD
    %% Client Layer
    subgraph "Client (Browser)"
        BROWSER["Browser"]:::client
    end

    %% Infrastructure Layer
    subgraph "Infrastructure (Cloudflare)"
        CDN["CDN / Static Assets"]:::infra
        WORKERS["Cloudflare Workers Runtime"]:::infra
    end

    %% Next.js Serverless Runtime
    subgraph "Next.js Serverless Runtime"
        APPROUTER["App Router (src/app)"]:::serverless
        APIR["getLogo API Route"]:::serverless
    end

    %% UI Pages and Routes
    subgraph "UI Pages & Routes"
        LAYOUT["layout.tsx"]:::serverless
        GLOBALS["globals.css"]:::serverless
        PAGE["page.tsx"]:::serverless
        DYN_USER_PAGE["[username]/page.tsx"]:::serverless
        DYN_USER_LAYOUT["[username]/layout.tsx"]:::serverless
        DYN_PORTF_PAGE["[username]/[portfolio]/page.tsx"]:::serverless
        DYN_PORTF_LAYOUT["[username]/[portfolio]/layout.tsx"]:::serverless
        DYN_PORTF_MANAGE_PAGE["[username]/[portfolio]/manage/page.tsx"]:::serverless
        DYN_PORTF_MANAGE_LAYOUT["[username]/[portfolio]/manage/layout.tsx"]:::serverless
        POSTS_LIST["[username]/posts/page.tsx"]:::serverless
        POST_VIEW_PAGE["[username]/posts/[postId]/page.tsx"]:::serverless
        POST_VIEW_LAYOUT["[username]/posts/[postId]/layout.tsx"]:::serverless
        AUTH_LOGIN["login/page.tsx"]:::serverless
        AUTH_REGISTER["register/page.tsx"]:::serverless
        AUTH_FORGOT["forgot-password/page.tsx"]:::serverless
        AUTH_RESET["reset-password/page.tsx"]:::serverless
        AUTH_VERIF_REQ["verification-required/page.tsx"]:::serverless
        AUTH_VERIFY["verify/page.tsx"]:::serverless
        BEST_PORTF["best-portfolios/page.tsx"]:::serverless
        OPINIONS["opinions/page.tsx"]:::serverless
    end

    APPROUTER --> LAYOUT
    APPROUTER --> GLOBALS
    APPROUTER --> PAGE
    APPROUTER --> DYN_USER_PAGE
    APPROUTER --> DYN_USER_LAYOUT
    APPROUTER --> DYN_PORTF_PAGE
    APPROUTER --> DYN_PORTF_LAYOUT
    APPROUTER --> DYN_PORTF_MANAGE_PAGE
    APPROUTER --> DYN_PORTF_MANAGE_LAYOUT
    APPROUTER --> POSTS_LIST
    APPROUTER --> POST_VIEW_PAGE
    APPROUTER --> POST_VIEW_LAYOUT
    APPROUTER --> AUTH_LOGIN
    APPROUTER --> AUTH_REGISTER
    APPROUTER --> AUTH_FORGOT
    APPROUTER --> AUTH_RESET
    APPROUTER --> AUTH_VERIF_REQ
    APPROUTER --> AUTH_VERIFY
    APPROUTER --> BEST_PORTF
    APPROUTER --> OPINIONS

    APIR -->|"REST"| FILEUPLOAD_SERVICE_EXT

    %% Services Layer
    subgraph "Data-Access Services (src/services)"
        USR_SVC["userService.ts"]:::service
        PORTF_SVC["portfolioService.ts"]:::service
        FOLLOW_SVC["followService.ts"]:::service
        SOCIAL_SVC["socialService.ts"]:::service
        FILEUPLOAD_SVC["fileUploadService.ts"]:::service
    end

    %% Utils and Config
    subgraph "Utilities & Config"
        ENV["env.ts"]:::service
        CHART_UTILS["chartUtils.ts"]:::service
        RESIZE_UTILS["useOnWindowResize.ts"]:::service
        UTILS_LIB["utils.ts"]:::service
        PW_UTILS["passwordUtils.ts"]:::service
        QTY_UTILS["quantityUtils.ts"]:::service
        STOCK_UTILS["stockUtils.ts"]:::service
    end

    %% Components Library
    subgraph "UI Components (src/components)"
        CHARTS["Charts"]:::client
        TABLES["Tables"]:::client
        MODALS["Modals"]:::client
        HEADER["Header/Footer"]:::client
        TOOLTIP["Tooltips"]:::client
    end

    %% External Backend Services & DB
    subgraph "External Backend APIs"
        AUTH_EXT["Authentication Service"]:::external
        PORTF_EXT["Portfolio Mgmt Service"]:::external
        SOCIAL_EXT["Social/Follow Service"]:::external
        FILEUPLOAD_SERVICE_EXT["File Upload / Image Service"]:::external
    end

    DB["Databases"]:::database

    %% Relationships
    BROWSER -->|"HTTPS / SSR & CSR"| WORKERS
    BROWSER -->|"Fetch Static Assets"| CDN
    WORKERS -->|"Edge SSR / Serve Static"| CDN
    WORKERS -->|"Invoke App Router"| APPROUTER
    WORKERS -->|"Invoke API Route"| APIR

    APPROUTER -->|"REST API Calls"| USR_SVC
    APPROUTER -->|"REST API Calls"| PORTF_SVC
    APPROUTER -->|"REST API Calls"| FOLLOW_SVC
    APPROUTER -->|"REST API Calls"| SOCIAL_SVC
    APPROUTER -->|"REST API Calls"| FILEUPLOAD_SVC

    USR_SVC -->|"HTTPS REST"| AUTH_EXT
    PORTF_SVC -->|"HTTPS REST"| PORTF_EXT
    SOCIAL_SVC -->|"HTTPS REST"| SOCIAL_EXT
    FILEUPLOAD_SVC -->|"HTTPS REST"| FILEUPLOAD_SERVICE_EXT

    AUTH_EXT --> DB
    PORTF_EXT --> DB
    SOCIAL_EXT --> DB

    %% Click Events
    click LAYOUT "https://github.com/inbest-inc/inbest-frontend/blob/main/src/app/layout.tsx"
    click GLOBALS "https://github.com/inbest-inc/inbest-frontend/blob/main/src/app/globals.css"
    click PAGE "https://github.com/inbest-inc/inbest-frontend/blob/main/src/app/page.tsx"
    click APIR "https://github.com/inbest-inc/inbest-frontend/blob/main/src/app/api/getLogo/route.ts"
    click DYN_USER_PAGE "https://github.com/inbest-inc/inbest-frontend/blob/main/src/app/[username]/page.tsx"
    click DYN_USER_LAYOUT "https://github.com/inbest-inc/inbest-frontend/blob/main/src/app/[username]/layout.tsx"
    click DYN_PORTF_PAGE "https://github.com/inbest-inc/inbest-frontend/blob/main/src/app/[username]/[portfolio]/page.tsx"
    click DYN_PORTF_LAYOUT "https://github.com/inbest-inc/inbest-frontend/blob/main/src/app/[username]/[portfolio]/layout.tsx"
    click DYN_PORTF_MANAGE_PAGE "https://github.com/inbest-inc/inbest-frontend/blob/main/src/app/[username]/[portfolio]/manage/page.tsx"
    click DYN_PORTF_MANAGE_LAYOUT "https://github.com/inbest-inc/inbest-frontend/blob/main/src/app/[username]/[portfolio]/manage/layout.tsx"
    click POSTS_LIST "https://github.com/inbest-inc/inbest-frontend/blob/main/src/app/[username]/posts/page.tsx"
    click POST_VIEW_PAGE "https://github.com/inbest-inc/inbest-frontend/blob/main/src/app/[username]/posts/[postId]/page.tsx"
    click POST_VIEW_LAYOUT "https://github.com/inbest-inc/inbest-frontend/blob/main/src/app/[username]/posts/[postId]/layout.tsx"
    click AUTH_LOGIN "https://github.com/inbest-inc/inbest-frontend/blob/main/src/app/login/page.tsx"
    click AUTH_REGISTER "https://github.com/inbest-inc/inbest-frontend/blob/main/src/app/register/page.tsx"
    click AUTH_FORGOT "https://github.com/inbest-inc/inbest-frontend/blob/main/src/app/forgot-password/page.tsx"
    click AUTH_RESET "https://github.com/inbest-inc/inbest-frontend/blob/main/src/app/reset-password/page.tsx"
    click AUTH_VERIF_REQ "https://github.com/inbest-inc/inbest-frontend/blob/main/src/app/verification-required/page.tsx"
    click AUTH_VERIFY "https://github.com/inbest-inc/inbest-frontend/blob/main/src/app/verify/page.tsx"
    click BEST_PORTF "https://github.com/inbest-inc/inbest-frontend/blob/main/src/app/best-portfolios/page.tsx"
    click OPINIONS "https://github.com/inbest-inc/inbest-frontend/blob/main/src/app/opinions/page.tsx"
    click USR_SVC "https://github.com/inbest-inc/inbest-frontend/blob/main/src/services/userService.ts"
    click PORTF_SVC "https://github.com/inbest-inc/inbest-frontend/blob/main/src/services/portfolioService.ts"
    click FOLLOW_SVC "https://github.com/inbest-inc/inbest-frontend/blob/main/src/services/followService.ts"
    click SOCIAL_SVC "https://github.com/inbest-inc/inbest-frontend/blob/main/src/services/socialService.ts"
    click FILEUPLOAD_SVC "https://github.com/inbest-inc/inbest-frontend/blob/main/src/services/fileUploadService.ts"
    click ENV "https://github.com/inbest-inc/inbest-frontend/blob/main/src/config/env.ts"
    click CHART_UTILS "https://github.com/inbest-inc/inbest-frontend/blob/main/src/lib/chartUtils.ts"
    click RESIZE_UTILS "https://github.com/inbest-inc/inbest-frontend/blob/main/src/lib/useOnWindowResize.ts"
    click UTILS_LIB "https://github.com/inbest-inc/inbest-frontend/blob/main/src/lib/utils.ts"
    click PW_UTILS "https://github.com/inbest-inc/inbest-frontend/blob/main/src/utils/passwordUtils.ts"
    click QTY_UTILS "https://github.com/inbest-inc/inbest-frontend/blob/main/src/utils/quantityUtils.ts"
    click STOCK_UTILS "https://github.com/inbest-inc/inbest-frontend/blob/main/src/utils/stockUtils.ts"
    click CDN "https://github.com/inbest-inc/inbest-frontend/tree/main/public/"
    click CDN "https://github.com/inbest-inc/inbest-frontend/tree/main/public/_redirects"
    click CDN "https://github.com/inbest-inc/inbest-frontend/blob/main/public/manifest.json"
    click WORKERS "https://github.com/inbest-inc/inbest-frontend/blob/main/wrangler.toml"
    click BROWSER "https://github.com/inbest-inc/inbest-frontend/blob/main/next.config.mjs"
    click BROWSER "https://github.com/inbest-inc/inbest-frontend/blob/main/tsconfig.json"
    click BROWSER "https://github.com/inbest-inc/inbest-frontend/blob/main/tailwind.config.js"

    %% Styles
    classDef client fill:#D0E8FF,stroke:#0366D6,stroke-width:1px
    classDef infra fill:#E8F4FD,stroke:#1A73E8,stroke-width:1px
    classDef serverless fill:#FFF5D7,stroke:#F4B400,stroke-width:1px
    classDef service fill:#F0F4C3,stroke:#9E9D24,stroke-width:1px
    classDef external fill:#FFE0E0,stroke:#D32F2F,stroke-width:1px
    classDef database fill:#E8FFE8,stroke:#388E3C,stroke-width:1px
```
