How cozy/cozy-drive works
Project type and purpose
• This is a single-page application (SPA) written in React, built to serve as the frontend “Drive” app of the Cozy platform. Its goal is to let users browse, upload, share, and edit files and folders, integrating deeply with the Cozy backend (“cozy-stack”) and external services like OnlyOffice and Nextcloud.
High-level architecture components
a. User’s Browser (Client)
b. Frontend Application
• React component tree under src/components & src/modules
• State management (Redux-style) in src/store (configureStore, rootReducer)
• Custom Hooks in src/hooks
• Context providers in src/lib (e.g., DriveProvider, ModalContext)
• Feature modules (e.g., upload, viewer, search, nextcloud integrations)
• I18n layer via Transifex and src/locales
c. API Client
• cozy-client-js used by the app to call cozy-stack HTTP/JSON endpoints
• Web Push (pushClient) for real-time updates
d. External Services
• OnlyOffice server for document editing (embedded via src/modules/views/OnlyOffice)
• Nextcloud APIs for mounting external drives
e. Backend (cozy-stack)
• Hosts the REST API endpoints, authentication, file storage, sharing logic
• Mailing service (MailHog in dev) for sharing flows
f. Build & Deployment
• rsbuild/webpack config under rsbuild.config.mjs & babel.config.js
• Targets: browser, public, intents, services
• CI/CD pipelines in .github/workflows (ci-cd.yml, codeql-analysis.yml)
Relationships & dataflows
• Browser ⇄ React SPA: user actions trigger component updates
• SPA → cozy-client-js → cozy-stack API: fetch folder entries, upload/download files, share/unshare, search
• SPA → Web Push endpoint → pushClient listener → update UI in real time
• SPA ↔ OnlyOffice via iframe/embed URL + postMessage callbacks for live document editing
• SPA ↔ Nextcloud via dedicated Nextcloud API hooks to display and operate on Nextcloud drives
• CI/CD: Source code → GitHub Actions → build artifacts → cozy-stack serve (dev) or static hosting (prod)
Architectural patterns & design principles
• Modular, feature-based folder structure under src/modules for separation of concerns
• Presentational vs. container components; Hooks for logic reuse
• Context API + custom providers for cross-cutting concerns (modal management, theming)
• Redux-style store, actions, and selectors for global state
• Hot Module Replacement and code splitting by entry point (browser, public)
• Testing strategy using Jest with setup in jest.config.js and jestHelpers
Technologies & frameworks
• React + JSX/TSX, Babel, Webpack/rsbuild
• Redux (store) + redux-thunk or sagas (async actions in src/modules)
• Jest + chai + sinon for unit/integration tests
• Stylus for styling (src/styles & .styl files in modules)
• Transifex CLI for i18n
• Yarn as package manager, GitHub Actions for CI