Skip to content

Latest commit

 

History

History
225 lines (138 loc) · 6.94 KB

README.md

File metadata and controls

225 lines (138 loc) · 6.94 KB

Account Service

The Account Service is a crucial component of the Gateway suite, enabling easy interaction with DSNP accounts on Frequency. This document provides an overview of the service, its architecture, and guides for setup and usage.

📗 Table of Contents

📖 About the Project

The Account Service simplifies the management of user accounts, defined by a user's handle and MSA Id (Message Source Account Identifier) on the Frequency blockchain using DSNP protocols.

🔍 Architecture Overview

The Account Service is built using NestJS and is divided into two main components:

  1. API: Handles incoming HTTP requests
  2. Worker: Processes jobs that require blockchain interaction

Gateway Account Service Architecture

🔑 Key Features

  • Account creation using SIWF (Sign-In With Frequency)
  • User and Provider Account management
  • Handle (username) claiming and management
  • Key management (adding and retrieving keys)
  • Delegation info retrieval for MSA Id
  • Seamless integration with Web3 wallets

💻 Getting Started

This section will guide you through setting up the Account Service for both quick start and local development.

Prerequisites

Ensure you have the following installed:

Quick Start

  1. Clone the repository and navigate to the project directory:

    git clone https://github.com/ProjectLibertyLabs/gateway.git
    cd gateway
  2. Copy the environment template:

    cp env-files/account.template.env .env.account

    Ensure that the .env.account file is correctly configured for your environment. For more information, refer to the Environment Variables section in the full documentation. Specifically, you will need to set the FREQUENCY_API_WS_URL, etc., to the correct network (e.g., wss://0.rpc.testnet.amplica.io).

  3. Install dependencies:

    npm install
  4. Start supporting services (local frequency node, redis) using Docker:

    ./scripts/account/restart-chain-docker.sh
  5. Start account service api and worker applications using Docker:

    docker compose -f docker-compose.yaml -f docker-compose-e2e.account.yaml --profile account up -d

Local Development (without containers)

If you prefer to run services locally for development:

  1. Start Redis and Frequency:

    ./scripts/account/restart-local-dev.sh
  2. Start the mock webhook server (in a new terminal):

    cd webhook-servers && cargo run
  3. Start the API (in a new terminal):

    npm run start:account-api:dev
  4. Start the Worker (in another new terminal):

    npm run start:account-worker:dev

Verification

Next Steps

After setting up the Account Service, you can:

  • Explore the API using the Swagger UI
  • Run the test suite to ensure everything is working correctly
  • Start integrating the Account Service into your application

For more detailed setup instructions, environment variable configuration, and advanced usage, please refer to our comprehensive documentation.

🚀 API Documentation

Live OpenAPI Docs

Explore our Live API Documentation for detailed information on endpoints and usage.

🛠 Development

This section covers testing, debugging, linting, and information about the technologies used in the Account Service.

Testing

Run E2E tests:

make test-e2e-account

Access Swagger UI: http://localhost:3000/api/docs/swagger

Manage queues: http://localhost:3000/queues

Linting

To run the linter:

npm run lint

To automatically fix linting issues:

npm run format

Debugging

Using Docker

To stop containers, networks, volumes, and images created by docker compose up, run:

docker compose down

Note: You may need to manually remove containers using the Docker Desktop app.

Using the Debugger with VSCode

  1. Follow step 1 from the Development Environment section above to set up the Redis and Frequency containers.

  2. Use the debug panel and start the Debug Api (NestJS via ts-node) configuration to debug the API.

    Use the debug panel and start the Debug Worker (NestJS via ts-node) configuration to debug the worker.

  3. Set breakpoints in the code and debug your code.

  4. Monitor the service worker jobs in BullUI.

    Any API functions that require an extrinsic to be submitted to the blockchain will be queued here. The queue will manage the amount of capacity this service is allowed to use.

  5. Use Swagger to test the API.

Reference the Frequency Docs for more information about extrinsics and capacity.

Note: Reference .vscode/launch.json for more details on the debug configurations and apply the concepts to your preferred debugger.

Built With

  • Framework: NestJS
  • Language: TypeScript
  • Testing: Jest, Supertest
  • Data Store: ioredis
  • API Documentation: Swagger
  • Containerization: Docker, Docker Compose

For a complete list of technologies used, please refer to the Tech Stack section in the full documentation.

🤝 Contributing

We welcome contributions! Please check our Contributing Guidelines and open issues.

❓ FAQ

Q: Can I use this service in my production social app?

Yes, Gateway Services are designed to be ready-to-use out of the box for social media apps using DSNP on Frequency.

Q: Will the Account Service scale for large applications?

The service is designed to support small-to-medium-sized social apps. For larger use cases, custom solutions may be necessary.

📝 License

This project is licensed under the Apache 2.0 License.

(back to top)