This app is used to tutor client server architecture.
It is a simple poll app that allows users to create polls and vote on them.
On the main branch you can find the finished app. You can use the commits to see the changes step by step.
On the start branch you can find the app without any logic. This is the perfect place to start with your own implementation.
- Install Node.js
- Install DockerDesktop
- Install dependencies:
npm install - Copy the
dist.envfile to.envand fill in any values
- Start the dockerized database:
docker-compose up - Start the server:
npm run dev
You can now access the client at http://localhost:3000
Prisma is used to generate the database schema and to access the database.
- Start the dockerized database:
docker-compose up - Run
npx prisma initto initialize the prisma configuration - Fill the schema in
prisma/schema.prisma - Generate the migration for your defined schema with:
npx prisma migrate dev --name {migration-name}
From now on, you can use the prisma client to access the database.
Every time you change the schema, you have to generate a new migration with npx prisma migrate dev --name {migration-name}.
The app is split into two parts: the server and the client. Views are rendered on the server and the client only sends requests to the server. Post requests are used to modify the database and trigger window reloads.
In this example, there are two entities: polls and votes.
- A poll has many votes.
- A poll has a name.
- A vote belongs to a poll.
- A vote has a voted option.
- Voted options are either
YES,NOorABSTENTION.
- Voted options are either
- A vote has a voter name.
- A vote has a poll id.
- A vote has a voted option.
docker-compose.ymlcontains the configuration for the dockerized databaseprisma/contains the prisma configuration and the database schema as well as the migrationssrc/contains the source codesrc/config.jscontains the configuration for the server and exports it, split into express-related (server) and prisma-related (prisma) configurationsrc/server.jscontains the routes and imports the configurationsrc/views/contains the handlebars templatessrc/public/contains the static filessrc/queriescontains the prisma queries