2020-04-26 20:33:39 +00:00
# Development Overview
The purpose of this document is to provide a general overview of the application architecture.
## Technologies
2021-01-12 02:23:20 +00:00
Insomnia is a desktop application built on top of [Electron ](http://electronjs.org/ ). Electron
2020-04-26 20:33:39 +00:00
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:
2020-08-03 04:53:09 +00:00
- [`React` ](https://reactjs.org/ ) is the library used for all UI components.
2021-01-12 02:23:20 +00:00
- [`styled-components` ](https://styled-components.com/ ) and [`Less` ](http://lesscss.org/ ) are used
2020-12-17 11:54:30 +00:00
for styling UI components.
2020-04-26 20:33:39 +00:00
- [`Electron Builder` ](https://github.com/electron-userland/electron-builder ) is used to help build,
sign, and package Insomnia for distribution.
- [`Flow` ](https://flow.org/ ) is used for adding types to the codebase. Not everything is Flow but
all new code should be typed with Flow.
- [`Webpack` ](https://webpack.js.org/ ) is the bundler used to compile the JS/Less/babel/etc
2021-01-12 02:23:20 +00:00
- [`libcurl` ](https://curl.se/libcurl/ ) is 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.
2020-08-03 04:53:09 +00:00
- [`nedb` ](https://github.com/louischatriot/nedb ) a local in-memory database.
2021-08-24 00:21:19 +00:00
- [`node-libcurl` ](https://github.com/JCMais/node-libcurl ) is a Node.js wrapper around the native libcurl library.
2021-01-12 02:23:20 +00:00
- [`Codemirror` ](https://codemirror.net/ ) is a web-based, extendable, code editor used for
2020-04-26 20:33:39 +00:00
highlighting and linting of data formats like JSON, GraphQL, and XML.
2020-12-17 11:54:30 +00:00
- [`Commander.js` ](https://github.com/tj/commander.js ) is used for building the inso CLI.
2020-04-26 20:33:39 +00:00
## Project Structure
2021-01-12 02:23:20 +00:00
Insomnia uses [`lerna` ](https://lerna.js.org/ ) to manage multiple npm packages within a single
2020-04-26 20:33:39 +00:00
repository. There are currently two package locations:
2020-08-03 04:53:09 +00:00
- `/packages` contains related packages that are consumed by `insomnia-app` or externally.
- `/plugins` contains plugin packages that are included by default with the application.
2020-04-26 20:33:39 +00:00
## 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:
2020-08-03 04:53:09 +00:00
- `/main.development.js` Entry for Electron.
- `/app/main` Stuff that runs inside Electron's main process.
2020-12-17 11:54:30 +00:00
- `/app/ui` React components and styling.
2020-08-03 04:53:09 +00:00
- `/app/common` Utilities used across both main and render processes.
- `/app/plugins` Logic around installation and usage of plugins.
- `/app/models` DB models used to store user data.
- `/app/network` Sending requests and performing auth (eg. OAuth 2).
- `/app/templating` Nunjucks and rendering related code.
- `/app/sync(-legacy)?` and `/app/accounts` Team sync and account stuff.
2020-04-26 20:33:39 +00:00
## Data and State Architecture
Insomnia stores data in a few places:
2020-08-03 04:53:09 +00:00
- 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.
2020-12-17 11:54:30 +00:00
- Multiple React Context stores, defined in `/app/ui/context` .
2020-04-26 20:33:39 +00:00
*Eventually, Redux could/should be removed, which would both reduce memory overhead and simplify
the codebase. NeDB should essentially replace it*
2020-12-17 11:54:30 +00:00
## Automated testing
We use [Jest ](https://jestjs.io/ ) and [react-testing-library ](https://testing-library.com/docs/react-testing-library )
to write our unit tests, and [Spectron ](https://www.electronjs.org/spectron ) for integration tests.
Unit tests exist alongside the file under test. For example:
- `/app/common/database.js` contains the database business logic
- `/app/common/__tests__/database.test.js` contains 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` ](/packages/insomnia-smoke-test ).
2020-04-26 20:33:39 +00:00
## Technical Debt
2021-01-12 02:23:20 +00:00
This is just a brief summary of Insomnia's current technical debt.
2020-04-26 20:33:39 +00:00
2020-08-03 04:53:09 +00:00
- Loading large responses (~20MB) can crash the app on weaker hardware.
2021-01-12 02:23:20 +00:00
- An in-memory duplicate of the local DB is stored in Redux, unnecessarily doubling memory usage. Moving
2020-04-26 20:33:39 +00:00
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
2020-08-03 04:53:09 +00:00
isn't really debt but may affect things going forward.
2020-04-26 20:33:39 +00:00
- Use of `libcurl` means Insomnia can't run in a web browser and can't support bidirectional socket
2020-08-03 04:53:09 +00:00
communication.