# opficdev/swiftui_starbridge architecture

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

- Interactive diagram: https://gitdiagram.com/opficdev/swiftui_starbridge
- Repository: https://github.com/opficdev/swiftui_starbridge

## Overview

##### Project Type and Purpose
- This is a full‑stack mobile application:
- Frontend: iOS app built with SwiftUI (incl. Social Login via Firebase/Kakao).
- Backend/API: Python Flask service exposing endpoints to the app.
- Data‑processing service: Python scripts crawling X.com and cleansing data via ChatGPT API, then persisting to MySQL (via SQLAlchemy).
- Persistence: AWS EC2‑hosted MySQL database.

##### File Structure Analysis
- Top‑level directories:
- DB/ – periodic data‐ingestion & processing scripts (cafe_db.py, x_db.py).
- api/ – Flask application (api.py), configuration (config.py), deployment scripts (gunicorn.py, cmd.sh).
- iOS/ – SwiftUI app source, assets, SocialLogin MVVM modules, Storyboard‑style entry points.
- Patterns & Config:
- iOS uses MVVM and SwiftUI views under SocialLogin and ContentView directories.
- Flask follows a single‐module MVC lite pattern (api.py handles routes, config.py for settings).
- SQLAlchemy models live inside DB scripts for schema creation & migrations.
- Deployment: gunicorn.py indicates WSIGI entrypoint.

##### README Insights
- Confirms the three pillars: SwiftUI frontend, Python/Flask backend/API, MySQL via SQLAlchemy.
- Describes data‑flow for “생일 카페” crawler: crawl JSON → cleanse (dedupe, format dates) → SQLAlchemy → MySQL → log to .txt.
- Documents 4 API “Content” operations: bboard, cafe, image, x.

a. Main Components
1. External Services
– X.com crawler target
– OpenAI ChatGPT API
– OAuth providers (Firebase Auth, Kakao)
2. Data‑Ingestion Service (DB/)
– cafe_db.py & x_db.py run on a scheduler (every 30 min)
– Perform crawling, call ChatGPT for cleanup
– Use SQLAlchemy to upsert into MySQL
– Emit JSON logs to .txt
3. Persistence Layer
– AWS EC2 – MySQL database instance
– Two domains: “생일 카페” tables & “게시판” tables
4. Backend/API Service (api/)
– Flask app (api.py) behind Gunicorn
– Routes parse “Content” field, query MySQL, return JSON or images
5. iOS Mobile App (iOS/)
– SwiftUI Views & MVVM (ContentView, SocialLogin modules)
– Social login flow → OAuth providers → FirebaseAuth/Kakao SDK
– HTTP client calls Flask API endpoints
– Renders lists, details, forms
b. Relationships & Data Flow
1. Crawling Service → (ChatGPT API) → Data processing → SQLAlchemy → MySQL
2. Crawling Service → JSON log files (.txt) for monitoring
3. iOS App → HTTP(S) requests → Flask API → MySQL → Back to iOS
4. iOS App ↔ OAuth providers (Firebase/Kakao) for login
5. Flask API → serves image files from disk per “image” requests
c. Architectural Patterns
- Scheduler + ETL (Extract/Transform/Load) for crawling
- MVC‐lite for Flask (controllers in api.py, models via SQLAlchemy)
- MVVM + SwiftUI for iOS
- REST‐style API with content‐driven routing
d. Key Technologies
- SwiftUI, Combine (or standard networking) on iOS
- Python 3.x, Flask, Gunicorn, SQLAlchemy on backend
- MySQL on AWS EC2
- ChatGPT API for NLP cleansing
- FirebaseAuth & Kakao SDK for Social Login

## Diagram (Mermaid)

