4.6 KiB
Development Overview
The purpose of this document is to provide a general overview of the application architecture.
Technologies
Insomnia is a desktop application built on top of Electron. Electron provides a Chromium runtime for the Insomnia web app to run inside of, as well as additional tools to provide access to operating system features.
There are a few more technologies and tools worth mentioning:
Reactis the library used for all UI components.styled-componentsandLessare used for styling UI components.Electron Builderis used to help build, sign, and package Insomnia for distribution.Flowis used for adding types to the codebase. Not everything is Flow but all new code should be typed with Flow.Webpackis the bundler used to compile the JS/Less/babel/etclibcurlis the library that Insomnia uses to make requests. Libcurl is the HTTP client of choice because it allows the deepest amount of debuggability and control of HTTP requests.nedba local in-memory database.node-libcurlis a NodeJS wrapper around the native libcurl library.Codemirroris a web-based, extendable, code editor used for highlighting and linting of data formats like JSON, GraphQL, and XML.Commander.jsis used for building the inso CLI.
Project Structure
Insomnia uses lerna to manage multiple npm packages within a single
repository. There are currently two package locations:
/packagescontains related packages that are consumed byinsomnia-appor externally./pluginscontains plugin packages that are included by default with the application.
The insomnia-app Main Package
/packages/insomnia-app is the entry point for the app. All other packages are imported from this
one.
There are a few notable directories inside of it:
/main.development.jsEntry for Electron./app/mainStuff that runs inside Electron's main process./app/uiReact components and styling./app/commonUtilities used across both main and render processes./app/pluginsLogic around installation and usage of plugins./app/modelsDB models used to store user data./app/networkSending requests and performing auth (eg. OAuth 2)./app/templatingNunjucks and rendering related code./app/sync(-legacy)?and/app/accountsTeam sync and account stuff.
Data and State Architecture
Insomnia stores data in a few places:
- A local in-memory NeDB database stores data for data models (requests, folder, workspaces, etc).
- A local Redux store contains an in-memory copy of all database entities.
- Multiple React Context stores, defined in
/app/ui/context.
Eventually, Redux could/should be removed, which would both reduce memory overhead and simplify the codebase. NeDB should essentially replace it
Automated testing
We use Jest and react-testing-library to write our unit tests, and Spectron for integration tests.
Unit tests exist alongside the file under test. For example:
/app/common/database.jscontains the database business logic/app/common/__tests__/database.test.jscontains the database tests
Unit tests for components follow the same pattern.
The structure for smoke tests is explained in the smoke testing package: packages/insomnia-smoke-test.
Technical Debt
This is just a brief summary of Insomnia's current technical debt.
- Loading large responses (~20MB) can crash the app on weaker hardware.
- An in-memory duplicate of the local DB is stored in Redux, unnecessarily doubling memory usage. Moving forward, Redux shouldn't need to be considered much and may be able to be removed eventually.
- Bundling
libcurl(native module) has caused many weeks of headaches trying to get builds working across Windows, Mac, and Linux. More expertise here is definitely needed. - All input fields that support templating/autocomplete/etc are actually Codemirror instances. This isn't really debt but may affect things going forward.
- Use of
libcurlmeans Insomnia can't run in a web browser and can't support bidirectional socket communication.