# tusgino/gp-webapp architecture

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

- Interactive diagram: https://gitdiagram.com/tusgino/gp-webapp
- Repository: https://github.com/tusgino/gp-webapp

## Overview

##### Project Type and Purpose
- This is a full-stack web front-end built with Next.js (App Router), React, Redux (with Redux-Saga), and Tailwind CSS.
- It consumes a set of RESTful back-end microservices (Auth, Course, Discussion, etc.) via Axios and Redux actions.
- It provides user flows for authentication, browsing courses, lesson playback, quizzes, payments, profiles, dashboards, and internationalization.

##### File-Structure Analysis
- Top-level “app/” directory holds Next.js pages, layouts, and route segments using the App Router.
- “components/” organized by feature (auth, course, dashboard, profile, shared UI primitives, etc.).
- “lib/” contains API wrappers and Redux modules:
– lib/*/api.ts → HTTP calls to each microservice
– lib/*/action.ts → action creators
– lib/redux/* → slice + saga + selectors per domain
- “public/” holds static assets and locale JSON files for next-i18next.
- “styles/” and Tailwind config for global styling.
- Config files: next.config.mjs, next-i18next.config.js, tsconfig.json, ESLint/Prettier, etc.

##### Key Components
a. Browser (Client)
– Next.js App Router → Server-side and Client-side components
– React / Redux store with Saga middleware
– UI component library (components/ui, shared, theme-provider)
– i18n loader fetching locale files (public/locales)
b. CDN / Static Assets
– Served from “public/assets” and built CSS/JS bundles
c. Next.js Server (Node.js)
– SSR/SSG pipelines
– App ‑> route handlers → initial props / API calls
d. External Services (Microservices)
– Auth Service
– Course Service
– Lesson Service
– Discussion Service
– Enrollment Service
– Payment Service (e.g., Stripe)
– Profile Service
– Progress & Review Services
e. Data Stores (implicit on back-end)
– User DB, Course DB, Payment DB, etc.

##### Interactions and Data Flow
1. Browser requests a page → Next.js server renders (SSR/SSG) or serves a client bundle.
2. Client-side navigation dispatches Redux actions → Sagas intercept → call lib/*/api.ts via Axios → HTTP request to microservices.
3. Responses update Redux store → React components re-render.
4. UI pulls translations from public/locales via next-i18next.
5. Payment flows redirect to external gateway → return to “/payment-return” route.

##### Architectural Patterns and Design Principles
– Feature-based component organization
– Separation of concerns: Router, UI, state management, API layer
– Redux-Saga for side-effects orchestration
– Next.js App Router for hybrid SSR/CSR
– i18n via next-i18next and locale JSONs
– Strict typing with TypeScript interfaces in “interface/”
– Theming and CSS utility via Tailwind

##### Essential Elements
– Notes on SSR vs CSR responsibilities

## Diagram (Mermaid)

