# openedu-project/openedu-ai-core architecture

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

- Interactive diagram: https://gitdiagram.com/openedu-project/openedu-ai-core
- Repository: https://github.com/openedu-project/openedu-ai-core

## Overview

##### Project Type and Purpose
- This project is an advanced AI integration and backend service for the OpenEdu educational platform.
- Its primary goal is to provide robust AI-powered features such as intelligent agents, course generation, smart mind mapping, and slide-to-video conversion.
- The README specifies it’s a backend core built on FastAPI with integrations with multiple LLM providers (Azure OpenAI, AWS Bedrock, Google Cloud) and integration with various storage and messaging layers (MongoDB, Redis, Celery, etc.).

##### File Structure
- The top-level directory includes Docker and CI/CD configurations (.github/workflows, Dockerfile, docker-compose.yml), indicating a containerized deployment approach.
- The src directory is the heart of the project. It is organized into several clearly-separated parts:
- api/ – Contains API endpoints (controllers), middlewares, repositories, schemas, and hooks, suggesting an MVC-like separation for the web layer.
- core/ – Contains the core business logic including agents, features, tools, prompts, and utilities. This layer likely implements the educational AI capabilities.
- config/ – Holds configuration details for databases (e.g., MongoDB, Redis) and overall settings.
- libs/ – Contains shared libraries that support specific domains (chatbot, mindmap, slide-to-video conversion, summarization, etc.).
- models/ – Defines data structure models used across the system.
- tasks/ – Contains background tasks (likely using Celery) for asynchronous processing such as handling conversational workflows or cron jobs.
- tests/ – Includes unit, integration, and performance tests ensuring code quality.
- utils/ – Utility functions and helpers, supporting the overall application logic.

##### Core Components and Their Responsibilities
a. API Layer:
- Built with FastAPI (src/api), this layer includes various controllers for different features (agent, auth, chatbot, blog, course, etc.).
- Contains middlewares (e.g., error handling, CORS, static file serving) that handle cross-cutting concerns.
b. Business Logic Layer (Core):
- Implements the AI features and agents (src/core/agents, src/core/features) for tasks such as content generation, chat, and mind mapping.
- Uses various tools and integrations with LLM providers (src/core/llm_integration) and utilities for supporting business workflows.
c. Data Persistence and Repositories:
- The configuration under src/config/db and functionality in src/api/repos and models indicate use of databases such as MongoDB.
- Redis integration is also present for caching and task state management.
d. Asynchronous Tasks:
- Background processes are managed under src/tasks, handling tasks like blog generation, course processing, transcript extraction, etc.
- Likely leveraging Celery (as mentioned in README and requirements) and Redis for queue management.
e. Shared Libraries:
- Includes modules for specific functionalities (chatbot, mindmap, slide-to-video conversion, etc.) to facilitate reusability and separation of concerns.
f. Integration Points:
- External AI/ML providers integrated via modules under src/core/llm_integration and others.
- Communication with external storage systems and messaging mechanisms (e.g., Docker orchestration, API keys managed via environment variables).

##### Architectural Patterns/Design Principles
- Layered/MVC Architecture: Separation of controllers, services, and repositories.
- Service-Oriented: Each core feature (agent, chatbot, etc.) is encapsulated in specialized modules making it easier to extend.
- Asynchronous Task Processing: Background tasks are managed separately to avoid blocking the main API.
- Microservice-Ready: While all code is part of one repository, the separation between API, core processing, and asynchronous tasks facilitates scaling individual parts if needed.
- Containerization: Dockerfiles and docker-compose.yml indicate a design that supports containerization and modern DevOps practices.

## Diagram (Mermaid)

```mermaid
graph TD
    %% Client
    User["User Request"]:::client

    %% API Layer
    subgraph "API Layer"
        API["API Layer (FastAPI)"]:::api
    end

    %% Business Logic
    subgraph "Business Logic"
        BL["Business Logic – AI Agents & Features"]:::business
        LLM["LLM Integration Modules"]:::business
    end

    %% Persistence
    subgraph "Persistence"
        DB["Database Config"]:::db
        REPOS["API Repositories"]:::db
        DM["Data Models"]:::models
    end

    %% Background Tasks
    subgraph "Background Tasks"
        tasks["Task Processing (Celery)"]:::tasks
    end

    %% Shared Libraries
    subgraph "Shared Libraries"
        libs["Shared Libraries"]:::libs
    end

    %% External Services
    subgraph "External Services"
        Azure["Azure OpenAI"]:::ext
        AWS["AWS Bedrock"]:::ext
        Google["Google Cloud"]:::ext
    end

    %% Infrastructure / Deployment
    subgraph "Infrastructure"
        deploy["Deployment & DevOps"]:::deploy
    end

    %% Connections
    User -->|"sends_request"| API
    API -->|"forwards_request"| BL
    API -->|"uses"| libs
    API -->|"triggers_task"| tasks

    BL -->|"queries"| DB
    BL -->|"calls_repos"| REPOS
    BL -->|"refers_to"| DM
    BL -->|"invokes"| LLM
    BL -->|"uses"| libs
    BL -->|"triggers_task"| tasks

    LLM -->|"calls"| Azure
    LLM -->|"calls"| AWS
    LLM -->|"calls"| Google

    DB -->|"defines"| DM
    REPOS -->|"maps_to"| DM
    tasks -->|"updates"| DB

    deploy -->|"containerizes"| API
    deploy -->|"containerizes"| BL
    deploy -->|"containerizes"| tasks
    deploy -->|"containerizes"| libs

    %% Click Events
    click API "https://github.com/openedu-project/openedu-ai-core/tree/main/src/api"
    click BL "https://github.com/openedu-project/openedu-ai-core/tree/main/src/core"
    click LLM "https://github.com/openedu-project/openedu-ai-core/tree/main/src/core/llm_integration"
    click DB "https://github.com/openedu-project/openedu-ai-core/tree/main/src/config/db"
    click REPOS "https://github.com/openedu-project/openedu-ai-core/tree/main/src/api/repos"
    click tasks "https://github.com/openedu-project/openedu-ai-core/tree/main/src/tasks"
    click libs "https://github.com/openedu-project/openedu-ai-core/tree/main/src/libs"
    click DM "https://github.com/openedu-project/openedu-ai-core/tree/main/src/models"

    %% Styles
    classDef api fill:#ADD8E6,stroke:#000,stroke-width:2px;
    classDef business fill:#90EE90,stroke:#000,stroke-width:2px;
    classDef db fill:#FFD700,stroke:#000,stroke-width:2px;
    classDef tasks fill:#DDA0DD,stroke:#000,stroke-width:2px;
    classDef libs fill:#FFFF99,stroke:#000,stroke-width:2px;
    classDef models fill:#87CEFA,stroke:#000,stroke-width:2px;
    classDef ext fill:#F0E68C,stroke:#000,stroke-width:2px;
    classDef deploy fill:#D3D3D3,stroke:#000,stroke-width:2px;
    classDef client fill:#FFEFD5,stroke:#000,stroke-width:2px;
```
