# tuienn/kma-one architecture

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

- Interactive diagram: https://gitdiagram.com/tuienn/kma-one
- Repository: https://github.com/tuienn/kma-one

## Overview

##### Project type and purpose
- This is a single‐page application (SPA) built with React, TypeScript, and Vite.
- It provides two user roles:
- Admin: course management, student and score management.
- User: real‐time chat, schedule/calendar viewing, point lookup.
- It uses Firebase (messaging, possibly Firestore/auth) and an external REST API (via APIService).

##### File structure
- Top-level:
- public/ – static assets, Firebase messaging service worker.
- src/ – all application code.
- src subdivisions:
- api/ – APIService.ts and endpoint wrappers (REST).
- firebase/ – Firebase setup (user, messaging).
- components/ – presentational and container components, organized by feature (admin / user / common).
- pages/ – route‐level components (AdminPages, UserPages).
- routes/ – React Router definitions (AdminRoutes, UserRoutes, ProtectedRoute).
- context/ – React Context providers (ChatProvider, ScheduleProvider, PathProvider).
- assets/, styles/, locales/ – images, CSS, i18n JSON.
- utils/ – shared helpers (format, storage).
- Config files: vite.config.ts, tsconfig*.json, eslint.config.js, tailwind.config.js.

##### Key insights from the README
- Minimal React+TypeScript+Vite setup with Fast Refresh.
- ESLint is configured; recommends type‐aware rules for production.
- No backend code here—consumption of external services is through APIService and Firebase.

##### Components
a. Main components
- Browser / Client Application (React SPA)
– UI Layer (Pages, Components, Layouts)
– Routing Layer (Routes, ProtectedRoute)
– State Layer (Context Providers: Chat, Schedule, Path)
– Service Layer (APIService, Firebase modules)
– Utility Layer (helpers, i18n, assets)
- External Services
– REST API endpoints (apiProvince, course/score/student management)
– Firebase (Messaging SW, Auth/Database or Firestore real‐time chat)
b. Relationships & data flow
- UI Components ←→ Context Providers ←→ Service Layer
- Service Layer → HTTP REST calls → External API
- Service Layer → Firebase SDK → Firebase backend
- Routing Layer maps URL → Page Components
c. Architectural patterns
- Feature-based folder structure
- Separation of concerns: UI, state (Context), data (Service)
- Client-side routing (React Router)
- Service abstraction (APIService wrapper over fetch/axios)
- Internationalization (i18n JSON files + content injection)
d. Key technologies
- Vite (build & dev server)
- React 18 + TypeScript
- React Router v6
- Firebase SDK (messaging, real-time features)
- ESLint, Prettier, Tailwind CSS, PostCSS

## Diagram (Mermaid)