```mermaid
graph TB
    %% Client-side
    subgraph "Browser (Client-side)"
        Browser["Browser"]:::frontend
        Router["Next.js App Router"]:::frontend
        ReduxStore["Redux Store & Saga"]:::state
        UIlib["UI Component Library"]:::ui
        i18n["i18n Loader"]:::frontend
    end

    %% CDN
    CDN["CDN / Static Assets"]:::frontend

    %% Next.js Server
    subgraph "Next.js Server (SSR/SSG)"
        AppHandler["App Routes (app/)"]:::frontend
        Config["Config & Middleware"]:::frontend
    end

    %% Auth Domain
    subgraph "Auth Domain"
        AuthPages["app/auth/**"]:::frontend
        AuthUI["components/auth/**"]:::ui
        AuthAPI["lib/auth/api.ts"]:::state
        AuthActions["lib/auth/actions.ts"]:::state
        AuthSlice["lib/redux/auth/auth.slice.ts"]:::state
        AuthSaga["lib/redux/auth/auth.saga.ts"]:::state
    end

    %% Course Domain
    subgraph "Course Domain"
        CoursePages["app/courses/[slug]/page.tsx"]:::frontend
        CourseUI["components/course/**"]:::ui
        CourseAPI["lib/course/api.ts"]:::state
        CourseAction["lib/course/action.ts"]:::state
        CourseSlice["lib/redux/course/course.slice.ts"]:::state
        CourseSaga["lib/redux/course/course.saga.ts"]:::state
    end

    %% Lesson Domain
    subgraph "Lesson Domain"
        LessonPages["app/lessons/[slug]/page.tsx"]:::frontend
        LessonUI["components/course/lesson-content/**"]:::ui
        LessonAPI["lib/lesson/api.ts"]:::state
        LessonAction["lib/lesson/action.ts"]:::state
        LessonSlice["lib/redux/lesson/lesson.slice.ts"]:::state
        LessonSaga["lib/redux/lesson/lesson.saga.ts"]:::state
    end

    %% External Services
    subgraph "Microservices"
        AuthService["Auth Service"]:::service
        CourseService["Course Service"]:::service
        LessonService["Lesson Service"]:::service
    end

    %% Flows
    Browser -->|"request page"| Router
    Router -->|"SSR/SSG"| AppHandler
    Router -->|"client nav"| ReduxStore
    ReduxStore -->|"state updates"| UIlib
    UIlib -->|"renders UI"| Browser
    Browser -->|"loads locales"| i18n

    AppHandler -->|routes to| AuthPages
    AuthPages -->|renders| AuthUI
    AuthUI -->|dispatch LOGIN| ReduxStore
    ReduxStore -->|call auth API| AuthAPI
    AuthAPI -->|HTTP request| AuthService
    AuthService -->|response| ReduxStore
    ReduxStore -->|update auth state| AuthSlice

    AppHandler -->|routes to| CoursePages
    CoursePages -->|renders| CourseUI
    CourseUI -->|dispatch COURSE_FETCH| ReduxStore
    ReduxStore -->|call course API| CourseAPI
    CourseAPI -->|HTTP GET /courses| CourseService
    CourseService -->|response| ReduxStore
    ReduxStore -->|update course state| CourseSlice

    AppHandler -->|routes to| LessonPages
    LessonPages -->|renders| LessonUI
    LessonUI -->|dispatch LESSON_FETCH| ReduxStore
    ReduxStore -->|call lesson API| LessonAPI
    LessonAPI -->|HTTP GET /lessons| LessonService
    LessonService -->|response| ReduxStore
    ReduxStore -->|update lesson state| LessonSlice

    CDN -->|"serve assets"| Browser

    Config -->|"middleware"| AppHandler

    %% Click events
    click Router "https://github.com/tusgino/gp-webapp/tree/develop/app/"
    click UIlib "https://github.com/tusgino/gp-webapp/tree/develop/components/ui/"
    click ReduxStore "https://github.com/tusgino/gp-webapp/blob/develop/lib/redux/store.ts"
    click AppHandler "https://github.com/tusgino/gp-webapp/tree/develop/app/"
    click AuthPages "https://github.com/tusgino/gp-webapp/tree/develop/app/auth/"
    click AuthUI "https://github.com/tusgino/gp-webapp/tree/develop/components/auth/"
    click AuthAPI "https://github.com/tusgino/gp-webapp/blob/develop/lib/auth/api.ts"
    click AuthActions "https://github.com/tusgino/gp-webapp/blob/develop/lib/auth/actions.ts"
    click AuthSlice "https://github.com/tusgino/gp-webapp/blob/develop/lib/redux/auth/auth.slice.ts"
    click AuthSaga "https://github.com/tusgino/gp-webapp/blob/develop/lib/redux/auth/auth.saga.ts"
    click CoursePages "https://github.com/tusgino/gp-webapp/blob/develop/app/courses/[slug]/page.tsx"
    click CourseUI "https://github.com/tusgino/gp-webapp/tree/develop/components/course/"
    click CourseAPI "https://github.com/tusgino/gp-webapp/blob/develop/lib/course/api.ts"
    click CourseAction "https://github.com/tusgino/gp-webapp/blob/develop/lib/course/action.ts"
    click CourseSlice "https://github.com/tusgino/gp-webapp/blob/develop/lib/redux/course/course.slice.ts"
    click CourseSaga "https://github.com/tusgino/gp-webapp/blob/develop/lib/redux/course/course.saga.ts"
    click LessonPages "https://github.com/tusgino/gp-webapp/blob/develop/app/lessons/[slug]/page.tsx"
    click LessonUI "https://github.com/tusgino/gp-webapp/tree/develop/components/course/lesson-content/"
    click LessonAPI "https://github.com/tusgino/gp-webapp/blob/develop/lib/lesson/api.ts"
    click LessonAction "https://github.com/tusgino/gp-webapp/blob/develop/lib/lesson/action.ts"
    click LessonSlice "https://github.com/tusgino/gp-webapp/blob/develop/lib/redux/lesson/lesson.slice.ts"
    click LessonSaga "https://github.com/tusgino/gp-webapp/blob/develop/lib/redux/lesson/lesson.saga.ts"

    %% Styles
    classDef frontend fill:#8ecae6,stroke:#333,stroke-width:1px
    classDef ui fill:#a6d96a,stroke:#333,stroke-width:1px
    classDef state fill:#fdae61,stroke:#333,stroke-width:1px
    classDef service fill:#cccccc,stroke:#333,stroke-width:1px
```
