# konnn04/simple-comc-ai-system architecture

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

- Interactive diagram: https://gitdiagram.com/konnn04/simple-comc-ai-system
- Repository: https://github.com/konnn04/simple-comc-ai-system

## Overview

##### Main Components
- Client (Front-end): This includes all the React Native components (found under the “client” folder) for different functionalities such as listening exams, speaking exams, vocabulary exercises, user authentication, and communication with AI.
- Server (Back-end): The Flask-based API housed in the “server” folder. Sub-components include:
- Authentication (e.g., routes and DAO under myapp/auth)
- Exam Management (routes and utility modules for speaking, listening, etc.)
- Admin and Teacher modules (for managing users, exams, and content)
- AI and Media Processing: Modules handling STT (Vosk, silero_stt.py), TTS (KokoroTTS, tts.py), and Gemini AI integration.
- Database Layer: Managed using SQLAlchemy (with MySQL as per the README).
- Database: A MySQL database (critical for storing user data, exam results, and application state).
- External Services: Third-party APIs such as Google Gemini AI for content generation and evaluation, and possibly Cloudinary for media storage.

##### Relationships and Data Flow
- How the server interacts with the database (using SQLAlchemy’s ORM) and external services (for voice recognition, TTS, etc.).

##### Architectural Patterns and Principles
- Client Side: Follows a component-based architecture (React/React Native components) with clear separation between navigation (navigators directory) and UI components.
- Server Side: Uses Flask’s routing mechanism and a modularized structure that separates concerns (auth, admin, teacher, data processing). It implicitly uses an MVC-like approach for handling data models (models.py), views (templates), and controllers (routes).
- Secure communication between client and server (JWT authentication and .env configuration files for keys).

##### Relevant Technologies and Frameworks
- Front-end: React Native, Expo, React Navigation, Axios.
- Back-end: Flask, SQLAlchemy, Flask-Admin, JWT handling.
- AI Technologies: Vosk, KokoroTTS, Google Gemini AI.
- Database: MySQL.
- Additional: eSpeak for TTS support at the system level.

## Diagram (Mermaid)

