1 # Server code documentation
3 The server is a web server developed with [TypeScript](https://www.typescriptlang.org/)/[Express](http://expressjs.com).
8 * [TypeScript](https://www.typescriptlang.org/) -> Language
9 * [PostgreSQL](https://www.postgresql.org/) -> Database
10 * [Redis](https://redis.io/) -> Job queue/cache
11 * [Express](http://expressjs.com) -> Web server framework
12 * [Sequelize](http://docs.sequelizejs.com/en/v3/) -> SQL ORM
13 * [WebTorrent](https://webtorrent.io/) -> BitTorrent tracker and torrent creation
14 * [Mocha](https://mochajs.org/) -> Test framework
19 The server main file is [server.ts](/server.ts).
20 The server modules description are in the [package.json](/package.json) at the project root.
21 All other server files are in the [server](/server) directory:
23 server.ts -> app initialization, main routes configuration (static routes...)
24 config -> server YAML configurations (for tests, production...)
25 scripts -> Scripts files for npm run
27 |__ controllers -> API routes/controllers files
28 |__ helpers -> functions used by different part of the project (logger, utils...)
29 |__ initializers -> functions used at the server startup (installer, database, constants...)
30 |__ lib -> library function (WebTorrent, OAuth2, ActivityPub...)
31 |__ middlewares -> middlewares for controllers (requests validators, requests pagination...)
32 |__ models -> Sequelize models for each SQL tables (videos, users, accounts...)
33 |__ tests -> API tests and real world simulations (to test the decentralized feature...)
38 Uses [JavaScript Standard Style](http://standardjs.com/).
42 The server is composed by:
44 * a REST API (relying on the Express framework) documented on http://docs.joinpeertube.org/api.html
45 * a WebTorrent Tracker (slightly custom version of [webtorrent/bittorrent-tracker](https://github.com/webtorrent/bittorrent-tracker#server))
47 A video is seeded by the server with the [WebSeed](http://www.bittorrent.org/beps/bep_0019.html) protocol (HTTP).
49 ![Architecture scheme](/support/doc/development/server/upload-video.png)
51 When a user uploads a video, the REST API creates the torrent file and then adds it to its database.
53 If a user wants to watch the video, the tracker will indicate all other users that are watching the video + the HTTP url for the WebSeed.
57 The server entrypoint is [server.ts](/server.ts). Looking at this file is a good start.
58 Then you can try to understand the [controllers](/server/controllers): they are the entrypoints of each API request.