Skip to content

consolelabs/mochi-api

Repository files navigation

Mochi Bot API

Overview

This repository is official BE service for Mochi bot

How to contribute

Prerequisites

  1. Go installed
  2. Docker installed
  3. Set up discord bot
  4. Owned a Metamask’s wallet. If not:
    1. Install Metamask on your browser
    2. After successful installation, you will be redirected to Metamask’s Getting started page. Follow the steps to create your own wallet

How to run source code locally

  1. Set up source

    Set up infras (db, redis), install dependencies, etc.

    make setup
    
  2. Set up env

    Update these variables inside .env, How to get mnemonic

    CENTRALIZED_WALLET_PRIVATE_KEY=“your metamask wallet mnemonic”
    DISCORD_TOKEN='your discord bot token'
    
  3. Run source

    make dev
    

    You should see the service starting with port 8200 as default

How to work on a TODO

  1. Feel free to pick any TODO for you from Board View → Mochi → Backlog**
  2. Assign that item to your account
  3. Remember to update item’s status based on your working progress
    • Backlog: not started yet
    • In Progress: still working on
    • In Review: Task done = PR has been merged to develop branch at least
    • Completed: Confirmation from the team that the TODO is completely finished
  4. When switching your TODO to In Review, remember to fill these in

Untitled

PR template

**What does this PR do?**

- [x] New API for updating ...
- [x] Update logic of ...
- [x] Fix error ...

**How to test**

- cURL
- Steps to test new logic
- etc.

**Flowchart** (optional)
Should have if the flow is complex

**Media** (Demo) (optional)
Attach images or demo videos
Can insert video URL in case the size exceeds github limit

Technical Document

  1. Project structure
  • cmd/ this folder contains the main application entry point files for the project
    • server/main.go: Containing init function main() of the service. This function will be executed when we run make dev
    • Other main.go files (e.g. fetch-discord-users/main.go): Entry points to execute some functional jobs. k8s Cronjob will be set up to execute these jobs schedually
  • docs/: contains Swagger documentation files generated by swaggo
  • migrations/: contains seeds and SQL migration files
    • schemas/: contains DB schema migration files
    • seed/: contains seed files which will initialize DB with sets of dummy data
    • test-seed/: also seed files but for test DB
  • pkg/: contains core source code of service
    • cache/: caching initial and functional methods
    • chain/: crypto chains’ initial and functional methods
    • config/: contains configs loaded from .env
    • constants/: constant variables
    • discordwallet/: methods to initialize & interact with crypto’s wallets (managed by Mochi)
    • handler/: handling API requests
    • entities/: where mainly core business logic happens, invoked by handler and cmd
    • job/: contains initial and Run() as execution functions. These are invoked by main() from main.go files (except server/main.go)
    • logger/: logging initial and functional methods
    • model/: DB model structs
    • repo/: data access layer, contains DB CRUD operations (see gorm)
    • request/ & response/: API request & response models
    • routes/: API routing (see gin)
    • services/: contains interaction with external services (coingecko API, binance API, etc.)
    • util/: utility methods
  1. Modules references
  1. Sample usecases

    1. Create new API

      • Check out file /pkg/routes/v1.go and explore the code flow to see how to create and handle an API
      • Remember to annotate handler functions with swaggo. Then run make gen-swagger to generate Swagger documentations
    2. New DB migration

      Check out .sql files under /migrations to write a valid schema migration / seed file

      • To apply new migration files, run make migrate-up
      • To apply seed files, run make seed-db
      • To apply new migration files for test DB, run make migrate-test

      Note: remember to run these 2 every time you pulling new code

      make migrate-up
      make migrate-test
      
    3. DB repositories

      Check out dirs under /pkg/repo Note: remember to run make gen-mock to generate mocks for new store file

🙏 Credits

A big thanks to all who contributed to this project!

If you'd like to contribute, please check out the contributing guide.

Contributing

Keep in touch

  • Reach us at discord.
  • Discuss development in the #build-with-us channel.