How fahcode/xiaoshuo-native works
Project type and purpose
• This is a React Native mobile application (“xiaoshuo-native”), a novel/e-book reader for iOS and Android.
• It bundles JavaScript UI code, a Redux-based state layer, a native bridge (React Native runtime), and uses network calls plus local persistence (Realm) to fetch and cache book data.
File structure
• Top-level “android” and “ios” folders contain the native projects and entry-point code (MainActivity.java, AppDelegate.m).
• “src” holds all React Native JavaScript:
• components/ (stateless, presentational UI)
• containers/ (stateful, connect to Redux store)
• routers/ (navigation definitions)
• store/ (Redux actions, reducers, store configuration)
• util/ (network fetch, Realm wrapper, WebSocket helper, common styles)
• “App.js” and “index.js” bootstrap the JS app via Metro bundler.
• README describes build steps (react-native start, run-android, assembleRelease).
README for additional insights
• No backend code is included; the mobile app relies on remote HTTP APIs (via util/fetch.js) and/or WebSockets (util/Socket.js).
• It uses Realm for on-device data caching (util/realm.js).
Components
a. Main components
• Mobile UI Layer (React components + React Navigation)
• State Management Layer (Redux Store + Actions + Reducers)
• Data Layer
• Network Module (fetch.js)
• WebSocket Client (Socket.js)
• Local Persistence (Realm DB)
• Native Host (React Native Bridge on iOS & Android)
• External Services
• Book Data REST APIs
• Real-time update WebSocket server (if in use)
b. Relationships & interactions
1. User taps UI → container dispatches Redux action
2. Action middleware calls fetch.js or Socket.js → HTTP/WebSocket → external API
3. Response → action payload → reducer updates Redux store
4. Store update → container re-renders component → UI reflects new data
5. Selected data also written to Realm for offline caching → read from Realm when offline
6. Metro Bundler serves JS bundle at runtime; native host packages JS for release
c. Architectural patterns & design principles
• Flux/Redux unidirectional data flow: UI → Action → Reducer → Store → UI
• Separation of concerns:
• Presentational vs. Container components
• Network layer abstracted in util/fetch.js
• Persistence abstracted in util/realm.js
• Offline-first caching pattern: fallback to Realm if network unavailable
d. Key technologies
• React Native (JS runtime + native bridge)
• Redux (state container)
• Realm (local mobile database)
• JavaScript Fetch API & WebSockets
• Metro bundler (module resolution & hot reload)