{"id":13502974,"url":"https://github.com/canduma/canduma","last_synced_at":"2025-03-29T13:30:28.678Z","repository":{"id":35694626,"uuid":"214442092","full_name":"canduma/canduma","owner":"canduma","description":"A Rust Boilerplate server with GraphQL API, Diesel, PostgreSQL, session authentication and JWT","archived":false,"fork":false,"pushed_at":"2023-10-19T23:44:06.000Z","size":1633,"stargazers_count":809,"open_issues_count":8,"forks_count":63,"subscribers_count":20,"default_branch":"master","last_synced_at":"2024-08-04T08:08:55.220Z","etag":null,"topics":["actix","actix-web","boilerplate-rust","graphql","juniper","jwt-token","micro-service"],"latest_commit_sha":null,"homepage":"","language":"Rust","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/canduma.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null}},"created_at":"2019-10-11T13:22:36.000Z","updated_at":"2024-07-24T21:14:48.000Z","dependencies_parsed_at":"2024-01-13T20:13:20.783Z","dependency_job_id":null,"html_url":"https://github.com/canduma/canduma","commit_stats":null,"previous_names":["canduma/canduma","clifinger/canduma"],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/canduma%2Fcanduma","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/canduma%2Fcanduma/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/canduma%2Fcanduma/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/canduma%2Fcanduma/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/canduma","download_url":"https://codeload.github.com/canduma/canduma/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":246190150,"owners_count":20737984,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["actix","actix-web","boilerplate-rust","graphql","juniper","jwt-token","micro-service"],"created_at":"2024-07-31T22:02:32.207Z","updated_at":"2025-03-29T13:30:28.321Z","avatar_url":"https://github.com/canduma.png","language":"Rust","funding_links":[],"categories":["Rust","graphql"],"sub_categories":[],"readme":"[![MIT license](http://img.shields.io/badge/license-MIT-brightgreen.svg)](http://opensource.org/licenses/MIT)\n[![Status](https://img.shields.io/badge/build-passing-brightgreen)]()\n[![Status](https://img.shields.io/badge/pull--request-open-blue)]()\n\n# Canduma rust Graphql\n\n`A Rust authentication server with GraphQL API, Diesel, PostgreSQL session authentication and JWT`\n\nThis repository contains a GraphQL server with JWT up and running quickly.\n\nIt uses [actix-web](https://actix.rs/), [Juniper](https://graphql-rust.github.io/juniper/current/),\n[Diesel](http://diesel.rs/) and [jsonwebtoken](https://docs.rs/jsonwebtoken)\n\nYour own pull requests are welcome!\n\n## Benchmarks with insert into PostgreSQL\n\n```shell script\n▶ ./bombardier -c 125 -n 10000000 http://localhost:3000/graphql -k -f body --method=POST -H \"Content-Type: application/json\" -s\nBombarding http://localhost:3000/graphql with 10000000 request(s) using 125 connection(s)\n\n10000000 / 10000000 [===========================================================================] 100.00% 28777/s 5m47s\nDone!\nStatistics        Avg      Stdev        Max\n  Reqs/sec     28788.66    2183.47   34605.95\n  Latency        4.32ms   543.07us   110.95ms\n  HTTP codes:\n    1xx - 0, 2xx - 10000000, 3xx - 0, 4xx - 0, 5xx - 0\n    others - 0\n  Throughput:    20.75MB/s\n```\n\n## Collection of major crates used in Canduma\n\n- actix - [link](https://actix.rs/)\n- actix-web - [link](https://docs.rs/actix-web/)\n- diesel - [link](http://diesel.rs/)\n- juniper - [link](https://graphql-rust.github.io/juniper/current/)\n- chrono - [link](https://docs.rs/chrono/)\n- serde_json - [link](https://docs.serde.rs/serde_json/)\n- argon2rs - [link](https://github.com/bryant/argon2rs)\n- jsonwebtoken - [link](https://docs.rs/jsonwebtoken)\n- anyhow - [link](https://github.com/dtolnay/anyhow)\n- thiserror - [link](https://github.com/dtolnay/thiserror)\n- shrinkwraprs - [link](https://docs.rs/shrinkwraprs/)\n\n## Required\n\n- [Rustup](https://rustup.rs/)\n- Stable Toolchain: `rustup default stable`\n- Diesel cli with postgres `cargo install diesel_cli --no-default-features --features \"postgres\"`\n- PostgreSQL database server or use our docker-compose.yml (require docker)\n\n## Getting Started\n\n```sh\ngit clone https://github.com/clifinger/canduma.git\ncd canduma\ndocker-compose up\ncp .env.example .env\ndiesel setup --database-url='postgres://postgres:canduma@localhost/canduma'\ndiesel migration run\ncargo run\n```\n\n## Test the GraphQL API with Insomnia\n\n### Register\n\n![Register with Insomnia](docs/images/new-insomnia-register.png)\n\n### Login\n\n![Login with Insomnia](docs/images/new-insomnia-login.png)\n\n### Get my account\n\n![Login with Insomnia](docs/images/new-insomnia-get-me.png)\n\n### Get JWT Token\n\n![Get JWT by GraphQL with Insomnia](docs/images/new-insomnia-grahql-get-jwt.png)\n\n### Set Bearer JWT Token\n\n![Set JWT Token with Insomnia](docs/images/insomnia-set-bearer.png)\n\n### Get decoded JWT by the server (for tests purpose)\n\n![Get JWT decoded Token by GraphQL with Insomnia](docs/images/new-insomnia-grahql-get-jwt-decoded.png)\n\n### Test authentication with session in GraphQL by getting all users (for tests purpose)\n\n![Get all users by GraphQL with Insomnia](docs/images/new-insomnia-grahql-get-users.png)\n\n### Logout\n\n![Logout with Insomnia](docs/images/new-insomnia-logout.png)\n\n### Raw code for Insomnia\n\n```text\n############ GraphQL Queries ############\nquery usersQuery {\n  users {\n    name\n    userUuid\n    email\n    createdAt\n  }\n}\n\nquery tokenQuery {\n  token {\n    bearer\n  }\n}\n\nquery decodeTokenQuery {\n  decode {\n    email\n    iss\n    iat\n    exp\n    sub\n  }\n}\n\n```\n\n## Test the GraphQL API with VScode REST Client\n\n[VScode plugin](https://marketplace.visualstudio.com/items?itemName=humao.rest-client)\n\nSee / open TEST.http file in vscode.\n\n## Build release\n\n```sh\ncargo build --release\ncd target/release\n./canduma\n```\n\n## Security\n\n### Important security considerations\n\nWe use session cookies for authentication.\n\n**Why not JWT authentication?**\n\n[Stop Using JWT for sessions and why your solution doesn't work](http://cryto.net/~joepie91/blog/2016/06/19/stop-using-jwt-for-sessions-part-2-why-your-solution-doesnt-work/)\n\nThe use of JWT remains secure only if you use adequate storage.\nThis boilerplate is built for use in a micro-services architecture.\n\nJWT can be use for representing claims to be transferred between two parties.\n\nThe private key should only be on this micro-service.\npublic key can be used on all other parties to decode the token.\n\nThis boilerplate provides a complete example, so we included JWT also.\n\n### Generate RSA keys for JWT\n\nIn development mode you can keep the one in `/keys` folder.\n\n```shell script\n// private key\n$ openssl genrsa -out rs256-4096-private.rsa 4096\n\n// public key\n$ openssl rsa -in rs256-4096-private.rsa -pubout \u003e rs256-4096-public.pem\n```\n\n### Logging\n\nLogging controlled by middleware::Logger [actix.rs](https://actix.rs/docs/errors/)\n\nTo enable debug logging set `RUST_LOG=debug` in `.env`\n\n### Testing\n\n#### Initialization\n\nFirst run `yarn` or `npm install` to get all required packages\n\n#### npm run test\n\nTo run you can use `npm run test` or `yarn test`.\n\nThe testing system designed to automatically build `canduma` offline and start in `tests/jest.beforeall.js`\nWe starting `canduma` in order to capture output from both rust and js code using `testci` target\n\n#### npm run testci\n\n```bash\n$ npm run testci\n\n\u003e canduma@ testci /home/olexiyb/b100pro/canduma\n\u003e cross-env RUST_LOG=debug DEBUG=canduma:* NODE_ENV=test jest\n\nDetermining test suites to run...\n$ killall canduma\ncanduma: no process found\n\n$ cargo build\n    Finished dev [unoptimized + debuginfo] target(s) in 0.07s\n  canduma:jest.beforeall.js build = { status: 0, signal: null, output: [ null, null, null ], pid: 2447, stdout: null, stderr: null } +0ms\n\n$  target/debug/canduma\n[2020-04-02T18:17:19Z INFO  actix_server::builder] Starting 24 workers\n[2020-04-02T18:17:19Z INFO  actix_server::builder] Starting server on 0.0.0.0:4000\nListening on 0.0.0.0:4000\nstarted API \n\n  canduma:user.test.js /user/me body='Unauthorized' text=\"Unauthorized\" +0ms\n\n...\n[2020-04-02T18:17:22Z DEBUG canduma::user::handler] user_string={\"user_uuid\":\"f7cfa71e-096e-44d0-ae4f-7d16dd9e4baf\",\"email\":\"email1@nowhere.com\",\"role\":\"bad_role\"}\n  canduma:user.test.js /graphql body={ data: null, errors: [ { message: 'Unauthorized', locations: [Array], path: [Array], extensions: [Object] } ] } +292ms\n PASS  tests/user.test.js\n \n...\n```\n\nIn example above you see output from jest tests as well as from rust code `debug!(\"user_string={}\", user_string);`\n\n#### CLion\n\nI also highly recommend to use CLion as a dev tool.\nI allows to run all tests or individual with single click and analyze logs\n\n![alt text](docs/images/clion-1.png)\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fcanduma%2Fcanduma","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fcanduma%2Fcanduma","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fcanduma%2Fcanduma/lists"}