# langochungdev/instar architecture

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

- Interactive diagram: https://gitdiagram.com/langochungdev/instar
- Repository: https://github.com/langochungdev/instar

## Overview

##### Project type and purpose
- This is a full-stack “Instagram clone” application:
- Backend: Spring Boot monolith exposing RESTful APIs, WebSocket chat, WebRTC signaling, JWT-based security.
- Frontend: VueJS SPA + Bootstrap, communicating via Axios, WebSocket, WebRTC.
- Database: SQL Server, with Redis for token blacklisting/possibly caching.

##### File structure
- Top-level directories:
- backend/ – Maven project with layered packages (config, common, feature/*, entity, repository, service, controller).
- frontend/ – Vue project organized by features (auth, device, init), plus global layouts, router, store, utils.
- TaiNguyen/ – miscellaneous docs, SQL scripts (instar.sql), design notes.
- Key config files:
- backend/src/main/resources/application.properties (DB, Redis, JWT settings)
- backend/src/main/java/.../config/*.java (WebMvcConfig, SecurityConfig, RedisConfig, WebSocketConfig)
- frontend/.env, vite.config.js, src/utils/firebase.js, axios.js.
- Deployment artifacts: Dockerfiles likely added in deploy scripts (not shown), CI/CD defined in project readme.

##### README for additional insight
- REST API endpoints across core domains: User, Post, Comment, Like, Follow, Save, Message, Notification, UserBehavior.
- Architectural notes: layered backend (Controller → Service → Repository → Entity), JWT & Spring Security, WebSocket for real-time, SQL Server schema, CI/CD on Ubuntu + Nginx.
- Frontend: Vue components organized by feature, real-time integrations.

##### Essential elements to capture
- All client interactions (login, feed, chat, call) mapped to API endpoints.
- Real-time flows separately drawn (WebSocket, WebRTC).
- Data persistence flows (CRUD ➔ SQL Server).
- Token lifecycle (Login → JWT issued → blacklist check via Redis on logout/refresh).
- CI/CD and deployment can be shown as an auxiliary pipeline if needed.

## Diagram (Mermaid)

```mermaid
flowchart TD
    %% Frontend Layer
    subgraph "Frontend Layer"
        direction TB
        Router["Vue Router"]:::frontend
        Store["Vuex Store"]:::frontend
        Axios["Axios HTTP Client"]:::frontend
        AuthUI["Auth Feature (Login/Register)"]:::frontend
        DeviceUI["Device Feature"]:::frontend
        InitUI["Init AuthCheck"]:::frontend
        ChatUI["Chat Module"]:::frontend
        CallUI["Call Module"]:::frontend
        FirebaseUtil["Firebase Messaging"]:::external
    end

    %% Backend Layer
    subgraph "Backend Layer"
        direction TB
        Entry["InstarApplication"]:::backend
        Props["application.properties"]:::backend

        subgraph "Config Layer"
            direction TB
            WebMvc["WebMvcConfig"]:::backend
            Security["SecurityConfig"]:::backend
            RedisCfg["RedisConfig"]:::backend
            WSCfg["WebSocketConfig"]:::backend
        end

        subgraph "API Layer (Controllers)"
            direction TB
            AuthCtrl["AuthController"]:::backend
            ChatCtrl["ChatController"]:::backend
            MsgCtrl["MessageController"]:::backend
            SignalCtrl["WebRTCSignalingController"]:::backend
        end

        subgraph "Service Layer"
            direction TB
            TBService["TokenBlacklistService"]:::backend
            JwtUtil["JwtUtil"]:::backend
        end
    end

    %% Data Stores
    SQL["SQL Server"]:::datastore
    RedisStore["Redis Cache"]:::datastore

    %% External Services
    FirebaseSrv["Firebase"]:::external
    STUNTURN["STUN/TURN Servers"]:::external

    %% Connections
    Axios -->|"HTTPS/REST"| AuthCtrl
    AuthUI -->|"HTTP/REST"| AuthCtrl
    DeviceUI -->|"HTTP/REST"| AuthCtrl
    InitUI -->|"HTTP/REST"| AuthCtrl

    ChatUI -->|"WSS/WebSocket"| ChatCtrl
    CallUI -->|"ICE (WebRTC)"| SignalCtrl

    AuthCtrl -->|"JWT operations"| JwtUtil
    AuthCtrl -->|"Blacklist check"| TBService
    TBService -->|"store tokens"| RedisStore
    AuthCtrl -->|"CRUD operations"| SQL
    ChatCtrl -->|"persist chat"| SQL
    MsgCtrl -->|"persist message"| SQL
    SignalCtrl -->|"signal negotiation"| STUNTURN
    AuthCtrl -->|"push notifications"| FirebaseSrv

    Router --> Store
    Store --> Axios
    Store --> FirebaseUtil

    %% Data Flow between Backend and Datastores
    JwtUtil -.-> RedisStore
    ServiceLayer["Service Layer"] -.-> SQL

    %% Click Events
    click Router "https://github.com/langochungdev/instar/blob/main/frontend/src/router/index.js"
    click Store "https://github.com/langochungdev/instar/blob/main/frontend/src/store/index.js"
    click Axios "https://github.com/langochungdev/instar/blob/main/frontend/src/utils/axios.js"
    click FirebaseUtil "https://github.com/langochungdev/instar/blob/main/frontend/src/utils/firebase.js"
    click AuthUI "https://github.com/langochungdev/instar/tree/main/frontend/src/features/auth"
    click DeviceUI "https://github.com/langochungdev/instar/tree/main/frontend/src/features/device"
    click InitUI "https://github.com/langochungdev/instar/blob/main/frontend/src/features/init/authCheck.js"
    click Entry "https://github.com/langochungdev/instar/blob/main/backend/src/main/java/com/instar/InstarApplication.java"
    click Props "https://github.com/langochungdev/instar/blob/main/backend/src/main/resources/application.properties"
    click WebMvc "https://github.com/langochungdev/instar/blob/main/backend/src/main/java/com/instar/config/WebMvcConfig.java"
    click Security "https://github.com/langochungdev/instar/blob/main/backend/src/main/java/com/instar/config/SecurityConfig.java"
    click RedisCfg "https://github.com/langochungdev/instar/blob/main/backend/src/main/java/com/instar/config/RedisConfig.java"
    click WSCfg "https://github.com/langochungdev/instar/blob/main/backend/src/main/java/com/instar/config/WebSocketConfig.java"
    click TBService "https://github.com/langochungdev/instar/blob/main/backend/src/main/java/com/instar/common/service/TokenBlacklistService.java"
    click JwtUtil "https://github.com/langochungdev/instar/blob/main/backend/src/main/java/com/instar/common/util/JwtUtil.java"
    click AuthCtrl "https://github.com/langochungdev/instar/blob/main/backend/src/main/java/com/instar/feature/auth/AuthController.java"
    click ChatCtrl "https://github.com/langochungdev/instar/blob/main/backend/src/main/java/com/instar/feature/chat/ChatController.java"
    click MsgCtrl "https://github.com/langochungdev/instar/blob/main/backend/src/main/java/com/instar/feature/chat/MessageController.java"
    click SignalCtrl "https://github.com/langochungdev/instar/blob/main/backend/src/main/java/com/instar/feature/chat/WebRTCSignalingController.java"

    %% Styles
    classDef frontend fill:#D6EFFF,stroke:#0288D1;
    classDef backend fill:#E3F2FD,stroke:#1976D2;
    classDef datastore fill:#E8F5E9,stroke:#388E3C,stroke-width:2px;
    classDef external fill:#FFF8E1,stroke:#F9A825,stroke-width:2px;
```
