All Projects → taneba → fullstack-graphql-app

taneba / fullstack-graphql-app

Licence: other
An opinionated fullstack GraphQL monorepo boilerplate using pnpm, Turborepo, Prisma, GraphQL Yoga 2, Fastify, Nextjs, urql, and React

Programming Languages

typescript
32286 projects
javascript
184084 projects - #8 most used programming language

Projects that are alternatives of or similar to fullstack-graphql-app

mrapi
A framework for rapid development of API or DAL applications.
Stars: ✭ 20 (-77.78%)
Mutual labels:  fastify, prisma
eas-monorepo-example
Fast pnpm monorepo for cross-platform apps built with Expo / React Native and React.
Stars: ✭ 187 (+107.78%)
Mutual labels:  pnpm, turborepo
fastify-graphql-nexus-prisma
GraphQL Server with Fastify, Mercurius, Prisma, and Nexus
Stars: ✭ 125 (+38.89%)
Mutual labels:  fastify, prisma
calendso
Scheduling infrastructure for absolutely everyone.
Stars: ✭ 13,100 (+14455.56%)
Mutual labels:  prisma, turborepo
fastify-prisma
Basic Fastify app using Prisma as an ORM
Stars: ✭ 26 (-71.11%)
Mutual labels:  fastify, prisma
nextjs-ts-antd-redux-storybook-starter
🏃🏼 Next.js + TypeScript + Ant Design + Redux Toolkit + Redux Saga + Styled Components + Jest + Storybook 企业级项目脚手架模板
Stars: ✭ 78 (-13.33%)
Mutual labels:  pnpm
node-fastify-mongo-api
Node.js Restful API starter template
Stars: ✭ 77 (-14.44%)
Mutual labels:  fastify
Electrode
Web applications with node.js and React
Stars: ✭ 2,033 (+2158.89%)
Mutual labels:  fastify
Http Proxy Middleware
⚡ The one-liner node.js http-proxy middleware for connect, express and browser-sync
Stars: ✭ 8,730 (+9600%)
Mutual labels:  fastify
prisma-dbml-generator
Prisma DBML Generator
Stars: ✭ 434 (+382.22%)
Mutual labels:  prisma
nodejs-integration-tests-best-practices
✅ Beyond the basics of Node.js testing. Including a super-comprehensive best practices list and an example app (April 2022)
Stars: ✭ 2,842 (+3057.78%)
Mutual labels:  fastify
vscode-monorepo-workspace
📦✨Manage monorepos with multi-root workspaces. Supports Lerna, Yarn, Pnpm, Rushjs and recursive package directories.
Stars: ✭ 93 (+3.33%)
Mutual labels:  pnpm
bunjil
A GraphQL bastion server with schema merging, authentication and authorization with Policy Based Access Control
Stars: ✭ 25 (-72.22%)
Mutual labels:  prisma
Notadd
A microservice development architecture based on nest.js. —— 基于 Nest.js 的微服务开发架构。
Stars: ✭ 2,556 (+2740%)
Mutual labels:  fastify
nest-next-sample
NestJS + Next.js sample application / Backend and Frontend use only TypeScript!!!
Stars: ✭ 110 (+22.22%)
Mutual labels:  prisma
Permit
An unopinionated authentication library for building Node.js APIs.
Stars: ✭ 1,654 (+1737.78%)
Mutual labels:  fastify
vite-primevue-starter
VUE 3 Starter project for using primevue 3 with Vite 2 - Pages, Layouts, Validation
Stars: ✭ 37 (-58.89%)
Mutual labels:  pnpm
fastify-jwt-authz
Verify authenticated user scope
Stars: ✭ 14 (-84.44%)
Mutual labels:  fastify
iridium
💎 Growing collection of VS Code extensions with a fancy name
Stars: ✭ 39 (-56.67%)
Mutual labels:  pnpm
postcss-prefixwrap
A PostCSS plugin that is used to wrap css styles with a css selector to constrain their affect on parent elements in a page.
Stars: ✭ 54 (-40%)
Mutual labels:  pnpm

fullstack-graphql-app

An opinionated fullstack GraphQL monorepo Boilerplate using modern tech stack.

Concepts

🛡Type-safe

  • graphql-code-generator
  • prisma
  • ts-pattern (for type-safe error handling)
  • and I code in a type-safe way and don't choose a library that doesn't have a good TypeScript support.

