# paritosh-j/cheap-chats architecture

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

- Interactive diagram: https://gitdiagram.com/paritosh-j/cheap-chats
- Repository: https://github.com/paritosh-j/cheap-chats

## Overview

##### Project Type and Purpose
- This is a full-stack, mobile-first, real-time group chat application (“Cheap Chats”), built as a single-page React/Vite frontend and a Spring Boot backend exposing both REST and WebSocket (STOMP/SockJS) endpoints.
- Users create temporary chat groups via REST, then exchange messages in real time via WebSockets.

##### High-Level File-Structure Analysis
- Top level:
- backend/ — Spring Boot project (Maven) with config, controllers, DTOs, models, repositories, services, resources, tests
- frontend/ — Vite + React + TypeScript SPA with TailwindCSS, organized into pages, components, services (api, socket), types, assets
- Key patterns:
- Backend follows MVC + Service + Repository layers (Spring Data JPA)
- Frontend follows component-based SPA structure with service modules for HTTP and WebSocket logic

##### README Insights
- Real-time messaging via WebSocket STOMP + SockJS
- REST endpoints for login, group management
- H2 or PostgreSQL for persistence
- Tech stack calls out React/Vite, Tailwind, Spring Boot 3, Spring Data JPA, WebSocket STOMP

##### Main Components
a. Frontend Client (Browser)
- UI (pages & components in React)
- REST Client (axios or fetch)
- WebSocket Client (STOMP over SockJS)
b. Backend Application Server
- REST Controllers (ChatController, GroupController)
- WebSocket Config & Message Endpoints
- Service Layer (business logic)
- Repository Layer (Spring Data JPA -> H2/PostgreSQL)
c. Database
- H2 (in-memory) or PostgreSQL
d. External/Infrastructure Services
- (Optional) Load Balancer or API Gateway
- (Optional) STOMP message broker (embedded in Spring or external)

##### Relationships & Data-Flow
- Browser → REST API (HTTP/HTTPS) → Spring Boot Controllers → Service → Repository → Database
- Browser ↔ WebSocket Server (STOMP/SockJS) → Message Broker → Spring Message Handlers → Service → Broadcast to subscribed clients
- Sequence examples:
1. Login via POST /api/login
2. Establish WebSocket handshake at /ws-endpoint
3. Subscribe to /topic/group/{groupName}
4. Send chat messages to /app/chat/{groupName}

##### Architectural Patterns & Design Principles
- Layered Architecture (Controller → Service → Repository)
- Single-Page Application (SPA) with separation of UI, API service, socket service
- Event-driven real-time messaging (publish/subscribe via STOMP)
- Temporary resource lifecycle (chat groups with TTL)

##### Technologies & Frameworks Callout
- Frontend: React, Vite, TypeScript, TailwindCSS, STOMP client over SockJS
- Backend: Spring Boot 3, Spring MVC, Spring WebSocket (STOMP), Spring Data JPA, Maven
- Database: H2 (dev) or PostgreSQL (prod)

## Diagram (Mermaid)

