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.
- Blockchain: NEAR
- Smart Contracts: Sputnik DAO Factory V2, Sputnik DAO V2
- Server Environment: NodeJS
- Package manager: Yarn
- Core programming language: TypeScript
- Application framework: NestJS
- Database: PostgreSQL, MongoDB, TypeORM
- Near API: near-api-js
- Indexer: Astro Lake Framework
- Caching/Events/Streams: Redis
- Notifications: Notifi
- Monitoring: Datadog
- Code quality: Eslint, Prettier
- Build: Docker
- 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.
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.
/apps
/aggregator
/api
/draft
/indexer-processor
/notifier
/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
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
- Clone the repo:
git clone git@github.com:near-daos/astro-api-gateway.git
- Open the repo folder:
cd astro-api-gateway
- Install dependencies:
yarn
-
Add
.env.local
to the root folder with required environment variables described in.env
. -
Run dev docker compose:
docker-compose -f docker-compose-dev.yml up
Please make sure that Docker has been installed on your local machine.
- 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
- Change entity definition
- If creating new entity, make sure it's specified in
ormconfig.js
- Generate migration via:
yarn migration:generate
node -r ts-node/register -r tsconfig-paths/register ./node_modules/typeorm/cli.js migration:generate -n <MigrationName>
- Review generated migration & fix migration code style & lint warnings
- Run new migrations via:
yarn migration:run
- If something went wrong, revert the last migration via:
yarn migration:revert
- Commit changes
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