# know-how-ai/know-how-fe architecture

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

- Interactive diagram: https://gitdiagram.com/know-how-ai/know-how-fe
- Repository: https://github.com/know-how-ai/know-how-fe

## Overview

##### Main Components

a. Frontend Layer (Next.js Application):
- Component hierarchy using Atomic Design:
- Atoms (basic UI components)
- Molecules (composite components)
- Organisms (complex components)
- Pages (route components)
- State Management (Redux + Redux Toolkit)
- Theme System (Light/Dark modes)
- Local Storage (Redux-persist)

b. Backend Layer (Express.js Application):
- MVC Architecture
- Authentication System (Session-based)
- API Controllers
- Middleware Layer

c. Database Layer:
- MySQL (Primary Database)
- Redis (Session Store)
- Sequelize ORM

d. External Services:
- OpenAI API Integration
- AWS Services (S3, CloudFront, Route 53, Lightsail)

**[Client Layer]**
- ↓ ↑
**[CDN Layer (CloudFront)]**
- ↓ ↑
**[Frontend Layer (Next.js on S3)]**
- ↓ ↑
**[API Gateway/Apache Reverse Proxy]**
- ↓ ↑
**[Backend Layer (Express.js on Lightsail)]**
- ↓ ↑
**[Database Layer]     [External Services]**

##### Important Flows to Highlight

- Authentication flow with session management
- API request/response cycle
- Static asset delivery through CDN
- Database interactions
- OpenAI API integration
- State management flow

##### Additional Elements

- Security layers (SSL/TLS)
- Caching mechanisms
- Monitoring points (PM2)

##### Implementation Details

- Keep components proportional to their importance
- Version numbers for major components
- Annotations for key architectural decisions

Remember to maintain a balance between detail and clarity, focusing on the service's unique aspects like the AI integration, atomic design pattern, and multi-layer authentication system.

## Diagram (Mermaid)

```mermaid
graph TB
    subgraph Client
        Browser["Web Browser"]
    end

    subgraph CDN
        CF["AWS CloudFront"]
    end

    subgraph Frontend
        direction TB
        NextApp["Next.js Application"]
        
        subgraph Components
            direction TB
            Atoms["Atoms"]:::component
            Molecules["Molecules"]:::component
            Organisms["Organisms"]:::component
            Pages["Pages"]:::component
        end

        subgraph State
            direction TB
            Store["Redux Store"]:::state
            UIState["UI State"]:::state
            UserState["User State"]:::state
            ResultState["Result State"]:::state
        end

        subgraph Theme
            direction TB
            ThemeConfig["Theme Configuration"]:::theme
            GlobalStyles["Global Styles"]:::theme
            ThemeWidget["Theme Widget"]:::theme
        end

        subgraph Auth
            direction TB
            AuthModal["Auth Modal"]:::auth
            LoginForm["Login Form"]:::auth
            ProfileModal["Profile Modal"]:::auth
        end

        FetchService["Fetch Service"]:::service
        Layout["Main Layout"]:::layout
    end

    subgraph Gateway
        Apache["Apache Reverse Proxy"]
    end

    subgraph Backend
        Express["Express.js Server"]
        Controllers["API Controllers"]
        Middleware["Middleware Layer"]
    end

    subgraph Database
        MySQL[(MySQL DB)]
        Redis[(Redis Session Store)]
    end

    subgraph External
        OpenAI["OpenAI API"]
        AWS["AWS Services"]
    end

    subgraph Testing
        Jest["Jest"]:::test
        Cypress["Cypress"]:::test
        Storybook["Storybook"]:::test
    end

    %% Relationships
    Browser <--> CF
    CF <--> NextApp
    NextApp <--> Apache
    Apache <--> Express
    Express <--> Controllers
    Controllers <--> Middleware
    Middleware <--> MySQL
    Middleware <--> Redis
    Express <--> OpenAI
    Express <--> AWS

    %% Component Relationships
    Atoms --> Molecules
    Molecules --> Organisms
    Organisms --> Pages
    Pages --> Layout
    Store --> NextApp

    %% Styling
    classDef component fill:#e1f5fe,stroke:#01579b
    classDef state fill:#e8f5e9,stroke:#2e7d32
    classDef theme fill:#fff3e0,stroke:#ff6f00
    classDef auth fill:#fce4ec,stroke:#c2185b
    classDef service fill:#f3e5f5,stroke:#7b1fa2
    classDef layout fill:#ede7f6,stroke:#4527a0
    classDef test fill:#efebe9,stroke:#3e2723

    %% Click Events
    click Atoms "https://github.com/know-how-ai/know-how-FE/tree/main/src/components/atoms"
    click Molecules "https://github.com/know-how-ai/know-how-FE/tree/main/src/components/molecules"
    click Organisms "https://github.com/know-how-ai/know-how-FE/tree/main/src/components/organics"
    click Pages "https://github.com/know-how-ai/know-how-FE/tree/main/src/pages"
    click Store "https://github.com/know-how-ai/know-how-FE/blob/main/src/contexts/store.ts"
    click UIState "https://github.com/know-how-ai/know-how-FE/blob/main/src/contexts/uiSlice.ts"
    click UserState "https://github.com/know-how-ai/know-how-FE/blob/main/src/contexts/userSlice.ts"
    click ResultState "https://github.com/know-how-ai/know-how-FE/blob/main/src/contexts/resultSlice.ts"
    click ThemeConfig "https://github.com/know-how-ai/know-how-FE/blob/main/src/components/styles/theme.ts"
    click GlobalStyles "https://github.com/know-how-ai/know-how-FE/blob/main/src/components/styles/global-style.ts"
    click ThemeWidget "https://github.com/know-how-ai/know-how-FE/blob/main/src/components/molecules/themeWidget/ThemeWidget.tsx"
    click AuthModal "https://github.com/know-how-ai/know-how-FE/blob/main/src/components/organics/authModal/AuthModal.tsx"
    click LoginForm "https://github.com/know-how-ai/know-how-FE/blob/main/src/components/molecules/loginOrJoinForm/LoginOrJoinForm.tsx"
    click ProfileModal "https://github.com/know-how-ai/know-how-FE/blob/main/src/components/organics/profileModal/ProfileModal.tsx"
    click Jest "https://github.com/know-how-ai/know-how-FE/blob/main/jest.config.js"
    click Cypress "https://github.com/know-how-ai/know-how-FE/tree/main/cypress/e2e"
    click Storybook "https://github.com/know-how-ai/know-how-FE/blob/main/.storybook/main.ts"
    click Layout "https://github.com/know-how-ai/know-how-FE/blob/main/src/layout/Layout.tsx"
    click FetchService "https://github.com/know-how-ai/know-how-FE/blob/main/src/libs/useFetchService.ts"
```