```mermaid
flowchart TD
    %% External Services
    subgraph "External Services" 
        direction TB
        Xcom["X.com (Target)"]:::external
        ChatGPTAPI["ChatGPT API"]:::external
        FirebaseAuth["Firebase Auth"]:::external
        KakaoAPI["Kakao OAuth API"]:::external
    end

    %% ETL Layer
    subgraph "ETL Layer" 
        direction TB
        CafeDB["cafe_db.py\nScheduler ETL\nEvery 30 min"]:::etl
        XDB["x_db.py\nScheduler ETL\nEvery 30 min"]:::etl
        Logs[".txt Logs"]:::etl
    end

    %% Persistence Layer
    subgraph "Persistence Layer"
        direction TB
        MySQL["MySQL DB\nAWS EC2"]:::db
    end

    %% API Service
    subgraph "Backend/API Service"
        direction TB
        FlaskApp["Flask + Gunicorn\napi.py, config.py"]:::api
        DeployScripts["gunicorn.py, cmd.sh"]:::api
    end

    %% Mobile App
    subgraph "iOS Mobile App"
        direction TB
        AppEntry["StarBridgeApp.swift"]:::mobile
        ContentModule["ContentView Modules\n(BulletinBoard, Cafe, Profile, Schedule)"]:::mobile
        SocialLoginModel["SocialLogin Model\n(FirebaseFirestoreSwift.swift,\nKakaoAuthVM.swift,\nMyFirestore.swift,\nUserInfo.swift)"]:::mobile
        SocialLoginView["SocialLogin Views\n(HomeView.swift,\nLoginView.swift,\nProfileSetupView.swift,\nSocialLoginButtonView.swift)"]:::mobile
        SocialLoginDelegate["SocialLogin Delegate\n(MyAppDelegate.swift,\nMySceneDelegate.swift)"]:::mobile
        GlobalConfig["Global.swift\napi.swift"]:::mobile
        XcodeProj["StarBridge.xcodeproj"]:::mobile
    end

    %% Connections: ETL
    Xcom -->|"Crawl JSON\nEvery 30 min"| CafeDB
    Xcom -->|"Crawl JSON\nEvery 30 min"| XDB
    CafeDB -->|"Cleanup Data"| ChatGPTAPI
    XDB -->|"Cleanup Data"| ChatGPTAPI
    ChatGPTAPI -->|"Clean Data"| CafeDB
    ChatGPTAPI -->|"Clean Data"| XDB
    CafeDB -->|"Upsert via SQLAlchemy"| MySQL
    XDB -->|"Upsert via SQLAlchemy"| MySQL
    CafeDB -->|"Emit Logs"| Logs
    XDB -->|"Emit Logs"| Logs

    %% Connections: API
    AppEntry -->|"Launch App"| ContentModule
    AppEntry -->|"Launch App"| SocialLoginView
    SocialLoginView -->|"SDK Calls\nOAuth tokens"| FirebaseAuth
    SocialLoginView -->|"SDK Calls\nOAuth tokens"| KakaoAPI
    ContentModule -->|"HTTP(S) REST"| FlaskApp
    FlaskApp -->|"Query/Insert"| MySQL
    FlaskApp -->|"HTTP(S) REST"| ContentModule
    FlaskApp -->|"Serve Images"| ContentModule
    DeployScripts -->|Runs| FlaskApp

    %% Styles
    classDef etl fill:#FFE5B4,stroke:#E69138,stroke-width:1px
    classDef api fill:#ADD8E6,stroke:#2B64A7,stroke-width:1px
    classDef mobile fill:#90EE90,stroke:#2E8B57,stroke-width:1px
    classDef external fill:#D3D3D3,stroke:#696969,stroke-width:1px
    classDef db fill:#F0E68C,stroke:#C2B280,stroke-width:1px

    %% Click Events
    click CafeDB "https://github.com/opficdev/swiftui_starbridge/blob/main/DB/cafe_db.py"
    click XDB "https://github.com/opficdev/swiftui_starbridge/blob/main/DB/x_db.py"
    click FlaskApp "https://github.com/opficdev/swiftui_starbridge/blob/main/api/api.py"
    click DeployScripts "https://github.com/opficdev/swiftui_starbridge/blob/main/api/gunicorn.py"
    click DeployScripts "https://github.com/opficdev/swiftui_starbridge/blob/main/api/cmd.sh"
    click AppEntry "https://github.com/opficdev/swiftui_starbridge/blob/main/iOS/StarBridgeApp.swift"
    click ContentModule "https://github.com/opficdev/swiftui_starbridge/tree/main/iOS/StarBridge/ContentView/"
    click SocialLoginModel "https://github.com/opficdev/swiftui_starbridge/tree/main/iOS/StarBridge/SocialLogin/Model/"
    click SocialLoginView "https://github.com/opficdev/swiftui_starbridge/tree/main/iOS/StarBridge/SocialLogin/View/"
    click SocialLoginDelegate "https://github.com/opficdev/swiftui_starbridge/tree/main/iOS/StarBridge/SocialLogin/Delegate/"
    click GlobalConfig "https://github.com/opficdev/swiftui_starbridge/blob/main/iOS/StarBridge/Global.swift"
    click GlobalConfig "https://github.com/opficdev/swiftui_starbridge/blob/main/iOS/StarBridge/api.swift"
    click XcodeProj "https://github.com/opficdev/swiftui_starbridge/blob/main/iOS/StarBridge.xcodeproj"
```
