DEV Community

Cover image for How to build an event management application in Amplication
Marcílio Júnior
Marcílio Júnior

Posted on

How to build an event management application in Amplication

In this article, we will guide you through the process of building a fully functional event management platform using Amplication. Amplication is a powerful open-source development platform designed to streamline the creation of scalable and secure Node.js applications.

But first, why choose Amplication as the foundation of your application? One obvious reason is its exceptional speed and efficiency, which can significantly enhance your application's performance and, consequently, the user experience. So, let's dive right into harnessing the capabilities of Amplication to create your event management platform.

Prerequisites

To successfully follow this tutorial, please ensure you have the following installed on your computer:

Required Software:

  1. Node.js
  2. npm
  3. Code Editor (such as Visual Studio Code)
  4. Web browser or Postman
  5. Docker Compose

Having these tools in place will facilitate your participation in this tutorial.

Finally, you'll need an Amplication account for your Amplication development environment. If you don't already have one, simply visit their website to create a free account.

Create your service in Amplication

If you prefer, follow the official Amplication guide on the page.

  1. Create Your Amplication Account

To begin, register for an Amplication account. Afterward, authorize your account with GitHub.

  1. Name Your Application

When choosing a name for your service, focus on its primary function and the problem it solves. A well-named service is easier to recognize and manage.

backend
Enter fullscreen mode Exit fullscreen mode
  1. Link Your GitHub Repository

Amplication will automatically synchronize your generated service with a chosen GitHub repository. Learn more at: sync-with-github.

  1. Customize Your Service

Amplication can generate GraphQL APIs, REST APIs, and an Admin UI for your services. Choose the components you need.
In our example, we'll enable only the REST API & Swagger and continue.

  1. Select Your Repo Style

Select the storage method for your service in your repository: Monorepo or Polyrepo.

In our example, we'll enable Monorepo. It's recommended if you plan to have multiple services in a single GitHub repository.

./apps
  - apps/my-new-service 
  - apps/my-new-service-admin
Enter fullscreen mode Exit fullscreen mode
  1. Choose Your Database

Amplication natively supports PostgreSQL, MongoDB, and MySQL. Select the one that best fits your requirements. In our example, we've chosen MySQL.

  1. Define Your Data Model

Define your database entities and fields. You can either create them manually or utilize a template offered by Amplication. In our example, we've chosen to start from scratch.

  1. Include Authentication

Optionally, you can incorporate the required authentication code in your service. If your service doesn't require authentication, you can choose to skip it. In our example, we prefer to include authentication, so we select the 'Include Auth Module' option.

You're Finished!

Congratulations! Your first Amplication service is now set up. You'll be directed to a screen where Amplication will begin generating all the required code for your service in real time.

Amplication page- Service created successfully

Creating/Modifying our entities

Once your first service is successfully created, the next steps involve adding entities, roles, and permissions to your service. Let's now create our event entity and adjust the relationship between the user and event entities.

  1. Add Event Entity

Click on "Add Entity," enter the name "Event," and then click "Create Entity."

Amplication page - Add new entity

  1. Add Entity Fields

After creating the event entity, add the fields that will represent the event. In our example, we've included the following fields:

  • category (String)
  • description (String)
  • endDate (DateTime)
  • startDate (DateTime)
  • imageUrl (String, optional)
  • locationPoint (String, optional)
  • title (String)
  • venue (String)
  • User (String)

In the User field, navigate to Data Type, select Relation to Entity, then in Related Entity, choose the User entity, and specify 'One Event can be related to one User'. If desired, you can add a label for the Foreign Key in 'Foreign Key Field Name'.

Amplication page - Event entity (User field)

After this, navigate to the User entity. You'll notice that the relationship between the User entity and the Event entity is automatically configured. Just ensure that the relationship is set to 'One User can be related to many Events'.

Amplication page - User entity (Event field)

Navigate to the "Permissions" section and modify the permissions to allow viewing, creating, and searching for users.

Amplication page - User entity (Edit Permissions)

Once you've completed the entity configurations, commit the changes, and proceed to VS Code by clicking on 'Commit changes & build'.

Getting started In VS Code

  1. Open the terminal and clone the repository selected in Amplication.
git clone https://github.com/jrsmarcilio/event-management-system.git
Enter fullscreen mode Exit fullscreen mode
  1. Enter the folder and change branch:
cd event-management-system; git checkout amplication
Enter fullscreen mode Exit fullscreen mode
  1. Go to project folder and install npm packages:
cd apps/backend; npm i
Enter fullscreen mode Exit fullscreen mode
  1. Create the .env file and add the environment variables:
PORT=3000

BCRYPT_SALT=10

JWT_SECRET_KEY=secret
JWT_EXPIRATION=1h

DB_PORT=3306
DB_HOST=localhost
DB_USER=root
DB_PASSWORD=amplication
DB_NAME=amplication
DB_URL=mysql://${DB_USER}:${DB_PASSWORD}@${DB_HOST}:3306/${DB_NAME}
Enter fullscreen mode Exit fullscreen mode
  1. Create the docker-compose.dev.yml file and add content:
version: "3"
services:
  db:
    image: mysql
    command: --default-authentication-plugin=mysql_native_password
    restart: always
    ports:
      - ${DB_PORT}:3306
    environment:
      MYSQL_ROOT_PASSWORD: ${DB_PASSWORD}
      MYSQL_DATABASE: ${DB_NAME}
    healthcheck:
      test:
        - CMD
        - mysqladmin
        - ping
        - -h
        - localhost
        - -u
        - ${DB_USER}
      timeout: 45s
      interval: 10s
      retries: 10

volumes:
  mysql: ~
Enter fullscreen mode Exit fullscreen mode
  1. Create MySQL container and volume:
docker compose -f docker-compose.dev.yml up -d
Enter fullscreen mode Exit fullscreen mode
  1. To map your data model to the database schema, you need to use the prisma migrate CLI commands:
npx prisma migrate dev --name init
Enter fullscreen mode Exit fullscreen mode
  1. Generate Prisma Client with the following command:
npx prisma generate
Enter fullscreen mode Exit fullscreen mode
  1. Initialize the project:
npm start #or yarn start
Enter fullscreen mode Exit fullscreen mode

Congratulations for getting this far. You have just built your event management application fully on the Amplication 👏🏼.

Top comments (0)