# @symbiota2/backend

> API Server for Symbiota2

Latest version **0.0.3** (published 2020-10-20) · MIT license · 0 weekly downloads

> **Deprecated.** This package is deprecated.

## Install

```sh
npm install @symbiota2/backend
pnpm add @symbiota2/backend
yarn add @symbiota2/backend
bun add @symbiota2/backend
```

## Health

**Score 10/100 (F)** — status: deprecated.

Negative: deprecated.

## Facts

| | |
|---|---|
| Version | 0.0.3 |
| Published | 2020-10-20 |
| First published | 2020-10-13 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | bundled |
| Module format | CommonJS |
| Dependencies | 28 |
| Unpacked size | 2.5 MB |
| Known vulnerabilities | 0 (+9 in 5 direct dependencies) |
| Install scripts | no |
| Maintainers | evindunn |

## Links

- npm: https://www.npmjs.com/package/@symbiota2/backend
- Repository: https://gitlab.com/symbiota2/s2-typescript
- Homepage: https://gitlab.com/symbiota2/s2-typescript#readme
- Issues: https://gitlab.com/symbiota2/s2-typescript/issues
- npm.io page: https://npm.io/package/@symbiota2/backend

## Dependencies (28)

- [cors](https://npm.io/package/cors.md) ^2.8.5
- [glob](https://npm.io/package/glob.md) ^7.1.6
- [rxjs](https://npm.io/package/rxjs.md) ^6.5.4
- [mysql](https://npm.io/package/mysql.md) ^2.18.1
- [helmet](https://npm.io/package/helmet.md) ^4.1.1
- [rimraf](https://npm.io/package/rimraf.md) ^3.0.2
- [core-js](https://npm.io/package/core-js.md) ^3.6.5
- [sqlite3](https://npm.io/package/sqlite3.md) ^5.0.0
- [ts-node](https://npm.io/package/ts-node.md) ^9.0.0
- [typeorm](https://npm.io/package/typeorm.md) ^0.2.28
- [argparse](https://npm.io/package/argparse.md) ^2.0.1
- [passport](https://npm.io/package/passport.md) ^0.4.1
- [@nestjs/cli](https://npm.io/package/@nestjs/cli.md) ^7.5.1
- [@nestjs/jwt](https://npm.io/package/@nestjs/jwt.md) ^7.1.0
- [@nestjs/core](https://npm.io/package/@nestjs/core.md) ^7.0.0
- [passport-jwt](https://npm.io/package/passport-jwt.md) ^4.0.0
- [cookie-parser](https://npm.io/package/cookie-parser.md) ^1.4.5
- [@nestjs/common](https://npm.io/package/@nestjs/common.md) ^7.0.0
- [@nestjs/config](https://npm.io/package/@nestjs/config.md) ^0.5.0
- [passport-local](https://npm.io/package/passport-local.md) ^1.0.0
- [@nestjs/swagger](https://npm.io/package/@nestjs/swagger.md) ^4.6.0
- [class-validator](https://npm.io/package/class-validator.md) ^0.12.2
- [passport-cookie](https://npm.io/package/passport-cookie.md) ^1.0.8
- [@nestjs/passport](https://npm.io/package/@nestjs/passport.md) ^7.1.0
- [reflect-metadata](https://npm.io/package/reflect-metadata.md) ^0.1.13
- [class-transformer](https://npm.io/package/class-transformer.md) ^0.3.1
- [swagger-ui-express](https://npm.io/package/swagger-ui-express.md) ^4.1.4
- [@nestjs/platform-express](https://npm.io/package/@nestjs/platform-express.md) ^7.0.0

## Recent versions

- 0.0.3 (latest) — 2020-10-20
- 0.0.2 — 2020-10-14
- 0.0.1 — 2020-10-13

## README

# Symbiota2 API in Typescript
This project uses NestJS/TypeORM to connect to an existing Symbiota1 or 
Symbiota2 database and expose the Symbiota2 API.

At the start of the project, all TypeORM entities were configured to be 
compatible with a Symbiota database. However, it's recommended to back up
your existing database before running the following steps.


Each time you install/update Symbiota2, you should also start the server, then run database migrations:
```console
$ npm run start
[Nest] 14747   - 10/16/2020, 1:57:42 PM   [NestFactory] Starting Nest application...
[Nest] 14747   - 10/16/2020, 1:57:42 PM   [InstanceLoader] AppModule dependencies initialized +13ms
[Nest] 14747   - 10/16/2020, 1:57:42 PM   [InstanceLoader] PassportModule dependencies initialized +0ms
[Nest] 14747   - 10/16/2020, 1:57:42 PM   [InstanceLoader] PluginModule dependencies initialized +0ms
[Nest] 14747   - 10/16/2020, 1:57:42 PM   [InstanceLoader] ConfigHostModule dependencies initialized +1ms
[Nest] 14747   - 10/16/2020, 1:57:42 PM   [InstanceLoader] ConfigModule dependencies initialized +0ms
[Nest] 14747   - 10/16/2020, 1:57:42 PM   [InstanceLoader] AppConfigModule dependencies initialized +0ms
[Nest] 14747   - 10/16/2020, 1:57:42 PM   [DatabaseProvider] CLI config written successfully
...
```

In a separate terminal:
```
$ npm run typeorm:migration:run
query: SELECT * FROM `INFORMATION_SCHEMA`.`COLUMNS` WHERE `TABLE_SCHEMA` = 'symbscan' AND `TABLE_NAME` = 'migrations'
query: CREATE TABLE `symbscan`.`migrations` (`id` int NOT NULL AUTO_INCREMENT, `timestamp` bigint NOT NULL, `name` varchar(255) NOT NULL, PRIMARY KEY (`id`)) ENGINE=InnoDB
query: SELECT * FROM `symbscan`.`migrations` `migrations`  ORDER BY `id` DESC
No migrations are pending
```

The backend has the following core modules:
- [AppConfigModule](./src/app-config/app-config.module.ts): Responsible for
import Symbiota2 configuration from either environment variables or a `.env`
file
- [AuthModule](./src/auth/auth.module.ts): Responsible for authenticating users
via username and password and issuing a corresponding JWT and refresh token. 
This JWT includes roles that the user is assigned. Those roles are then 
validated against protected API routes.
- [ConfigurationModule](./src/configuration/configuration.module.ts): 
Responsible for retrieving key-value configuration for the web UI
- [Database](./src/database/database.module.ts): By far the largest module,
it contains all TypeORM definitions for Symbiota1 database tables, plus two
new Symbiota2 tables:
    - [RefreshToken](./src/database/entities/user/RefreshToken.entity.ts):
    Used to silently refresh/revoke a user's login JWT
    - [Configuration](./src/database/entities/Configuration.entity.ts):
    Used in ConfigurationModule (above)
- [Language](./src/language/language.module.ts): Used for retrieving different
language identifiers
- [Plugin](./src/plugin/plugin.module.ts): Used to load Symbiota2 plugins.
Each plugin is a NodeJS package with one or more NestJS modules. A default 
module is exported from the package and imported to Symbiota2 via the 
PluginModule at runtime. Plugins to be loaded are stored in 
`${APP_DATA_DIR}/plugins`. See the 
[sample plugin](https://gitlab.com/symbiota2/sample-plugin) for more.
- [SchemaVersion](./src/schema-version/schema-version.module.ts): Used to
retrieve the Symbiota schema updates that have been applied to the database.
- [User](./src/user/user.module.ts): Used for retrieving details on users of
the Symbiota2 instance

All modules are exported, and are available to plugins via the
[@symbiota2/backend](https://www.npmjs.com/package/@symbiota2/backend) 
NodeJS package.

---
_Source: https://npm.io/package/@symbiota2/backend · Machine-readable twin of the npm.io package page. Health data is recomputed on every publish._
