How tensorplex-labs/dojo-worker-api works
Main Components
• Microservices: The repository contains multiple microservices such as:
– The main API server (located at cmd/server): This service likely acts as the central API endpoint.
– AWS integration service (cmd/aws) for cloud-specific operations.
– SIWS service (cmd/siws) for blockchain or smart contract related operations.
– Seeder service (cmd/seed) for data initialization (evidenced by fixture files and JSON seed data).
• Core Functionality Modules: Under pkg, you have several modular components including:
– API components (pkg/api) that involve controllers, middleware, routing, and rate limiting.
– Authentication (pkg/auth) and blockchain integrations (pkg/blockchain) which include SIWS logic.
– ORM packages (pkg/orm) managing database interactions (aligned with the Prisma schema and migrations).
– Additional helper services for caching, emailing, events, metrics, sandboxing, task processing, and worker management.
• Database: A PostgreSQL instance is expected (as indicated by the docker-compose and instructions for setting up a local Postgres instance).
• External Tools & Libraries:
– Swagger for API documentation (see gin-swagger annotations and usage).
– Docker & Docker Compose for containerizing local environments and running the database.
– Prisma (schema.prisma, Dockerfile.prisma, migrations) for data modeling and database operations.
Relationships and Interactions
• Clients (e.g., REST client, browser, or automated clients) send HTTP requests to the main API service (cmd/server).
• The API service relies on internal controllers, middleware, and routes defined in pkg/api to process these requests.
• Depending on the request, the API service interacts with underlying modules like authentication (pkg/auth), blockchain (pkg/blockchain), and task management (pkg/task).
• These business logic components in turn use ORM (pkg/orm) for database operations which communicate with the PostgreSQL instance.
• Other supporting functionalities include caching, emailing, and event services, which may interact with external systems (like an email service provider or cloud services via the AWS microservice).
• The SIWS component (under both cmd/siws and pkg/blockchain/siws) handles blockchain identity aspects.
• The Swagger documentation is generated and served through the API (as part of cmd/server), allowing interactive API testing and reference.
Architectural Patterns and Design Principles
• Microservice Structure: The use of multiple “cmd” directories suggests that each service is standalone yet shares common libraries (found under pkg) ensuring code reuse.
• Separation of Concerns: By dividing authentication, blockchain, ORM, and various utility functions into distinct packages, the design is modular and easier to maintain.
• API Documentation Integration: Use of swagger annotations and generated documentation reinforces good practices in API clarity and consistency.