# shotxd012/windapp architecture

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

- Interactive diagram: https://gitdiagram.com/shotxd012/windapp
- Repository: https://github.com/shotxd012/windapp

## Overview

##### Project type and purpose
- This is an Electron-based desktop chat application (“Windos Chat”) with a full-stack design:
- Frontend: React + Vite in the renderer process
- Backend: Embedded Express + Socket.IO server in the main process
- Database: MongoDB (local or Atlas)
- Purpose: Provide a Windows-style chat UI with login/registration, real-time messaging, custom title bar, and persistent storage.

##### File structure
- Top-level:
- package.json, tsconfig*, vite.config.ts – build & config files
- src/main/ – Electron main process + server
- src/renderer/ – React renderer process
- src/main/:
- config.ts – MongoDB & JWT secret
- main.ts – launches BrowserWindow, loads preload.ts
- preload.ts – IPC bridge between renderer & main
- server.ts – starts Express + Socket.IO on a local port
- src/renderer/:
- index.html + Vite entry
- src/pages/ – Login, Register, Chat pages
- src/components/ – Custom TitleBar, shared UI
- src/stores/ – authStore, chatStore (Zustand or similar) for state management

##### Important README insights
- Describes real-time messaging via Socket.IO
- MongoDB configuration options (local/Atlas/auth)
- Scripts for dev (`npm run dev`), build (`npm run build`), packaging (`npm run dist`)

##### Main components
a. Electron Main Process
– Responsibilities: create window, run preload, host Express/Socket.IO server
b. Preload Script (IPC Bridge)
– Exposes a limited, secure API from main → renderer
c. Express + Socket.IO Server
– API endpoints (REST for auth), WebSocket for chat events
d. React Renderer (BrowserWindow)
– UI pages, components, state stores
– Socket.IO client + HTTP client for auth
e. MongoDB Database
– Stores users, chat history
f. External Services (optional)
– MongoDB Atlas cluster

##### Relationships and interactions
- Renderer → Preload (IPC invoke) for any Electron-specific calls
- Renderer → Server (HTTP REST) for login/register → receives JWT
- Renderer ↔ Server (Socket.IO) for real-time chat events (message send/receive)
- Server → MongoDB (driver) for persistence and queries
- Main Process contains & orchestrates server + preload + window

##### Architectural patterns & design principles
- Separation of concerns:
- Main process for native/system tasks
- Preload for safe IPC
- Server for business logic & real-time comms
- Renderer for UI
- Layered architecture: UI ↔ API/Real-time ↔ Data
- State management in renderer via “stores”
- Configuration centralization in config.ts

##### Technologies & frameworks to annotate
- Electron (main, preload, renderer)
- Vite + React + TypeScript
- Express + Socket.IO
- MongoDB driver or Mongoose
- Zustand or custom store library

## Diagram (Mermaid)

```mermaid
flowchart TB
    %% Electron Main Process Zone
    subgraph "ELECTRON MAIN"
        direction TB
        Config["config.ts\n(MongoDB & JWT)"]:::core
        Main["Main Process\nmain.ts"]:::core
        Preload["Preload Script\npreload.ts"]:::core
    end

    %% Server & Database Zone
    subgraph "SERVER & DATABASE"
        direction TB
        Server["Express +\nSocket.IO Server\nserver.ts"]:::backend
        DB["MongoDB"]:::database
    end

    %% Renderer Zone
    subgraph "RENDERER (UI)"
        direction TB
        HTML["index.html"]:::frontend
        Entry["main.tsx"]:::frontend
        App["App.tsx\nApp.css"]:::frontend
        Components["TitleBar.tsx\nTitleBar.css"]:::frontend
        Login["Login.tsx"]:::frontend
        Register["Register.tsx"]:::frontend
        ChatPage["Chat.tsx"]:::frontend
        AuthStore["authStore.ts"]:::frontend
        ChatStore["chatStore.ts"]:::frontend
    end

    %% Connections: Electron Core
    Config --> Main
    Main --> Preload
    Main --> Server

    %% Connections: Server & DB
    Server --> DB

    %% Connections: Renderer Initialization
    HTML --> Entry
    Entry --> App
    App --> Components
    App --> Login
    App --> Register
    App --> ChatPage
    Login --> AuthStore
    Register --> AuthStore
    ChatPage --> ChatStore

    %% IPC and HTTP/WebSocket Flows
    Login -->|IPC invoke| Preload
    Register -->|IPC invoke| Preload
    ChatPage -->|IPC invoke| Preload

    Login -->|"HTTP /login"| Server
    Register -->|"HTTP /register"| Server
    ChatPage -->|"HTTP /auth"| Server

    ChatPage -.->|"Socket.IO connect"| Server
    ChatPage -.->|"Socket.IO message"| Server

    %% Click Events
    click Main "https://github.com/shotxd012/windapp/blob/main/src/main/main.ts"
    click Preload "https://github.com/shotxd012/windapp/blob/main/src/main/preload.ts"
    click Server "https://github.com/shotxd012/windapp/blob/main/src/main/server.ts"
    click Config "https://github.com/shotxd012/windapp/blob/main/src/main/config.ts"
    click Entry "https://github.com/shotxd012/windapp/blob/main/src/renderer/src/main.tsx"
    click HTML "https://github.com/shotxd012/windapp/blob/main/src/renderer/index.html"
    click App "https://github.com/shotxd012/windapp/blob/main/src/renderer/src/App.tsx"
    click Components "https://github.com/shotxd012/windapp/blob/main/src/renderer/src/components/TitleBar.tsx"
    click Login "https://github.com/shotxd012/windapp/blob/main/src/renderer/src/pages/Login.tsx"
    click Register "https://github.com/shotxd012/windapp/blob/main/src/renderer/src/pages/Register.tsx"
    click ChatPage "https://github.com/shotxd012/windapp/blob/main/src/renderer/src/pages/Chat.tsx"
    click AuthStore "https://github.com/shotxd012/windapp/blob/main/src/renderer/src/stores/authStore.ts"
    click ChatStore "https://github.com/shotxd012/windapp/blob/main/src/renderer/src/stores/chatStore.ts"

    %% Styles
    classDef frontend fill:#ADD8E6,stroke:#000
    classDef backend fill:#90EE90,stroke:#000
    classDef database fill:#FFA500,stroke:#000
    classDef core fill:#D3D3D3,stroke:#000
```