🛠Customizable

  • envelop (plugin system for GraphQL)
  • urql (highty customizable GraphQL Client)

📈Simple but scalable

Ever evolving

  • I constantly maintain this repository.
  • TypeScript, React, GraphQL are ever evolving world too.
  • In that sense, any tech stack might be replaced in the future.

Tech Stack

Common

  • TypeScript
  • Turborepo
  • pnpm
  • GraphQL
  • graphql-codegen

Backend

  • Prisma
  • fastify
  • envelop
  • graphql-yoga 2.0
  • graphiql
  • ts-pattern
  • mysql

Frontend

  • React
  • Next.js
  • urql
  • tailwindcss
  • radix ui
  • shadcn/ui
  • React Hook Form

Authentication

  • Auth0

Testing

  • testing-library
  • jest
  • msw

Getting Started

Setting up auth0

As this project uses auth0 for authentication, you need to setup auth0 to make everything work. If you don't have any auth0 account, then sign up and create account.

You need to create API, Application (Single Page Application) in the auth0 console. In Application, go to Application URIs section in the middle of the settings page and specify http://localhost:3000 to Allowed Callback URLs, Allowed Logout URLs, Allowed Web Origins, Allowed Origins (CORS).

Once you have set up API and Application, collect credentials below which will be used in your application:

  • Client Id: Your Auth0 application's Client ID. can be found on the Application setting page.
  • Domain: Your Auth0 application's Domain. can be found on the Application setting page.
  • Audience: API Identifier for an access token. can be found on the API setting page.

Add roles to a user using Rules

You can manage role-based authorization with auth0 Rules, which is a mechanism that allows us to run some code when user register an account on auth0.

To do so, got to the Auth0 dashboard and create a new Rule (which can be found in Auth Pipeline on the side menu). Then fill the field with example code (Note that you should specify your own audience to namespace e.g. const namespace = 'https://api.fullstack-graphql-app.com'). And finally name the rule whatever you like.

After attached the rule, auth0 now add role to the user after a user registered the account on auth0.

const { loginWithRedirect } = useAuth0()

// Here "ADMIN" will be sent to auth0 and the rule put the role to jwt token.
loginWithRedirect({
  role: 'ADMIN',
})

Configure environment variables

In the root directory, Specify .env and .env.localhost file with the following environment variables:

.env

DATABASE_URL="mysql://fga:fga@db:3306/fga"
AUTH0_CLIENT_ID=<Client Id>
AUTH0_DOMAIN=<Domain>
AUTH0_AUDIENCE=<Audience>
GRAPHQL_END_POINT=http://localhost:5001/graphql

.env.localhost

DATABASE_URL="mysql://fga:fga@localhost:3306/fga"
AUTH0_CLIENT_ID=<Client Id>
AUTH0_DOMAIN=<Domain>
AUTH0_AUDIENCE=<Audience>
GRAPHQL_END_POINT=http://localhost:5001/graphql

And in the frontend root directory, Specify .env.local file with the following environment variables:

NEXT_PUBLIC_AUTH0_CLIENT_ID=<Client Id>
NEXT_PUBLIC_AUTH0_DOMAIN=<Domain>
NEXT_PUBLIC_AUTH0_AUDIENCE=<Audience>
NEXT_PUBLIC_GRAPHQL_END_POINT=http://localhost:5001/graphql

Backend

install deps

pnpm install

start server

docker-compose up

Graphql Playground will start on localhost:5001

scripts

The scripts you might frequently use:

  • db:migration:generate: Generates migration file (not apply automatically). Run this whenever you change your database schema.
  • db:migration:run: Runs generated migration file. Run this after you generate the migration file.
  • prisma-gen: Generates the Prisma client
  • prisma-studio: Starts Prisma Studio on localhost:5555 where you can inspect your local development database.

connect to your mysql database

 docker exec -it backend_db_1 mysql -u root -p

 mysql> use fga

Frontend

start

Run the command below. which uses turborepo cli internally and it runs shared ui package's watch script as well.

pnpm run dev

workflow

Update GraphQL API

1. Edit Schema file

path: apps/backend/src/api/graphql/typeDefs.ts

2. run graphql-codegen to generate files based on the latest schema

pnpm run generate:graphql

this will run turbo run codgen:graphql, which runs all codegen:graphql in each package.

Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].