# anandhakrishnanaji/tuneswitch architecture

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

- Interactive diagram: https://gitdiagram.com/anandhakrishnanaji/tuneswitch
- Repository: https://github.com/anandhakrishnanaji/tuneswitch

## Overview

##### Main Components Identification

The system consists of three major layers that should be prominently displayed:

a) Frontend (Flutter Mobile Application):
- Modules:
- Authentication Module
- Player Interface
- Channel Management
- Location Services
- WebSocket Client

b) Backend (Django Application):
- In the middle
- Highlight:
- Django Channels (WebSocket Server)
- REST API Endpoints
- Authentication System
- Channel Management System

c) External Services:
- On the right side
- Include:
- Spotify API
- Redis (for WebSocket)
- Geolocation Services

##### Component Relationships

a) Real-time Communications:
- Real-time music swapping flow

b) Authentication Flow:
- Flutter → Spotify OAuth
- Flutter → Django Backend
- Django Backend → Spotify API

c) Data Flow:
- Location data flow from mobile to backend
- Music swap requests and responses
- Channel creation and management flow

##### Specific Implementation Details

Technical details in smaller notes:
- Django Channels for WebSocket implementation
- Flutter WebSocket Channel for client-side
- Spotify SDK integration
- Geolocation services
- Redis for WebSocket backing

##### Key Features to Highlight

- Normal Mode
- Travel Mode
- Channel Mode
- Real-time music swapping logic

##### Architecture Patterns

Emphasize:
- WebSocket-based real-time communication
- REST API for non-real-time operations
- Token-based authentication
- Location-based services integration

##### Notes Section

Technical notes about:
- Scalability considerations
- Known limitations (from README issues)
- Deployment specifications (Heroku)

Remember to include version information and any deployment-specific configurations that affect the architecture (like Heroku deployment details).

## Diagram (Mermaid)

```mermaid
graph TB
    subgraph Frontend
        FE_Main["Main App Entry"]:::frontend
        FE_Auth["Authentication Module"]:::frontend
        FE_Player["Player Interface"]:::frontend
        FE_Channel["Channel Management"]:::frontend
        FE_Location["Location Services"]:::frontend
        FE_WebSocket["WebSocket Client"]:::frontend
        FE_Mode["Mode Management"]:::frontend
        FE_UI["UI Pages"]:::frontend
    end

    subgraph Backend
        BE_Entry["ASGI Entry Point"]:::backend
        BE_WebSocket["WebSocket Server"]:::backend
        BE_API["REST API Layer"]:::backend
        BE_Auth["Authentication System"]:::backend
        BE_Channel["Channel Management"]:::backend
        BE_Models["Data Models"]:::backend
        BE_Serial["Serialization"]:::backend
    end

    subgraph External
        Spotify["Spotify API"]:::external
        Redis["Redis"]:::external
        GeoService["Geolocation Services"]:::external
    end

    %% Frontend Relationships
    FE_Main --> FE_Auth
    FE_Main --> FE_Player
    FE_Main --> FE_Channel
    FE_Main --> FE_Location
    FE_Main --> FE_WebSocket
    FE_Main --> FE_Mode
    FE_Main --> FE_UI

    %% Backend Relationships
    BE_Entry --> BE_WebSocket
    BE_Entry --> BE_API
    BE_API --> BE_Auth
    BE_API --> BE_Channel
    BE_API --> BE_Models
    BE_Models --> BE_Serial

    %% Cross-Layer Relationships
    FE_WebSocket <--> BE_WebSocket
    FE_Auth --> BE_Auth
    FE_Channel --> BE_Channel
    BE_WebSocket --> Redis
    FE_Location --> GeoService
    FE_Auth --> Spotify
    BE_Auth --> Spotify

    %% Styling
    classDef frontend fill:#3498db
    classDef backend fill:#2ecc71
    classDef external fill:#9b59b6
    
    %% Click Events
    click FE_Main "https://github.com/anandhakrishnanaji/TuneSwitch/blob/master/lib/main.dart"
    click FE_Auth "https://github.com/anandhakrishnanaji/TuneSwitch/blob/master/lib/providers/auth.dart"
    click FE_Player "https://github.com/anandhakrishnanaji/TuneSwitch/blob/master/lib/widgets/playContainer.dart"
    click FE_Channel "https://github.com/anandhakrishnanaji/TuneSwitch/blob/master/lib/widgets/channelcreate.dart"
    click FE_Mode "https://github.com/anandhakrishnanaji/TuneSwitch/blob/master/lib/providers/mode.dart"
    click FE_UI "https://github.com/anandhakrishnanaji/TuneSwitch/blob/master/lib/pages/homePage.dart"
    click BE_Entry "https://github.com/anandhakrishnanaji/TuneSwitch/blob/master/Backend/TuneSwitch/TuneSwitch/asgi.py"
    click BE_WebSocket "https://github.com/anandhakrishnanaji/TuneSwitch/blob/master/Backend/TuneSwitch/switch/consumers.py"
    click BE_API "https://github.com/anandhakrishnanaji/TuneSwitch/blob/master/Backend/TuneSwitch/switch/views.py"
    click BE_Auth "https://github.com/anandhakrishnanaji/TuneSwitch/blob/master/Backend/TuneSwitch/switch/token_auth.py"
    click BE_Models "https://github.com/anandhakrishnanaji/TuneSwitch/blob/master/Backend/TuneSwitch/switch/models.py"
    click BE_Serial "https://github.com/anandhakrishnanaji/TuneSwitch/blob/master/Backend/TuneSwitch/switch/serializer.py"
    click Spotify "https://github.com/anandhakrishnanaji/TuneSwitch/blob/master/android/spotify-app-remote/spotify-app-remote-release-0.7.0.aar"
```