```mermaid
flowchart TB
    %% Frontend Layer
    subgraph "Frontend Client (Browser)"
        direction TB
        Pages["UI Pages"]:::frontend
        Components["UI Components"]:::frontend
        APIService["REST Client Service"]:::frontend
        SocketService["WebSocket Client Service"]:::frontend
        Types["Type Definitions"]:::frontend
    end

    %% Backend Application Server
    subgraph "Backend Application Server"
        direction TB
        App["Main Application Entry"]:::backend

        subgraph "Configuration"
            direction TB
            WSConfig["WebSocketConfig"]:::config
            SecConfig["SecurityConfig"]:::config
        end

        subgraph "Controllers"
            direction TB
            ChatCtrl["ChatController"]:::controller
            GroupCtrl["GroupController"]:::controller
        end

        subgraph "Services"
            direction TB
            GroupServiceI["GroupService Interface"]:::service
            GroupServiceImpl["GroupServiceImpl"]:::service
        end

        subgraph "Repositories"
            direction TB
            ChatGroupRepo["ChatGroupRepository"]:::repo
            ChatMsgRepo["ChatMessageRepository"]:::repo
            UserRepo["UserRepository"]:::repo
        end

        subgraph "Models"
            direction TB
            ChatGroup["ChatGroup"]:::model
            ChatMessage["ChatMessage"]:::model
            User["User"]:::model
        end

        subgraph "DTOs & Properties"
            direction TB
            ChatMessageDto["ChatMessageDto"]:::dto
            ApplicationProps["application.properties"]:::config
        end
    end

    %% Database
    Database["H2/PostgreSQL Database"]:::db

    %% Connections - REST
    Pages -->|"uses API"| APIService
    Components -->|"uses API"| APIService
    APIService -->|"HTTP/HTTPS"| ChatCtrl
    APIService -->|"HTTP/HTTPS"| GroupCtrl
    ChatCtrl -->|"calls"| GroupServiceI
    GroupCtrl -->|"calls"| GroupServiceI
    GroupServiceI -->|"implemented by"| GroupServiceImpl
    GroupServiceImpl -->|"uses"| ChatGroupRepo
    GroupServiceImpl -->|"uses"| ChatMsgRepo
    GroupServiceImpl -->|"uses"| UserRepo
    ChatGroupRepo -->|"CRUD"| Database
    ChatMsgRepo -->|"CRUD"| Database
    UserRepo -->|"CRUD"| Database

    %% Connections - WebSocket
    SocketService -->|"WSS/STOMP"| WSConfig
    WSConfig -->|"maps endpoints"| ChatCtrl
    ChatCtrl -->|"@MessageMapping"| GroupServiceImpl
    GroupServiceImpl -->|"uses"| ChatGroupRepo
    GroupServiceImpl -->|"uses"| ChatMsgRepo
    ChatCtrl -->|"broadcasts"| SocketService

    %% Click Events - Frontend
    click Pages "https://github.com/paritosh-j/cheap-chats/tree/main/frontend/src/pages"
    click Components "https://github.com/paritosh-j/cheap-chats/tree/main/frontend/src/components"
    click APIService "https://github.com/paritosh-j/cheap-chats/blob/main/frontend/src/services/api.ts"
    click SocketService "https://github.com/paritosh-j/cheap-chats/blob/main/frontend/src/services/socket.ts"
    click Types "https://github.com/paritosh-j/cheap-chats/blob/main/frontend/src/types/index.ts"

    %% Click Events - Backend
    click App "https://github.com/paritosh-j/cheap-chats/blob/main/backend/src/main/java/com/paritosh/cheapchats/App.java"
    click ChatCtrl "https://github.com/paritosh-j/cheap-chats/blob/main/backend/src/main/java/com/paritosh/cheapchats/controller/ChatController.java"
    click GroupCtrl "https://github.com/paritosh-j/cheap-chats/blob/main/backend/src/main/java/com/paritosh/cheapchats/controller/GroupController.java"
    click WSConfig "https://github.com/paritosh-j/cheap-chats/blob/main/backend/src/main/java/com/paritosh/cheapchats/config/WebSocketConfig.java"
    click SecConfig "https://github.com/paritosh-j/cheap-chats/blob/main/backend/src/main/java/com/paritosh/cheapchats/config/SecurityConfig.java"
    click GroupServiceI "https://github.com/paritosh-j/cheap-chats/blob/main/backend/src/main/java/com/paritosh/cheapchats/services/GroupService.java"
    click GroupServiceImpl "https://github.com/paritosh-j/cheap-chats/blob/main/backend/src/main/java/com/paritosh/cheapchats/services/impl/GroupServiceImpl.java"
    click ChatGroupRepo "https://github.com/paritosh-j/cheap-chats/blob/main/backend/src/main/java/com/paritosh/cheapchats/repositories/ChatGroupRepository.java"
    click ChatMsgRepo "https://github.com/paritosh-j/cheap-chats/blob/main/backend/src/main/java/com/paritosh/cheapchats/repositories/ChatMessageRepository.java"
    click UserRepo "https://github.com/paritosh-j/cheap-chats/blob/main/backend/src/main/java/com/paritosh/cheapchats/repositories/UserRepository.java"
    click ChatGroup "https://github.com/paritosh-j/cheap-chats/blob/main/backend/src/main/java/com/paritosh/cheapchats/models/ChatGroup.java"
    click ChatMessage "https://github.com/paritosh-j/cheap-chats/blob/main/backend/src/main/java/com/paritosh/cheapchats/models/ChatMessage.java"
    click User "https://github.com/paritosh-j/cheap-chats/blob/main/backend/src/main/java/com/paritosh/cheapchats/models/User.java"
    click ChatMessageDto "https://github.com/paritosh-j/cheap-chats/blob/main/backend/src/main/java/com/paritosh/cheapchats/dto/ChatMessageDto.java"
    click ApplicationProps "https://github.com/paritosh-j/cheap-chats/blob/main/backend/src/main/resources/application.properties"

    %% Styles
    classDef frontend fill:#fde2e4,stroke:#b33a3a;
    classDef backend fill:#e2f0cb,stroke:#5a7d00;
    classDef config fill:#d0e6f5,stroke:#235789;
    classDef controller fill:#f5e1da,stroke:#ba5a31;
    classDef service fill:#f9f2d0,stroke:#c48e1f;
    classDef repo fill:#e3dafd,stroke:#6a4c93;
    classDef model fill:#d9ead3,stroke:#38761d;
    classDef dto fill:#ffe599,stroke:#b67607;
    classDef db fill:#ffefcc,stroke:#b45f06;
```
