diff --git a/developer-docs/account/README.md b/developer-docs/account/README.md index 912af631..df463e83 100644 --- a/developer-docs/account/README.md +++ b/developer-docs/account/README.md @@ -1,358 +1,135 @@ # Account Service - +## 📗 Table of Contents -# 📗 Table of Contents - -- [📖 About the Project](#account-service) -- [🔍 Arch Map](#-arch-maps) -- [🛠 Built With](#built-with) - - [Tech Stack](#tech-stack) - - [Key Features](#key-features) -- [🚀 Live OpenAPI Docs](#-live-docs) -- [💻 Getting Started](#-getting-started) - - [Prerequisites](#prerequisites) - - [Environment Variables](#environment-variables) - - [Install](#install) - - [Usage](#usage) +- [📖 About the Project](#about-project) +- [🔍 Architecture Overview](#architecture-overview) +- [🔑 Key Features](#key-features) +- [💻 Getting Started](#getting-started) +- [🚀 Live OpenAPI Docs](#live-docs) - [📋 Testing](#testing) - - [Swagger UI](#swagger-ui) - - [Queue Management](#queue-management) - - [Linting](#linting) - - [Auto-format](#auto-format) - - [Debugging](#debugging) - - [Debugging with VSCode](#using-the-debugger-with-vscode) -- [🤝 Contributing](#-contributing) -- [⭐️ Show your support](#show-your-support) -- [❓FAQ](#faq) -- [📝 License](#-license) - - - -# 📖 `account-service` - -Account Service is a service enabling easy interaction with [DSNP](https://dsnp.org/) accounts on [Frequency](https://docs.frequency.xyz/). Accounts can be defined as a user's handle and MSA Id. +- [🛠 Built With](#built-with) +- [🤝 Contributing](#contributing) +- [❓ FAQ](#faq) +- [📝 License](#license) -Visit [Key Features](#key-features) for more details on what Account Services does. +## 📖 About the Project - +The Account Service is a crucial component of the Gateway suite, enabling easy interaction with [DSNP](https://dsnp.org/) accounts on [Frequency](https://docs.frequency.xyz/). It simplifies the management of user accounts, defined by a user's handle and MSA Id (Message Source Account Identifier). -## 🔭 Arch Maps +## 🔍 Architecture Overview -The account-service is a NestJS application that is split into two main parts: the API and the Worker. +The Account Service is built using NestJS and is divided into two main components: -The API is responsible for handling incoming HTTP requests and the Worker is responsible for processing jobs that require blockchain interaction. +1. **API**: Handles incoming HTTP requests +2. **Worker**: Processes jobs that require blockchain interaction -![Gateway Account Service](./account_service_arch.drawio.png) +![Gateway Account Service Architecture](./account_service_arch.drawio.png) -

(back to top)

+## 🔑 Key Features -## 🛠 Built With +- Account creation using [SIWF](https://github.com/ProjectLibertyLabs/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 -### Tech Stack - -
- Framework - -
- -
- Language - -
- -
- Testing Libraries - -
- -
- Linting - -
- -
- Data Store - -
- -
- Request Library - -
- -
- Scheduling - -
- -
- Validation - -
- -
- Environment Configuration - -
- -
- Code Quality - -
- -
- Containerization - -
- -
- API Documentation - -
- - - -### Key Features - -- **Account creation using [SIWF](https://github.com/ProjectLibertyLabs/siwf)** - - Includes behind the scenes delegation to the provider -- **Get User and Provider Account(s)** -- **Handle (aka username) claiming** - - Create - - Change -- **Keys Handling** - - Add keys to an account - - Get keys -- **Get delegation info for an MSA Id** -- **Easy integration with Web3 wallets** - -

(back to top)

- - - -## 🚀 Live Docs - -- [Live Docs](https://projectlibertylabs.github.io/account-service) - -

(back to top)

- - - -## 💻 Getting Started - -To get a local copy up and running, follow these steps. +## 💻 Getting Started ### Prerequisites -In order to run this project you need: - +Ensure you have the following installed: - [Node.js](https://nodejs.org) - [Docker](https://docs.docker.com/get-docker/) -### Environment Variables - -Modify any environment variables in the `.env` file as needed. The complete set of environment variables is documented [here](./ENVIRONMENT.md), and a sample environment file is provided [here](../../env-files/account.template.env). - -1. Copy the template values into the .env.account file. - -```sh - cp env-files/account.template.env .env.account -``` - -2. Replace template values with values appropriate to your environment. - -### Install - -Install NPM Dependencies: - -```sh - npm install -``` +### Quick Start -### Usage +1. Clone the repository and navigate to the project directory: + ```bash + git clone https://github.com/ProjectLibertyLabs/gateway.git + cd gateway + ``` +2. Copy the environment template: + ```bash + cp env-files/account.template.env .env.account + ``` +3. Install dependencies: + ```bash + npm install + ``` +4. Start all services using Docker: + ```bash + ./scripts/account/restart-chain-docker.sh + ``` +### Local Development (without containers) -Note: using [docker compose file](../../docker-compose.yaml) to start the services. This will start the services in development mode. +If you prefer to run services locally for development: -The following command will start all of the necessary containers for the account service to run in development mode. +1. Start Redis and Frequency: + ```bash + ./scripts/account/restart-local-dev.sh + ``` -```bash -./scripts/account/restart-chain-docker.sh -``` +2. Start the mock webhook server (in a new terminal): + ```bash + cd rust-webhook-server && cargo run + ``` -In order to run the `account-service` in development mode without containers, you can use the following commands: +3. Start the API (in a new terminal): + ```bash + npm run start:account-api:dev + ``` -#### 1. Start the Redis server container and the Frequency container. You can view the logs with your Docker setup +4. Start the Worker (in another new terminal): + ```bash + npm run start:account-worker:dev + ``` -```bash -./scripts/account/restart-local-dev.sh -``` +### Verification -Once [Frequency](https://polkadot.js.org/apps/?rpc=ws%3A%2F%2F127.0.0.1%3A9944#/explorer) is up, you can monitor the transactions on the blockchain. +- Access Swagger UI: [http://localhost:3000/api/docs/swagger](http://localhost:3000/api/docs/swagger) +- View and manage queues: [http://localhost:3000/queues](http://localhost:3000/queues) -#### 2. Follow the instructions in the terminal to start the local apps. Start the mock webhook server by running the following command in another terminal or in the background +For more detailed setup instructions, environment variable configuration, and advanced usage, please refer to our [comprehensive documentation](#). -```sh -cd rust-webhook-server && cargo run -``` +## 🚀 Live OpenAPI Docs -#### 3. Start the Api and Worker.

