Pokedex
Pokedex web service
Goal
Create a Pokedex web service to record Pokemons and their abilities.
Features
- Create a new Pokemon
- Update an existing Pokemon
- Delete an existing Pokemon
- List all Pokemons
- Find a Pokemon by ID
- 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
- The applicatoin must be a web service.
- Use SQLite as persistent storage. You must design your own database and how you will store data.
- 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
Application will be divided into 2 layers which are
-
Persistent layer
Persistent layer is the software that interacts with the database.
-
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
- Design database
You should design how your data will look like. After that, create an SQLite database using SQLite CLI or Dbeaver.
Installing SQLite on Ubuntu ::
- 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.
- 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.
-
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
- 📁 model:*Generate auto by gqlgen
- 📄 main.go
- 📄 mod.go
- 📄 sum.go