# bernardzach/morsecodeapp architecture

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

- Interactive diagram: https://gitdiagram.com/bernardzach/morsecodeapp
- Repository: https://github.com/bernardzach/morsecodeapp

## Overview

##### Project Type and Purpose
- The project is a Flask-based web application designed to help users learn Morse code. It’s essentially a full-stack interactive game that involves both backend processing (Morse code generation, game logic, and processing user input) and frontend rendering (HTML/CSS/JavaScript).
- The README highlights its interactive game play, real-time audio generation, and capabilities for deployment (both local and on AWS EC2), which indicate that the design should capture both client- and server-side components as well as deployment/dynamic audio generation aspects.

##### File Structure
- Top-Level Files:
- “app.py” is the main Flask application entry point.
- “generate_morse_sounds.py” seems responsible for dynamically generating Morse audio.
- “requirements.txt” ensures all Python dependencies are captured.
- Directories:
- The “data/” folder holds JSON data (like test words) for the Morse phrases.
- “src/” contains the core Python backend logic: files handling audio generation, Morse data, and utility functions (e.g., “mongo_utils.py”) even if not directly used in the game interface; possibly hints at future data persistence or additional functionality.
- “static/” contains frontend assets: CSS, JavaScript, images, and even a pre-generated “morse_output.wav”.
- “templates/” holds the HTML pages (like “index.html” and “test.html”) which are rendered by Flask.

##### Readme Insights
- The README describes the features (real-time audio generation, level tracking, adjustable speed, game interaction via keys) and instructions for local run and AWS deployment.
- It explicitly outlines the architecture of the project and even notes the separation of concerns between the backend (Flask app and related logic under “src/”) and the frontend (static UI assets, templates).

##### Main Components
a. Backend Server (Flask App):
- “app.py” as the central entry point controlling routing, initialization, and integration of backend logic.
- Underneath, include core modules from “src/” (morse_audio.py, morse_data.py, mongo_utils.py) to indicate where audio generation, data processing, and potential database interactions occur.
- “generate_morse_sounds.py” as a component for dynamic audio processing.
b. Data & Storage:
- “data/” directory as a datastore for test phrases (e.g., morse_test_words.json).
c. Frontend:
- “templates/” as the container for HTML views (index and test pages).
- “static/” containing CSS (styles.css), JavaScript (script.js), images, and sound files.
d. External Dependencies & Deployment:
- AWS EC2 as an external deployment target, highlighting that the Flask app can run in the cloud.

##### Relationships and Interactions
- That the Flask server interacts with both the “src/” backend modules (for logic, audio generation, Morse code transformation) and serves data from the “data/” folder.
- That the assets housed in “static/” and “templates/” make up the UI layer.
- A dedicated connection (data flow/trigger) from the backend to FFMPEG (via pydub) which then generates the real-time Morse audio.

##### Architectural Patterns & Design Principles to Highlight
- Separation of Concerns: Frontend assets (static and templates) vs. backend logic (Flask app and src modules).
- Modular Design: Clearly indicate that “src/” holds separated utility and logic modules.
- Extensibility: Mention that hints of a potential database (mongo_utils.py) and future enhancements (leaderboard, multiplayer features) could drive further architectural expansion.
- Interaction Flow: User clicks and key strokes (in the browser) trigger backend processing which then calls audio generation components.

## Diagram (Mermaid)

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

    %% Backend Layer
    Server["Flask Web Server (app.py)"]:::backend

    subgraph "Backend Components"
        Audio1["Morse Audio Generation (src/morse_audio.py)"]:::backend
        Audio2["Morse Audio Generation (generate_morse_sounds.py)"]:::backend
        DataProc["Morse Data Processing (src/morse_data.py)"]:::backend
        DBUtil["Database Utility (src/mongo_utils.py)"]:::backend
    end

    DataStore["Data Store (data/morse_test_words.json)"]:::database

    %% Frontend Layer
    subgraph "Frontend Components"
        TemplateIndex["Template Index (templates/index.html)"]:::frontend
        TemplateTest["Template Test (templates/test.html)"]:::frontend
        StaticAssets["Static Assets (static/)"]:::frontend
    end

    %% External Dependencies
    FFMPEG["Audio Processing - FFMPEG/pydub"]:::external
    AWS["AWS EC2 Deployment"]:::external

    %% Connections
    Browser -->|"HTTP_Request/Response"| Server

    Server -->|"Calls"| Audio1
    Server -->|"Calls"| Audio2
    Server -->|"Calls"| DataProc
    Server -->|"Utilizes"| DBUtil
    DBUtil -->|"Reads/Writes"| DataStore

    Audio1 -->|"Triggers"| FFMPEG
    Audio2 -->|"Triggers"| FFMPEG

    Server -->|"Renders"| TemplateIndex
    Server -->|"Renders"| TemplateTest
    Server -->|"Serves"| StaticAssets

    Browser -->|"Loads"| StaticAssets

    Server -->|"Deployed on"| AWS

    %% Styles
    classDef backend fill:#AED6F1,stroke:#2471A3,stroke-width:2px,color:#1B4F72;
    classDef frontend fill:#F9E79F,stroke:#F1C40F,stroke-width:2px,color:#B9770E;
    classDef database fill:#F5CBA7,stroke:#D35400,stroke-width:2px,color:#A04000;
    classDef external fill:#D2B4DE,stroke:#7D3C98,stroke-width:2px,color:#512E5F;
    classDef client fill:#ABEBC6,stroke:#27AE60,stroke-width:2px,color:#196F3D;

    %% Click Events
    click Server "https://github.com/bernardzach/morsecodeapp/blob/main/app.py"
    click Audio1 "https://github.com/bernardzach/morsecodeapp/blob/main/src/morse_audio.py"
    click Audio2 "https://github.com/bernardzach/morsecodeapp/blob/main/generate_morse_sounds.py"
    click DataProc "https://github.com/bernardzach/morsecodeapp/blob/main/src/morse_data.py"
    click DBUtil "https://github.com/bernardzach/morsecodeapp/blob/main/src/mongo_utils.py"
    click DataStore "https://github.com/bernardzach/morsecodeapp/blob/main/data/morse_test_words.json"
    click TemplateIndex "https://github.com/bernardzach/morsecodeapp/blob/main/templates/index.html"
    click TemplateTest "https://github.com/bernardzach/morsecodeapp/blob/main/templates/test.html"
    click StaticAssets "https://github.com/bernardzach/morsecodeapp/tree/main/static/"
```
