Skip to content

Commit

Permalink
Merge branch 'CHAOS-224-KHAOS-rewrite' into CHAOS-475-api-documentation
Browse files Browse the repository at this point in the history
  • Loading branch information
Alex_Miao_WSL committed Sep 25, 2024
2 parents ac0eb77 + 15aa828 commit 4d4c060
Show file tree
Hide file tree
Showing 42 changed files with 4,186 additions and 298 deletions.
8 changes: 5 additions & 3 deletions .github/workflows/rust.yml
Original file line number Diff line number Diff line change
Expand Up @@ -48,13 +48,15 @@ jobs:
~/.cargo/registry/index/
~/.cargo/registry/cache/
~/.cargo/git/db/
backend/prisma-cli/target/
backend/server/target/
key: ${{ runner.os }}-cargo-${{ hashFiles('**/Cargo.lock') }}
restore-keys: ${{ runner.os }}-cargo-
- name: Migrate DB
working-directory: backend/prisma-cli
run: cargo run db push
working-directory: backend
run: |
which sqlx || cargo install sqlx-cli --no-default-features --features native-tls,postgres
sqlx database create
sqlx migrate run
- name: Build
working-directory: backend/server
run: cargo build
Expand Down
25 changes: 22 additions & 3 deletions backend/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,26 @@

CHAOS' backend is implemented in Rust and for data persistence, we use PostgreSQL.

## Table of Contents

- [Dev Setup](#dev-setup)
- [Code Structure](#code-structure)
- [Tech Stack](#tech-stack)


## Dev Setup

To run the backend in a dev/testing environment:
1. Install `docker-compose` (see [official installation guide](https://docs.docker.com/compose/install/)).
2. Navigate to the directory this file is in (`backend`) in your terminal (not `backend/server`).
3. Possibly terminate any running instances of postgres, as the dockerized postgres we will spawn uses the same default port, so the two might interefere with each other.
4. Run `./setup-dev-env.sh` (you might have to make it executable before with `chmod +x setup-dev-env.sh`), which should drop you into a new shell that has the required tools installed.
5. Now, you can `cd server` and should be able to `cargo build` successfully.
6. Once you exit out of the newly created shell (e.g. type `exit`, or kill the terminal), the dockerized postgres instance should automatically be torn down, so it's not unnecessarily running in the background all the time.


## Code Structure

### Service
The service module contains all functions that conduct business logic, and also interact with the database. This
separation from the request handling makes it easy to swap out any new form of requests, but reuse the same business
Expand All @@ -27,12 +46,12 @@ Request -> Middleware (optional) -> Handler -> Service -> Middleware (Optional)


## Tech Stack

### Web Server
- [Axum](https://github.com/tokio-rs/axum)

### Persistence
- [SQLx](https://github.com/launchbadge/sqlx) - Queries
- [Prisma](https://www.prisma.io/) - Migrations and Schema
- [SQLx](https://github.com/launchbadge/sqlx) - Queries and Migrations
- PostgreSQL

### AuthN
Expand All @@ -42,4 +61,4 @@ Request -> Middleware (optional) -> Handler -> Service -> Middleware (Optional)
- JWT

### Storage
- Local file system
- Object storage
Loading

0 comments on commit 4d4c060

Please sign in to comment.