Skip to content

Add full documentation #8

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 13 commits into from
7 changes: 6 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,10 @@ instead of a direct connection to the boat.
All the realtime transmission happens over Socket.io which is adopted by frameworks for many different languages.
Here is a simple connection diagram:

`🎮 Client/Phone` ↔️ `📟 Proxy/Server` ↔️ `⛵️ Boat`
```markdown
**🎮 Client/Phone** ↔️ **📟 Proxy/Server** ↔️ **⛵️ Boat**
Svelte Golang Python
```

## 🎚 Hardware

Expand Down Expand Up @@ -62,6 +65,8 @@ but will be discussed and explained soon. Stay tuned 📻

## 🚧 Going further

If you are interested, you can look into our [Documentation](./docs)

I am grateful for any type of feedback, inspiration or question regarding CosmicSail.<br>
Feel free to create an Issue to get in touch.

22 changes: 22 additions & 0 deletions docs/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
# 📖 Documentation

This documentation is split up into several parts for a better structure and overview
over the protocols and communitcation methods that CosmicSail utilizes.

## Backend

Our backend is written in Golang with the help of two amazing frameworks,
[Gorm](https://gorm.io) and [Fiber](https://gofiber.io).

- [Authentication](./backend/Authentication.md): To use the CosmicSail API, a user has to authenticate over these endpoints
- WIP [v1 User Endpoints](./backend/v1%20User%20Endpoints.md): Endpoints that a user can access to manage their boats
- WIP [v1 Boat Endpoints](): Endpoints which are made for the boat (telemetry updating or data loading)

## Socket Protocol

We are communicating over [Socket.io](https://socket.io) for realtime scenarios,
as it's much more stable and reliable compared to traditional WebSockets.

- WIP [Socket connection](): Documentation on how to establish an authenticated connection to the server
- WIP [User communication](): Events a user can send/receive to control boats and get data
- WIP [Boat communication](): Events a boat client should implement to work properly
50 changes: 50 additions & 0 deletions docs/backend/Authentication.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
# Authentication

The majority of endpoints and the socket framework
are protected by an authentication layer.<br>
For REST calls, we utilize the Authorization Header with a Bearer token to get access:
```env
Authorization: "Bearer <token>"
```

And when connecting to socket.io the token is specified as url query parameter along with the boat emblem:
```
<socket_url>?token=<token>&boatEmblem=<boat_emblem>
```
*More on socket connection in [Socket Protocoll Documentation](https://github.com/Adwirawien/CosmicSail/tree/feature/docs/docs#socket-protocol)*

### Where to get a token?

You currently **cannot** register for CosmicSail, but if you have a login,
the process of getting a user token is fairly simple.

# Login
Get a jsonwebtoken for usage with the api.

### Request
POST `/auth/login`<br>

**Authorization:** None<br>
**Query Params:** None<br>
**Body:**
| Name | Description | Type | Required |
| ---------- | -------------- | ------ | -------- |
| `username` | Username | String | Yes |
| `password` | Password | String | Yes |

### Response

`200` - Success<br>
The token is valid for 24h.
```json
{
"Token": ...,
"Username": "cosmicSailor"
}
```

`400` - Bad Request<br>
Your post body could not be parsed.

`403` - Forbidden<br>
Username or password not valid.
Loading