```mermaid
flowchart TD
    subgraph "Client Application"
        subgraph "UI Layer"
            subgraph "Admin Pages"
                Course["CourseManagement"]:::ui
                Score["ScoreManagement"]:::ui
                Student["StudentManagement"]:::ui
            end
            subgraph "User Pages"
                ChatApp["ChatApp"]:::ui
                ChatAI["ChatAI"]:::ui
                ScoresPage["Scores"]:::ui
                Schedule["MySchedule"]:::ui
                FindClass["FindClass"]:::ui
                DetailClass["DetailClass"]:::ui
            end
            subgraph "Common Components"
                ModalInfo["ModalInfo"]:::ui
                FormItemCommon["FormItemCommon"]:::ui
                QuerySelect["QuerySelect"]:::ui
                ExportButton["ExportButton"]:::ui
                ImportButton["ImportButton"]:::ui
                TableScores["TableScores"]:::ui
                TableStudents["TableStudents"]:::ui
            end
        end
        subgraph "Routing Layer"
            Routes["Routes"]:::ui
            AdminRoutes["AdminRoutes"]:::ui
            UserRoutes["UserRoutes"]:::ui
            ProtectedRoute["ProtectedRoute"]:::ui
        end
        subgraph "State Layer"
            ChatProv["ChatProvider"]:::state
            ScheduleProv["ScheduleProvider"]:::state
            PathProv["PathProvider"]:::state
        end
        subgraph "Service Layer"
            APIService["APIService"]:::service
            APIProvince["apiProvince"]:::service
            FirebaseUser["firebase.ts"]:::service
            SW["firebase-messaging-sw.js"]:::service
        end
        subgraph "Utility Layer"
            CommonUtil["common.ts"]:::service
            FormatUtil["formatValue.ts"]:::service
            StorageUtil["handleStorage.ts"]:::service
            I18n["i18n.ts"]:::service
        end
    end

    subgraph "External Services"
        REST["REST API"]:::external
        Firebase["Firebase Service"]:::external
    end

    Course -->|"navigates to"| UI
    ChatApp -->|"renders"| UI
    UI -->|"uses routes"| Routes
    Routes -->|route to| AdminRoutes
    Routes -->|route to| UserRoutes
    AdminRoutes -->|protect| ProtectedRoute
    UserRoutes -->|protect| ProtectedRoute

    UI -->|"provides context"| ChatProv
    UI -->|"provides context"| ScheduleProv
    UI -->|"provides context"| PathProv

    ChatProv -->|calls| APIService
    ScheduleProv -->|calls| APIService
    PathProv -->|calls| APIService

    APIService -->|HTTP| REST
    APIProvince -->|HTTP| REST
    FirebaseUser -->|SDK| Firebase
    SW -->|push notifications| Firebase

    classDef ui fill:#AED6F1,stroke:#1B4F72
    classDef state fill:#A9DFBF,stroke:#1D8348
    classDef service fill:#F9E79F,stroke:#B9770E
    classDef external fill:#D5D8DC,stroke:#566573

    click Course "https://github.com/tuienn/kma-one/blob/master/src/pages/admin/CourseManagement.tsx"
    click Score "https://github.com/tuienn/kma-one/blob/master/src/pages/admin/ScoreManagement.tsx"
    click Student "https://github.com/tuienn/kma-one/blob/master/src/pages/admin/StudentManagement.tsx"
    click ChatApp "https://github.com/tuienn/kma-one/blob/master/src/pages/user/ChatApp.tsx"
    click ChatAI "https://github.com/tuienn/kma-one/blob/master/src/pages/user/ChatAI.tsx"
    click ScoresPage "https://github.com/tuienn/kma-one/blob/master/src/pages/user/Scores.tsx"
    click Schedule "https://github.com/tuienn/kma-one/blob/master/src/pages/user/schedule/MySchedule.tsx"
    click FindClass "https://github.com/tuienn/kma-one/blob/master/src/pages/user/schedule/ClassList/FindClass.tsx"
    click DetailClass "https://github.com/tuienn/kma-one/blob/master/src/pages/user/schedule/ClassList/DetailClass.tsx"
    click ModalInfo "https://github.com/tuienn/kma-one/blob/master/src/components/common/ModalInfo.tsx"
    click FormItemCommon "https://github.com/tuienn/kma-one/blob/master/src/components/common/FormItemCommon.tsx"
    click QuerySelect "https://github.com/tuienn/kma-one/blob/master/src/components/common/QuerySelect.tsx"
    click ExportButton "https://github.com/tuienn/kma-one/blob/master/src/components/common/ExportButton.tsx"
    click ImportButton "https://github.com/tuienn/kma-one/blob/master/src/components/common/ImportButton.tsx"
    click TableScores "https://github.com/tuienn/kma-one/blob/master/src/components/common/TableScores.tsx"
    click TableStudents "https://github.com/tuienn/kma-one/blob/master/src/components/common/TableStudents.tsx"
    click Routes "https://github.com/tuienn/kma-one/blob/master/src/routes/Routes.tsx"
    click AdminRoutes "https://github.com/tuienn/kma-one/blob/master/src/routes/AdminRoutes.tsx"
    click UserRoutes "https://github.com/tuienn/kma-one/blob/master/src/routes/UserRoutes.tsx"
    click ProtectedRoute "https://github.com/tuienn/kma-one/blob/master/src/routes/ProtectedRoute.tsx"
    click ChatProv "https://github.com/tuienn/kma-one/blob/master/src/context/ChatProvider.tsx"
    click ScheduleProv "https://github.com/tuienn/kma-one/blob/master/src/context/ScheduleProvider.tsx"
    click PathProv "https://github.com/tuienn/kma-one/blob/master/src/context/PathProvider.tsx"
    click APIService "https://github.com/tuienn/kma-one/blob/master/src/api/APIService.ts"
    click APIProvince "https://github.com/tuienn/kma-one/blob/master/src/api/apiProvince.ts"
    click FirebaseUser "https://github.com/tuienn/kma-one/blob/master/src/firebase/user/firebase.ts"
    click SW "https://github.com/tuienn/kma-one/blob/master/public/firebase-messaging-sw.js"
    click CommonUtil "https://github.com/tuienn/kma-one/blob/master/src/utils/common.ts"
    click FormatUtil "https://github.com/tuienn/kma-one/blob/master/src/utils/formatValue.ts"
    click StorageUtil "https://github.com/tuienn/kma-one/blob/master/src/utils/handleStorage.ts"
    click I18n "https://github.com/tuienn/kma-one/blob/master/src/locales/i18n/i18n.ts"
```
