How cleanengine/cleanengine-fe works
Project Type and Purpose
• Invest Future is a front-end web application built with React that combines SSR/SSG (for landing pages, SEO) and a SPA trade page, consuming real-time market data and exposing mock-investment functionality.
• Core features: real-time charts (AmCharts), order entry, chat, and simulated buy/sell bots that interpolate between user actions and live market data via Stomp.js.
File Structure
• Top-level configs: Dockerfile, vite.config.ts, GitHub Actions workflows, Sonar, Husky hooks → indicates containerized build & CI pipeline.
• src/app/entry.server.tsx & entry.client.tsx + react-router.config.ts → SSR server & client hydration using React Router v7 in “framework mode.”
• FSD pattern: src/entities, src/features, src/shared, src/widgets → high-cohesion, feature-based modules.
• Real-time / API layers:
• REST API clients under src/entities/*/api/*.endpoint.ts and src/features/*/api/*
• WebSocket (Stomp) provider under src/app/provider/StompProvider.tsx
• Mocking layer: src/mocks (MSW handlers) for dev/testing.
• State machines: XState models under features like chat/model/chat.machine.ts, order/models/form.machine.ts.
Extract Key Architectural Insights from README
• Event-Driven Modeling: UI state is managed by XState machines.
• Feature Sliced Design: Modules grouped by domain (entities, features, shared, widgets).
• Hybrid Rendering: SSR/SSG + SPA for /trade.
• Real-Time Communication: AmCharts + Stomp.js.
• Bots: Backend bots reconcile divergence between simulated and live data.
Main Components
A. Client Browser
• Initial load → SSR HTML
• Hydration → React Router switch
• Trade page → full SPA for dynamic charts & order entry
• Other pages → SSR/SSG served content
B. Front-end Application
• Server Node (instrument.server.mjs + Vite SSR plugin)
• Client Bundle (Vite build output served as static assets)
C. API Layer
• REST Endpoints: /coin, /order, /session, /user, /chat
• Auth Service: Kakao Login API
D. WebSocket (Stomp) Server
• Streams real-time market data → order book, trades
E. Market-Simulation Bots (external microservice or part of API)
• Interpolates divergence by auto-trading on real market
F. 3rd-Party Services
• Real Market Data Provider
• Kakao OAuth
G. Dev/Test Tooling
• MSW mocks (browser & node)
• CI/CD (GitHub Actions)
• Docker containerization
Relationships & Data Flows
1. Browser requests page → SSR Server renders HTML via entry.server.tsx.
2. HTML + JS → Browser hydrates client bundle (entry.client.tsx).
3. For /trade route: SPA kicks in, subscribes to Stomp WebSocket for live ticks & order book.
4. User Actions (order submission, chat messages) → REST POST to API Server.
5. API Server triggers backend bots if chart divergence > threshold → places real trades via Market Data Provider.
6. Market Data Provider & API Server push updates via WebSocket → front-end XState machines update UI.
7. Auth flows via Kakao → OAuth redirects → session endpoint → user context provider.
Architectural Patterns & Principles
• Event-Driven State Machines (XState) for robust UI flows.
• Feature-Sliced Design for modular, high-cohesion code.
• Hybrid SSR/SPA leveraging React Router framework mode.
• Facade Layers: httpClient.tsx abstracts REST calls, StompProvider abstracts WS.
• Mock-First: MSW intercepts API calls in dev/test.
Don’t Overthink—Be Detailed
• Folder/module to a component if it has its own runtime role (e.g., XState machine → “Event-Driven State Layer”).
• SSR server, client router, REST facade, WebSocket connector, charting library, state machines, API server, bots, external providers.