Giter Site home page Giter Site logo

next-fullstack-starter's Introduction

Next FullStack Starter

Next.js + TypeORM + TailwindCSS + (Type-)GraphQL

This project serves as the starting point of some of my SaaS products, so I'm continuously improving it.

Features

Documentation

Prerequisites

Moving .env.example to .env.

Then get your database ready, install PostgreSQL and make sure you have a user and database matching following config:

DB_USER=postgres
DB_PASS=random
DB_HOST=localhost
DB_PORT=5432
DB_NAME=mydb

You can also customize it by updating .env file.

Development

# Install dependencies
yarn

# Apply migrations if you're running for the first time
yarn migrate:deploy

# Start Next.js
yarn dev:server
yarn dev:app

NPM Scripts

yarn dev

Run the development server.

yarn g:gql

Generate React (Apollo) hooks for GraphQL queries, powered by GraphQL Code Generator

yarn g:prism

Generate Prisma client.

yarn migrate:save

Save migrate files, tyoically you should run this after making changes to prisma/schema.prisma.

yarn migrate:up

Applying local migrations to the database, run this after yarn migrate:save.

yarn migrate:rollback

Rollback the most recent migration.

Folder structure

.
├── README.md
├── graphql-codegen.yml
├── graphql.schema.json       # Auto-generated GraphQL schema
├── next-env.d.ts
├── next.config.js
├── package.json
├── postcss.config.js
├── prisma
│   └── schema.prisma         # Database schema
├── scripts
│   └── with-env.js           # Run command with `.env` file loaded
├── server
│   ├── auth.ts               # Auth helpers
│   ├── constants.ts
│   ├── db.types.ts           # Types from Prisma
│   ├── decorators            # ES decorators, mainly for Type GraphQL resolvers
│   ├── graphql.types.ts      # Types used by GraphQL resolvers
│   ├── guards                # Authorization
│   ├── passport.ts           # `passport` for social login
│   ├── prisma.ts             # Prisma instance
│   ├── resolvers             # GraphQL resolvers, powered by Type GraphQL
│   └── response.ts           # HTTP response helpers
├── src
│   ├── css                   # CSS, mainly tailwind.css
│   ├── generated             # Generate Apollo React hooks
│   ├── graphql               # .graphql files
│   └── pages                 # Next.js pages
├── tailwind.config.js
├── tsconfig.json
├── types.d.ts
└── yarn.lock

We also added two Next.js/TS aliases: @ for src folder and @server for server folder.

GraphQL

We create a GraphQL at /api/graphql using Apollo Server and Type GraphQL, GraphQL resolvers are populated at server/resolvers, consult Type GraphQL docs for more.

Every time you create a new resolver file you need to add it to src/pages/api/graphql.ts.

On the client-side we use Apollo Client to execute GraphQL query, you should write GraphQL queries using SDL in src/graphql and run yarn g:gql to generate corresponding React hooks, and import the generated hooks from src/generated/graphql like this:

import { useCurrentUserQuery } from '@/generated/graphql'

const currentUser = useCurrentUserQuery()

if (currentUser.loading) {
  return null
}

return <div>{currentUser.data.currentUser.name}</div>

Style guide

Variable casing

Use PascalCase for Component name, otherwise camelCase is preferred.

Filename casing

Use PascalCase for React component files, other wise use kebab-case.

License

MIT © EGOIST

next-fullstack-starter's People

Contributors

olvvlo avatar

Watchers

 avatar

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.