```mermaid
flowchart TD
    %% Client Subgraph
    subgraph "Client Side (React Native)"
        clientReact["React Native App"]:::client
        clientAuth["Auth Components"]:::client
        clientListen["Listening Exams"]:::client
        clientSpeak["Speaking Exams"]:::client
        clientExam["Exam Components"]:::client
        clientComm["Communication Component"]:::client
        clientNav["Navigation"]:::client
        clientUtil["Utility API & Auth Hook"]:::client
    end

    %% Server Subgraph
    subgraph "Server Side (Flask API)"
        serverInit["Flask App Initialization"]:::server
        serverAuth["Auth Routes"]:::server
        serverAuthDAO["Auth DAO"]:::server
        serverMain["Main Exam Routes"]:::server
        examCreateListening["Create Listening"]:::server
        examCreateSpeaking["Create Speaking"]:::server
        examCreateTest["Create Test"]:::server
        examProcessor["Exam Processor"]:::server
        examHistory["Exam History"]:::server
        serverAdmin["Admin Routes"]:::server
        serverTeacher["Teacher Routes"]:::server
        teacherDAO["Teacher DAO"]:::server
        teacherUtil["Teacher Utility"]:::server
        voiceRec["Voice Recognition (STT)"]:::server
        sttUtil["STT Utility"]:::server
        textToSpeech["Text-to-Speech"]:::server
        aiComm["AI Communication"]:::server
        phonemizer["Phonemizer"]:::server
        configFile["Config File"]:::server
        routesConst["Routes Constants"]:::server
    end

    %% Database Subgraph
    subgraph "Database (MySQL)"
        dbModels["ORM Models"]:::db
        dbCreate["DB Creation Script"]:::db
    end

    %% External Services Subgraph
    subgraph "External Services"
        extAPI["Google Gemini AI"]:::external
    end

    %% Client to Server Communication
    clientReact -->|"REST_API"| serverInit
    clientReact -->|"navigation"| clientNav
    clientReact -->|"auth_call"| clientAuth
    clientReact -->|"listening_exam"| clientListen
    clientReact -->|"speaking_exam"| clientSpeak
    clientReact -->|"exam_quiz"| clientExam
    clientReact -->|"communication"| clientComm
    clientReact -->|"api_util"| clientUtil

    %% Server Internal Flow
    serverInit -->|"init_auth"| serverAuth
    serverInit -->|"init_exam"| serverMain
    serverInit -->|"init_admin"| serverAdmin
    serverInit -->|"init_teacher"| serverTeacher
    serverInit -->|"load_config"| configFile
    configFile -->|"load_constants"| routesConst

    serverAuth -->|"access_DAO"| serverAuthDAO

    serverMain -->|"invoke"| examCreateListening
    serverMain -->|"invoke"| examCreateSpeaking
    serverMain -->|"invoke"| examCreateTest
    serverMain -->|"invoke"| examProcessor
    serverMain -->|"invoke"| examHistory

    serverTeacher -->|"use_DAO"| teacherDAO
    serverTeacher -->|"helper"| teacherUtil

    serverMain -->|"process_voice"| voiceRec
    voiceRec -->|"voice_util"| sttUtil
    serverMain -->|"generate_speech"| textToSpeech
    serverMain -->|"integrate_AI"| aiComm
    aiComm -->|"call_API"| extAPI
    phonemizer -->|"assist_TTS"| textToSpeech

    %% Server to Database Communication
    serverInit -->|"DB_connection"| dbModels
    dbModels -->|"setup"| dbCreate

    %% Classes / Styles
    classDef client fill:#bbdefb,stroke:#0d47a1,stroke-width:2px;
    classDef server fill:#c8e6c9,stroke:#1b5e20,stroke-width:2px;
    classDef db fill:#ffe082,stroke:#ff6f00,stroke-width:2px;
    classDef external fill:#fff9c4,stroke:#f9a825,stroke-width:2px;

    %% Click Events for Client Components
    click clientReact "https://github.com/konnn04/simple-comc-ai-system/tree/main/client/"
    click clientAuth "https://github.com/konnn04/simple-comc-ai-system/tree/main/client/components/Auth"
    click clientListen "https://github.com/konnn04/simple-comc-ai-system/tree/main/client/components/ListeningExam"
    click clientSpeak "https://github.com/konnn04/simple-comc-ai-system/tree/main/client/components/SpeakingExam"
    click clientExam "https://github.com/konnn04/simple-comc-ai-system/tree/main/client/components/Exam"
    click clientComm "https://github.com/konnn04/simple-comc-ai-system/blob/main/client/components/Communication.tsx"
    click clientNav "https://github.com/konnn04/simple-comc-ai-system/tree/main/client/navigations"
    click clientUtil "https://github.com/konnn04/simple-comc-ai-system/tree/main/client/utils"

    %% Click Events for Server Components
    click serverInit "https://github.com/konnn04/simple-comc-ai-system/blob/main/server/myapp/__init__.py"
    click serverAuth "https://github.com/konnn04/simple-comc-ai-system/blob/main/server/myapp/auth/routes.py"
    click serverAuthDAO "https://github.com/konnn04/simple-comc-ai-system/blob/main/server/myapp/dao/auth.py"
    click serverMain "https://github.com/konnn04/simple-comc-ai-system/blob/main/server/myapp/main/routes.py"
    click examCreateListening "https://github.com/konnn04/simple-comc-ai-system/blob/main/server/myapp/utils/create_listening.py"
    click examCreateSpeaking "https://github.com/konnn04/simple-comc-ai-system/blob/main/server/myapp/utils/create_speaking.py"
    click examCreateTest "https://github.com/konnn04/simple-comc-ai-system/blob/main/server/myapp/utils/create_test.py"
    click examProcessor "https://github.com/konnn04/simple-comc-ai-system/blob/main/server/myapp/utils/exam.py"
    click examHistory "https://github.com/konnn04/simple-comc-ai-system/blob/main/server/myapp/utils/history.py"
    click serverAdmin "https://github.com/konnn04/simple-comc-ai-system/blob/main/server/myapp/adm/routes.py"
    click serverTeacher "https://github.com/konnn04/simple-comc-ai-system/blob/main/server/myapp/teacher/routes.py"
    click teacherDAO "https://github.com/konnn04/simple-comc-ai-system/blob/main/server/myapp/dao/teacher.py"
    click teacherUtil "https://github.com/konnn04/simple-comc-ai-system/blob/main/server/myapp/utils/teacher.py"
    click voiceRec "https://github.com/konnn04/simple-comc-ai-system/blob/main/server/myapp/tech/silero_stt.py"
    click sttUtil "https://github.com/konnn04/simple-comc-ai-system/blob/main/server/myapp/utils/speech2text.py"
    click textToSpeech "https://github.com/konnn04/simple-comc-ai-system/blob/main/server/myapp/tech/tts.py"
    click aiComm "https://github.com/konnn04/simple-comc-ai-system/blob/main/server/myapp/utils/communicationAI.py"
    click phonemizer "https://github.com/konnn04/simple-comc-ai-system/blob/main/server/myapp/tech/phonemizer.py"
    click configFile "https://github.com/konnn04/simple-comc-ai-system/blob/main/server/myapp/config.py"
    click routesConst "https://github.com/konnn04/simple-comc-ai-system/blob/main/server/myapp/constants/routes.py"

    %% Click Events for Database Components
    click dbModels "https://github.com/konnn04/simple-comc-ai-system/blob/main/server/myapp/models.py"
    click dbCreate "https://github.com/konnn04/simple-comc-ai-system/blob/main/server/myapp/create_db.py"
```
