Skip to main content

Pokedex

Pokedex web service

Goal

Create a Pokedex web service to record Pokemons and their abilities.

Features

  1. Create a new Pokemon
  2. Update an existing Pokemon
  3. Delete an existing Pokemon
  4. List all Pokemons
  5. Find a Pokemon by ID
  6. Find a Pokemon by Name

Technical Implementation

Techstack

  • Go as the programming language
  • Use Go-Chi as the web framework
  • GraphQL as API interface (recommended framework - gqlgen)
  • SQLite as persistent storage (recommended sql library - bun, GORM)

Technical requirement

  1. The applicatoin must be a web service.
  2. Use SQLite as persistent storage. You must design your own database and how you will store data.
  3. API interface must be GraphQL.

Data structure

type: Pokemon
properties:
- property_name: name
data_type: string
- property_name: description
data_type: string
- property_name: category
data_type: string
- property_name: type
data_type: [PokemonType]
- property_name: abilities
data_type: [string] (array of strings)

Design guide

This is complex program. Design steps should be taken carefully.

Software layers

Software layer

Application will be divided into 2 layers which are

  1. Persistent layer

    Persistent layer is the software that interacts with the database.

  2. API layer

    API layer is the software that interacts with the user. The API layer should pass information to the persistent layer and perform database operation.

Design steps

  1. Design database

You should design how your data will look like. After that, create an SQLite database using SQLite CLI or Dbeaver.

note

Installing SQLite on Ubuntu ::

  1. Design persistent layer

After finishing design the database, start designing the persistent layer. This layer should be a package that contains functions that could add, update, delete, and find entries from the database.

You have to create a database connection and utilize it to perform database operations.

  1. Design API layer

In this step, you could create the APIs at which for the user to make a request.

For GraphQL, you must design the schema first. You have to define type, input, mutation, and query and then generate the server.

  1. Combining code

    After everything is ready, it's time to combine all the code to make the application usable.

Project Structure Example

For structuring the project , you can create by yourself or Following this structure:

  • 📁 database: Contains project documentation.
    • 📄 db.go
    • 📄 db_model.go
  • 📁 graph: *Generate auto by gqlgen
    • 📁 model:*Generate auto by gqlgen
      • 📄 model_gen.go:*Generate auto by gqlgen
    • 📄 generated.go:*Generate auto by gqlgen
    • 📄 resolver.go:*Generate auto by gqlgen
    • 📄 shema.resolver.go:*Generate auto by gqlgen
    • 📄 resolver.go:*Generate auto by gqlgen
  • 📄 main.go
  • 📄 mod.go
  • 📄 sum.go

Useful resources