# harry0703/audionotes architecture

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

- Interactive diagram: https://gitdiagram.com/harry0703/audionotes
- Repository: https://github.com/harry0703/audionotes

## Overview

##### Project Type and Purpose
- AudioNotes is a backend application that processes multimedia inputs to generate structured, readable notes.
- Its purpose is to extract content from audio/video files using FunASR and then enhance and structure that content using a language model (Qwen2 through Ollama).
- The project supports two modes of deployment: Docker-based (recommended) and local deployment with a PostgreSQL database.

##### File Structure
- Top-Level Files:
- .env.example, Dockerfile, docker-compose.yml, main.py, and requirements.txt indicate environmental configuration, containerization, and the entry point.
- The app Directory:
- Contains the core business logic.
- app/services holds modules that interface with external services:
- asr_funasr.py: Likely handles communication with the FunASR service for audio/video recognition.
- data_layer.py: Manages interactions with the database (PostgreSQL), ensuring that processed notes are stored.
- ollama.py: Interfaces with the Ollama service to access Qwen2 for processing the recognized content.
- app/utils holds utility functions (utils.py) used across modules.
- docs Directory:
- Contains illustrations and sample images demonstrating the system’s output.

##### README for Additional Insights
- The README clearly outlines how the system interacts with external dependencies (FunASR and Qwen2) and describes both deployment methods.
- It provides key URLs and commands, which indicate the need to manage dependencies and configurations (e.g., modifying .env, running Docker containers or a local server).

a. Main Components to Include:
- Client/User Interface: Represents the end-user accessing the service via a web-based UI (e.g., provided by chainlit as hinted by the 'chainlit run main.py' command).
- API/Application Server: The server that runs main.py — this acts as the central hub orchestrating service interactions.
- Service Layer:
- ASR Module (app/services/asr_funasr.py): For audio/video recognition via FunASR.
- Data Layer Module (app/services/data_layer.py): For interactions with the PostgreSQL database.
- Ollama Module (app/services/ollama.py): For interfacing with the Qwen2 model.
- Utilities: Represent the shared functions in app/utils/utils.py that support service operations.
- External Services:
- FunASR (external open-source ASR tool).
- Ollama’s Qwen2 (the language model).
- Database:
- PostgreSQL: Used in the local deployment setup for storing structured notes and related data.

b. Relationships and Interactions:
- How the client sends requests to the API/Application server.
- That the ASR module sends audio/video files to FunASR and receives recognized text.
- Then, this text is passed to the Ollama module, which calls the Qwen2 model to transform or structure the content.
- The structured notes are stored/retrieved from the PostgreSQL database (via the Data module).
- Interactions back to the client, e.g., delivering the structured markdown notes via the UI.

c. Architectural Patterns & Design Principles:
- Separation of Concerns: The division into services (ASR, Data, and Ollama) ensures each module focuses on a specific task.
- Modularity: Use of utility functions and clear service modules benefits maintainability and future enhancements.
- Deployment Flexibility: The presence of both Docker and local deployment setups indicates the need to clearly delineate the infrastructure components and environment variables/configurations.
- Extensibility: With a clear service and data layer, incorporating additional services or switching between external providers can be easily visualized.

- From Client → Application Server
- From Application Server → ASR Service → Application Server → Language Processing Service → Application Server → Database
- Additional Annotations: Label key protocols or interfaces if known (e.g., REST API calls, gRPC, or direct function calls) and note container-specific details if illustrating Docker elements.

## Diagram (Mermaid)

```mermaid
graph TD
    %% Client Layer
    subgraph "Client Layer"
        UI["Client/User Interface"]:::client
    end

    %% Server Layer
    subgraph "Server Layer"
        API["API/Application Server"]:::server
        ASR["ASR Service (FunASR)"]:::internal
        OLL["Language Processing (Qwen2/Ollama)"]:::internal
        DATA["Data Layer (Database)"]:::internal
        UTIL["Utilities"]:::utility
    end

    %% External Services
    subgraph "External Services"
        FUN["FunASR (External)"]:::external
        QWEN["Qwen2 (via Ollama)"]:::external
        PSQL["PostgreSQL Database"]:::database
    end

    %% Deployment & Configuration
    subgraph "Deployment & Config"
        ENV["Env Config"]:::config
        DOCKERFILE["Dockerfile"]:::deployment
        DOCKERCOMPOSE["docker-compose.yml"]:::deployment
    end

    %% Connections
    UI -->|"sends_request"| API

    API -->|"processes_input"| ASR
    ASR -->|"sends_audio"| FUN
    FUN -->|"returns_text"| ASR
    ASR -->|"sends_text"| API

    API -->|"enhances_text"| OLL
    OLL -->|"calls_model"| QWEN
    QWEN -->|"returns_content"| OLL
    OLL -->|"sends_refined_text"| API

    API -->|"stores_notes"| DATA
    DATA -->|"db_operations"| PSQL
    API -->|"returns_markdown"| UI

    API -->|"uses"| UTIL

    ENV -->|"configures"| API
    DOCKERFILE -->|"builds"| API
    DOCKERCOMPOSE -->|"orchestrates"| API

    %% Click Events
    click API "https://github.com/harry0703/audionotes/blob/main/main.py"
    click ASR "https://github.com/harry0703/audionotes/blob/main/app/services/asr_funasr.py"
    click DATA "https://github.com/harry0703/audionotes/blob/main/app/services/data_layer.py"
    click OLL "https://github.com/harry0703/audionotes/blob/main/app/services/ollama.py"
    click UTIL "https://github.com/harry0703/audionotes/blob/main/app/utils/utils.py"
    click ENV "https://github.com/harry0703/audionotes/blob/main/.env.example"
    click DOCKERFILE "https://github.com/harry0703/audionotes/tree/main/Dockerfile"
    click DOCKERCOMPOSE "https://github.com/harry0703/audionotes/blob/main/docker-compose.yml"

    %% Styles
    classDef client fill:#FFCCCC,stroke:#333,stroke-width:2px;
    classDef server fill:#CCE5FF,stroke:#333,stroke-width:2px;
    classDef internal fill:#D4EFDF,stroke:#333,stroke-width:2px;
    classDef external fill:#FADBD8,stroke:#333,stroke-width:2px;
    classDef database fill:#FCF3CF,stroke:#333,stroke-width:2px;
    classDef config fill:#E6E6FA,stroke:#333,stroke-width:2px;
    classDef deployment fill:#FFF2CC,stroke:#333,stroke-width:2px;
    classDef utility fill:#D6EAF8,stroke:#333,stroke-width:2px;
```
