Skip to content

near-daos/astro-api-gateway

Repository files navigation

Astro API Gateway

Release version Build Launch API Autotests On Schedule Telegram group

Astro API Gateway contains list of services used by DAO applications based on Sputnik DAO Contracts version 2 on NEAR Protocol.

Main features:

  • Sync DAO Contracts data with the Database.
  • Provide API endpoints to interact with DAOs.
  • Produce DAO updates notifications.

Tech Stack

Services

  • Aggregator - sync blockchain historical data with the Database.
  • Indexer Processor - sync blockchain real-time data with the Database.
  • API - provides a set of API endpoints to view, filter, search, sync etc.
  • Draft - provides a set of API endpoints to manage draft proposals and comments.
  • Notifier - simple notification service for sending / subscribing on service events.

Services

Project Structure

Project has standard NestJS monorepo structure, where all services (aggregator, api, etc.) are separated on apps. All reusable modules separated on libs by domains and could be shared between different apps and libs itself.

Project Structure

Apps

/apps
  /aggregator
  /api
  /draft
  /indexer-processor
  /notifier

Libs

/libs
  /account
  /bounty
  /cache
  /comment
  /common
  /config
  /dao
  /dao-api
  /dao-settings
  /draft-comment
  /draft-proposal
  /error-tracker
  /event
  /migrations
  /near-api
  /near-indexer
  /notifi-client
  /notification
  /orm-migrations
  /otp
  /proposal
  /proposal-template
  /sputnikdao
  /stats
  /subscription
  /token
  /transaction
  /transaction-handler
  /utils
  /websocket

Config

Main config properties could be specified by environment variables defined in .env file.

All the configs are managed by config lib and shared between apps and libs.

/libs/config/src
  /aggregator-config.ts
  /api-config.ts
  /cache.ts
  /configuration.ts
  /dao-api.ts
  /database.ts
  /database-draft.ts
  /database-near-indexer.ts
  /draft-config.ts
  /indexer-processor-config.ts
  /near.ts
  /near-api.ts
  /near-config.ts
  /near-token-factory.ts
  /notifi.ts
  /notifier-config.ts
  /redis.ts
  /typeorm-config.service.ts

Getting Started

Local Development

  1. Clone the repo:
git clone git@github.com:near-daos/astro-api-gateway.git
  1. Open the repo folder:
cd astro-api-gateway
  1. Install dependencies:
yarn
  1. Add .env.local to the root folder with required environment variables described in .env.

  2. Run dev docker compose:

docker-compose -f docker-compose-dev.yml up

Please make sure that Docker has been installed on your local machine.

  1. Run all services in dev mode:
yarn start-dev

Or run specific service you need:

  • Aggregator: yarn start-aggregator:dev
  • API: yarn start-api:dev
  • Notifier: yarn start-notifier:dev

Migrations

Database migration workflow

  1. Change entity definition
  • If creating new entity, make sure it's specified in ormconfig.js
  1. Generate migration via:
  • yarn migration:generate
  • node -r ts-node/register -r tsconfig-paths/register ./node_modules/typeorm/cli.js migration:generate -n <MigrationName>
  1. Review generated migration & fix migration code style & lint warnings
  2. Run new migrations via: yarn migration:run
  3. If something went wrong, revert the last migration via: yarn migration:revert
  4. Commit changes

OR

You can sync database manually without running migration (NOT RECOMMENDED):

yarn schema:sync

Before syncing schema, a review of SQL queries to be executed is highly RECOMMENDED:

yarn schema:log