Code Monkey home page Code Monkey logo

fullstack-rust-axum-dioxus-rwa's Introduction

RealWorld Example App

Dioxus and Axum codebase containing real world examples (CRUD, auth, advanced patterns, etc) that adheres to the RealWorld spec and API.

This codebase was created to demonstrate a fully fledged fullstack application built with Dioxus (as front-end) and Axum (as back-end), including routing, authentication, CRUD operations, authentication, and more.

We've gone to great lengths to adhere to the styleguides & best practices promoted by these frameworks. For more information on how to this works with other frontends/backends, head over to the RealWorld repo.


How it works

This project uses the classic three-tier architecture:

  ╭───────────────╮       ╭────────────────╮       ╭────────────────╮
  │   Front-end   │       │    Back-end    │       │     Database   │
  │    (Dioxus)   ├──────►│     (Axum)     ├──────►│   (PostgreSQL) │
  ╰───────────────╯       ╰────────────────╯       ╰────────────────╯

Getting started

First, have the database available as described in backend's readme by starting it and run the database migration (that populates it with the required objects).

Next, for local development and usage, just run ./run_dev.sh script that starts both the front-end and the back-end.

fullstack-rust-axum-dioxus-rwa's People

Contributors

dxps avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar

fullstack-rust-axum-dioxus-rwa's Issues

[be] `ArticlesRepo` - Fix delete article with tags

The current implementation deletes only from articles table.
If an article has tags, then it obviously fails with:

update or delete on table "articles" violates foreign key constraint "fk_article_id" on table "tags_articles"

[be] Only owned articles can be updated or deleted

AS-IS
Currently, the authorization is all or nothing: any authenticated user can update or delete any article (besides creating one, of course).

TO-BE
Only the user that is the author of (aka own) an article can update or delete it.

[be] `ArticlesRepo` - Refactor the common parts

Some parts are duplicated, thus need to be extracted into a reusable function:

  1. The INSERT INTO tags_articles statements (done in both add and update methods).
  2. Rendering the AppError based on Error or DatabaseError.

`sqlx::FromFrow` as implementation vs attribute

Currently, src/repos/users_repo.rs file contains explicit implementations (impl FromRow ... for ...) for User, UserId and UserEntry.

Initial reasoning was to try to keep the domain model as clean as possible.
However, just adding the sqlx::FromRow into the existing #[derive(...) attribute shouldn't hurt, but eliminate those implementations:
image

Better handling of article slug uniqueness

Trying to create an article with the same slug it returns an HTTP RC 500.

And in the log it throws this:

2023-01-29T20:59:05.718215Z DEBUG backend::app_errors: From sqlx err: Database(PgDatabaseError { 
severity: Error, code: "23505", 
message: "duplicate key value violates unique constraint \"unique_slug\"", 
detail: Some("Key (slug)=(how-to-train-your-dragon) already exists."), 
hint: None, position: None, where: None, schema: Some("public"), 
table: Some("articles"), column: None, data_type: None, 
constraint: Some("unique_slug"), 
file: Some("nbtinsert.c"), line: Some(663), routine: Some("_bt_check_unique") })

It should return a 422 (Unprocessable Entity).

Swagger documentation

Hi, great example project - thanks!

I'm not sure if the specc requires swagger/OpenAPI docs, but I think it would be a great addition in order to match what someone would expect from a production app.

Simplify output DTOs with `Json(json!({ "some": some })`

Use the approach that exists in get_user_profile handler. This means:

  • return Json(json!({ "profile": profile })))
  • and thus UserProfileDTO is one single struct
    (instead of two structs, like the case of UserOutDTO and its UserOutDTOUserAttrs child).

Fix initial routing

The routes within the SPA are working. For example: navigating from HomePage (/) to SignIn (/signin) works fine.

But if you go directly to http://localhost:8080/signin you get a 404.

[be] Consistenly use `UserId` extractor, instead of `Claims`

follow_user and create_article handlers are using user_claims: Claims as method arguments.
But they are using only user_claims.sub part which is actually the UserId.
Therefore, it's more clear and efficient to use user_id: UserId extractor.

And update_article and delete_article handlers are not using any of these, so they behave as public (not protected as they should be) endpoints.

Current source code doesn't compile correctly

When trying to run example (git clone..; ./run_dev.sh) I'm getting following error:

[INFO] 🚅 Running build command...
[ERROR] 🚫 Serve startup failed: error[E0107]: this struct takes 2 generic arguments but 1 generic argument was supplied
   --> /home/spock/.cargo/registry/src/github.com-1ecc6299db9ec823/dioxus-core-0.2.1/src/virtual_dom.rs:109:19
    |
109 |     dirty_scopes: IndexSet<ScopeId>,
    |                   ^^^^^^^^ ------- supplied 1 generic argument
    |                   |
    |                   expected 2 generic arguments
    |
note: struct defined here, with 2 generic parameters: `T`, `S`
   --> /home/spock/.cargo/registry/src/github.com-1ecc6299db9ec823/indexmap-1.9.3/src/set.rs:67:12
    |
67  | pub struct IndexSet<T, S> {
    |            ^^^^^^^^ -  -
help: add missing generic argument
    |
109 |     dirty_scopes: IndexSet<ScopeId, S>,
    |                                   +++```

Looks like libraries used by project has some issues.

[be] A user cannot follow himself

AS-IS
Currently, any user can follow any user, including himself (which it doesn't make sense, ofc).

TO-BE
A user can follow any other user, except of himself.

Respond with a JSON in case of initial request body deserialization issues

By default, in cases where the request body can't be deserialized as JSON, the response code is 422 (Unprocessable Entity), but the body is a text (explicitly declared also by the response's content-type header with value text/plain; charset=utf-8:

Failed to deserialize the JSON body into the target type: missing field `password` at line 5 column 3

A proper response of such an HTTP API would be a JSON with an error attribute, at minimum.

JWT related config elements

Additional elements must be exposed as configuration values.

This includes:

  1. JWT lifetime
  2. JWT signing secret

[front-end] Upgrade to Dioxus 0.5

Currently, the front-end is done using version 0.3 of Dioxus.

The initial try to upgrade to version 0.4 showed that it's not that easy breezy.
Since version 0.5 introduces signals and thus provides a nicer API, I'd skip the upgrade to 0.4.

This issue is mainly a reminder to do this when Dioxus ver. 0.5 will be released.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.