]> git.immae.eu Git - github/Chocobozzz/PeerTube.git/blame - support/doc/development/server/code.md
Fix video import if autoblacklist is enabled
[github/Chocobozzz/PeerTube.git] / support / doc / development / server / code.md
CommitLineData
00ffc03e
C
1# Server code documentation
2
69f616ab 3The server is a web server developed with [TypeScript](https://www.typescriptlang.org/)/[Express](http://expressjs.com).
00ffc03e
C
4
5
6## Technologies
7
69f616ab 8 * [TypeScript](https://www.typescriptlang.org/) -> Language
7e6afafd 9 * [PostgreSQL](https://www.postgresql.org/) -> Database
94a5ff8a 10 * [Redis](https://redis.io/) -> Job queue/cache
00ffc03e 11 * [Express](http://expressjs.com) -> Web server framework
7e6afafd 12 * [Sequelize](http://docs.sequelizejs.com/en/v3/) -> SQL ORM
82e62423 13 * [WebTorrent](https://webtorrent.io/) -> BitTorrent tracker and torrent creation
00ffc03e
C
14 * [Mocha](https://mochajs.org/) -> Test framework
15
16
17## Files
18
afe81767
C
19The server main file is [server.ts](/server.ts).
20The server modules description are in the [package.json](/package.json) at the project root.
21All other server files are in the [server](/server) directory:
00ffc03e 22
2bb0f9d5 23 server.ts -> app initialization, main routes configuration (static routes...)
00ffc03e
C
24 config -> server YAML configurations (for tests, production...)
25 scripts -> Scripts files for npm run
26 server
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...)
339632b4 30 |__ lib -> library function (WebTorrent, OAuth2, ActivityPub...)
00ffc03e 31 |__ middlewares -> middlewares for controllers (requests validators, requests pagination...)
fcaf1e0a 32 |__ models -> Sequelize models for each SQL tables (videos, users, accounts...)
00ffc03e
C
33 |__ tests -> API tests and real world simulations (to test the decentralized feature...)
34
35
36## Conventions
37
38Uses [JavaScript Standard Style](http://standardjs.com/).
39
00ffc03e
C
40## Architecture
41
42The server is composed by:
43
3e9e6f2f
RK
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))
00ffc03e 46
a2431b7d 47A video is seeded by the server with the [WebSeed](http://www.bittorrent.org/beps/bep_0019.html) protocol (HTTP).
00ffc03e 48
afe81767 49![Architecture scheme](/support/doc/development/server/upload-video.png)
00ffc03e 50
3e9e6f2f 51When a user uploads a video, the REST API creates the torrent file and then adds it to its database.
00ffc03e 52
82e62423 53If 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.
00ffc03e
C
54
55## Newcomers
56
3e9e6f2f
RK
57The server entrypoint is [server.ts](/server.ts). Looking at this file is a good start.
58Then you can try to understand the [controllers](/server/controllers): they are the entrypoints of each API request.