# rexaintreal/syna architecture

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

- Interactive diagram: https://gitdiagram.com/rexaintreal/syna
- Repository: https://github.com/rexaintreal/syna

## Overview

##### Project type and purpose
- Project Type: Full-stack social music web application
- Purpose: Let users log in with Spotify, analyze their listening habits, and match them with other users via a cosine-similarity algorithm

##### File structure
- Top-Level Files
– app.py: Flask application entry point; defines routes, OAuth callbacks, renders templates
– clean.py: Utility script (likely for maintenance or cleanup tasks)
– requirements.txt: Python dependencies (Flask, spotipy or requests, SQLite driver, etc.)
- Directories
– static/assets: CSS (Tailwind), images (logo, screenshots), webmanifest, Spotify branding assets
– templates: Jinja2 HTML templates (login, setup, dashboard, top-charts, settings, feedback, privacy, terms)
– utils: Business-logic modules
· db.py: Database connection and ORM or raw SQL helpers for SQLite
· matcher.py: Core cosine-similarity algorithm to compare user music profiles
· match_cache.py: Caching layer to store computed matches and reduce recomputation
- Configuration & Deployment
– .gitignore, LICENSE, README.md
– Hosting: PythonAnywhere; environment variables for Spotify OAuth in a .env file

##### README for additional insights
- Tech Stack:
– Frontend: HTML + Tailwind CSS
– Backend: Flask (Python 3.8+)
– DB: SQLite
– Auth: Spotify OAuth 2.0
– Algorithm: Cosine Similarity
- Features: user profiles, top-charts page, matching, settings, feedback

a. Main components
1. User & Browser (UI Client)
2. Frontend Layer (templates + Tailwind assets served by Flask)
3. Flask Application Server
– Route Handler (app.py)
– Business Logic (utils/matcher.py, utils/match_cache.py)
– Data Access Layer (utils/db.py)
4. SQLite Database
5. External Service: Spotify API & OAuth2 Provider
6. Hosting Environment: PythonAnywhere (optional annotation)
b. Relationships & interactions
- User/browser → HTTP(S) → Flask Server
- Flask Server ↔ SQLite (read/write user profiles, top-charts, cached matches)
- Flask Server ↔ Spotify API (OAuth handshake, fetch listening data, refresh tokens)
- Matcher module reads from DB and calculates similarity; writes output back to DB or cache
- Server renders dynamic pages via Jinja2 templates injecting data from DB & match results
c. Architectural patterns & design principles
- MVC-style separation:
– Views: Jinja2 templates under /templates
– Controllers: Flask route functions in app.py
– Model/Data Access: utils/db.py
- Layered architecture: Presentation, Application Logic, Data Access, External Services
- Caching layer (utils/match_cache.py) to improve performance of expensive similarity computations
d. Key technologies & frameworks
- Flask 2.x (WSGI web framework)
- Tailwind CSS for styling
- SQLite (file-based relational DB)
- Spotify OAuth 2.0 / REST API
- Python libraries: spotipy or requests, numpy or custom math functions for cosine similarity

##### Detail without over-fragmentation
- Every logical component: UI, static assets, route handlers, matcher/cache, DB, external API
- Do not delve into individual CSS classes or every single template—group them as “UI layer”
- Caching layer separately from raw matching logic to highlight performance design

## Diagram (Mermaid)

```mermaid
flowchart TD
    %% Title
    title["Syna System Architecture"]

    %% User
    User["User & Browser"]:::user

    %% Frontend Layer
    subgraph "Frontend Layer"
        direction TB
        StaticAssets["Static Assets"]:::frontend
        Templates["HTML Templates"]:::frontend
    end

    %% Flask Application Server
    subgraph "Flask Application Server"
        direction TB
        AppPy["app.py\n(Route Handlers & OAuth)"]:::backend
        CleanPy["clean.py"]:::backend
        DBLayer["utils/db.py"]:::backend
        Matcher["utils/matcher.py"]:::backend
        MatchCache["utils/match_cache.py"]:::backend
    end

    %% Data Layer
    DB["SQLite Database"]:::database

    %% External Services
    Spotify["Spotify API & OAuth2"]:::external

    %% Configuration & Documentation
    subgraph "Configuration & Documentation"
        direction TB
        Requirements["requirements.txt"]:::config
        Gitignore[".gitignore"]:::config
        License["LICENSE"]:::config
        Readme["README.md"]:::config
    end

    %% Connections
    User -->|"HTTPS Request"| AppPy
    AppPy -->|"Serves Static"| StaticAssets
    AppPy -->|"Renders Templates"| Templates
    AppPy -->|"Uses DB Layer"| DBLayer
    DBLayer -->|"SQL Queries"| DB

    AppPy -->|"Invokes Matcher"| Matcher
    Matcher -->|"Reads/Writes"| DB
    AppPy -->|"Uses Cache"| MatchCache
    MatchCache -->|"Reads/Writes"| DB

    AppPy -->|"OAuth & Data Fetch"| Spotify
    Spotify -->|"Tokens & User Data"| AppPy

    CleanPy -->|"Maintenance Tasks"| DB

    Requirements --> AppPy
    Gitignore --> AppPy
    License --> AppPy
    Readme --> AppPy

    %% Click Events
    click StaticAssets "https://github.com/rexaintreal/syna/tree/main/static/assets/"
    click Templates "https://github.com/rexaintreal/syna/tree/main/templates/"
    click AppPy "https://github.com/rexaintreal/syna/blob/main/app.py"
    click CleanPy "https://github.com/rexaintreal/syna/blob/main/clean.py"
    click Matcher "https://github.com/rexaintreal/syna/blob/main/utils/matcher.py"
    click MatchCache "https://github.com/rexaintreal/syna/blob/main/utils/match_cache.py"
    click DBLayer "https://github.com/rexaintreal/syna/blob/main/utils/db.py"
    click Requirements "https://github.com/rexaintreal/syna/blob/main/requirements.txt"
    click Gitignore "https://github.com/rexaintreal/syna/blob/main/.gitignore"
    click License "https://github.com/rexaintreal/syna/tree/main/LICENSE"
    click Readme "https://github.com/rexaintreal/syna/blob/main/README.md"

    %% Styles
    classDef user fill:#ddf,stroke:#333,stroke-width:1px
    classDef frontend fill:#dfd,stroke:#333,stroke-width:1px
    classDef backend fill:#def,stroke:#333,stroke-width:1px
    classDef database fill:#fdc,stroke:#333,stroke-width:1px
    classDef external fill:#d0d,stroke:#333,stroke-width:1px
    classDef config fill:#eee,stroke:#333,stroke-width:1px
```
