bandboyztour / nice-web

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Description

This project includes a web server and a web client written in Rust. It created with work, time, and a little bit of rocket, diesel, yew frameworks. As a database for this used a PostgreSQL.

It has the following features:

  • creating an account
  • signing in account
  • creating posts
  • deleting them
  • bookmarking them [to see them first]
  • seeing own posts.

How to Use

Pre-requirements

  • Rust + Cargo
  • Postgres Server
  • trunk (it's needed to build a Rust WASM application)
  • Diesel CLI
  1. Do you have installed PostgreSQL? If not, follow this instructions https://www.postgresql.org/download/
  2. Do you have installed rust, cargo? If not, follow this instructions https://www.rust-lang.org/tools/install
  3. Do you have installed diesel? If not, execute command cargo install diesel_cli --no-default-features --features postgres
  4. Also follow to this install instruction to install trunk for web-client: https://yew.rs/docs/getting-started/introduction#install-webassembly-target

After all

  1. $ git clone https://github.com/DKotov29/nice-web.git
  2. $ cd nice-web/nice-web-backend
  3. Rename .env.template file to .env. In .env file change username, password to yours, and $ diesel_demo to yours database name
  4. $ diesel migration run
  5. $ cd ..
  6. $ cd web-client
  7. $ trunk build
  8. $ cd ..
  9. $ cd nice-web-backend
  10. $ cargo run
  11. profit

How it works

The project was created to provide the following functionality: user account creation and the ability to create and write posts. As stated in the technical specification, the frontend utilizes the Yew framework, while interaction with the database is handled using Diesel. For the backend, Rocket was chosen as the framework. To facilitate communication between the server and client, a decision was made to employ a RESTful API. User authentication is implemented using sessions. Upon logging in, a unique key is generated and added to the cache, which is then used to ensure minimal authorization when accessing protected API endpoints. Posts are delivered in accordance with the project requirements.

Project backend structure includes a "migrations" directory, which houses SQL files responsible for setting up the necessary tables.

In the "src" directory, you'll find the main file, which establishes a connection pool to the database and initiates request handling on mounted paths.

Additionally, there is a "schema" file generated by Diesel, which serves for compile-time correctness checking.

The "controller" directory contains all the files where the server handles incoming requests.

Lastly, the "model" directory is the sole place where the server interacts directly with the database, including session management.

Project client have such structure: The project is built using the Yew framework, which plays a central role in its structure.

The client communicates with the server through a RESTful API. The API module is responsible for handling all interactions with the API. This design choice simplifies the organization of related logic.

Within the project, you'll find a "components" folder housing everything related to the interaction between the user and the business logic.

Additionally, the client stores the session token received from the server in session storage for authentication and security purposes.

About


Languages

Language:Rust 96.3%Language:SCSS 2.8%Language:HTML 0.9%