- -**Option 1:** In a new terminal window, start the `account-service` api app. Logs will be displayed in the terminal for easy reference. - -```sh -npm run start:account-api:dev -``` - -In another terminal window, start the `account-service` worker app. - -```sh -npm run start:account-worker:dev -``` - --- or --

- -**Option 2:** -Run the following command to start the account service api and worker containers. This will start the account service api and worker in development mode. - -```sh -docker compose up -d account-service-api account-service-worker -``` - -#### 4. Check the job in [BullUI](http://0.0.0.0:3000/queues/), to monitor job progress based on defined tests +Explore our [Live API Documentation](https://projectlibertylabs.github.io/account-service) for detailed information on endpoints and usage. ## 📋 Testing -### Run the tests - -Make sure to follow the steps above and use `restart-chain-docker.sh` to start the services. This will ensure that the local node is running and is properly configured. Then run the following command to run the tests. **NOTE:** The tests are not idempotent. When re-running the e2e tests, use the `restart-chain-docker.sh` script to reset the chain. - -```bash -make test-e2e-account -``` - -This will run the tests in `apps/account-api/test` folder. - -#### Check e2e test file for more details on the test - -### Swagger UI - -Check out the Swagger UI hosted on the app instance at [http://localhost:3000/api/docs/swagger](http://localhost:3000/docs/swagger) to view the API documentation and submit requests to the service. - -### Queue Management +- Run E2E tests: `make test-e2e-account` +- Access Swagger UI: [http://localhost:3000/api/docs/swagger](http://localhost:3000/docs/swagger) +- Manage queues: [http://localhost:3000/queues](http://localhost:3000/queues) -You may also view and manage the application's queue at [http://localhost:3000/queues](http://localhost:3000/queues). +For more testing options, including linting and debugging, please see the [Testing](#testing) section in the full documentation. -### Linting - -```sh - npm run lint -``` - -### Auto-format - -```sh - npm run format -``` - -### Debugging - -- Docker to stop containers, networks, volumes, and images created by `docker compose up` run... - - ```sh - docker compose down - ``` - -- You may have to go to your Docker Desktop app and manually remove containers. - -### 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, if you wish to debug the api. - - Use the debug panel and start the `Debug Worker (NestJS via ts-node)` configuration, if you wish to debug the worker. - -3. Set breakpoints in the code and debug your code. - -4. Monitor the service worker jobs in [BullUI](http://0.0.0.0:3000/queues/). - - 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. - - Reference the [Frequency Docs](https://docs.frequency.xyz/) for more information about extrinsics and capacity. - -5. Use [Swagger](http://0.0.0.0:3000/api/docs/swagger) to test the API. - -**Note:** Reference `.vscode/launch.json` for more details on the debug configurations and apply the concepts to your preferred debugger. - -

(back to top)

- - - -## 🤝 Contributing - -Contributions, issues, and feature requests are welcome! - -- [Contributing Guidelines](./CONTRIBUTING.md) -- [Open Issues](https://github.com/ProjectLibertyLabs/gateway/issues) - -

(back to top)

- - - -## ⭐️ Show your support - -If you would like to explore contributing bug fixes or enhancements, issues with the label `good-first-issue` can be a good place to start. - -

(back to top)

- - +## 🛠 Built With -## ❓FAQ +- **Framework**: NestJS +- **Language**: TypeScript +- **Testing**: Jest, Supertest +- **Data Store**: ioredis +- **API Documentation**: Swagger +- **Containerization**: Docker, Docker Compose -- **Can I use this service in my production social app?** +For a complete list of technologies used, please refer to the [Tech Stack](#tech-stack) section in the full documentation. - - Yes. All the Gateway Services are intended to be ready-to-use out of the box as part of the fabric of your own social media app using DSNP on Frequency. +## 🤝 Contributing -- **I'm building the next Facebook, it's going to be huge! Will `account-service` scale?** +We welcome contributions! Please check our [Contributing Guidelines](./CONTRIBUTING.md) and [open issues](https://github.com/ProjectLibertyLabs/gateway/issues). - - Gateway Services are designed to support the scale of a small-to-medium-sized social app. For larger use cases, you would probably want to build your own services. +## ❓ FAQ -

(back to top)

+**Q: Can I use this service in my production social app?** +A: 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?** +A: The service is designed to support small-to-medium-sized social apps. For larger use cases, custom solutions may be necessary. -## 📝 License +## 📝 License -This project is [Apache 2.0](./LICENSE) licensed. +This project is licensed under the [Apache 2.0 License](./LICENSE). -

(back to top)

+

(back to top)

\ No newline at end of file