{"id":26659863,"url":"https://github.com/phantasma-io/explorerbackend","last_synced_at":"2025-03-25T11:15:50.281Z","repository":{"id":284069842,"uuid":"770364422","full_name":"phantasma-io/ExplorerBackend","owner":"phantasma-io","description":"Explorer Backend for Phantasma blockchain","archived":false,"fork":false,"pushed_at":"2025-03-24T02:14:49.000Z","size":1373,"stargazers_count":0,"open_issues_count":0,"forks_count":0,"subscribers_count":0,"default_branch":"main","last_synced_at":"2025-03-24T02:19:49.406Z","etag":null,"topics":["backend","blockchain","dapp","explorer","layer1","phantasma","phantasmachain","phantasmaio","smartnft","smartnfts"],"latest_commit_sha":null,"homepage":"https://explorer.phantasma.info/","language":"C#","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/phantasma-io.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2024-03-11T12:29:13.000Z","updated_at":"2025-03-23T15:04:11.000Z","dependencies_parsed_at":"2025-03-24T08:00:43.492Z","dependency_job_id":null,"html_url":"https://github.com/phantasma-io/ExplorerBackend","commit_stats":null,"previous_names":["phantasma-io/explorerbackend"],"tags_count":8,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/phantasma-io%2FExplorerBackend","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/phantasma-io%2FExplorerBackend/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/phantasma-io%2FExplorerBackend/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/phantasma-io%2FExplorerBackend/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/phantasma-io","download_url":"https://codeload.github.com/phantasma-io/ExplorerBackend/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":245449674,"owners_count":20617190,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["backend","blockchain","dapp","explorer","layer1","phantasma","phantasmachain","phantasmaio","smartnft","smartnfts"],"created_at":"2025-03-25T11:15:48.454Z","updated_at":"2025-03-25T11:15:50.150Z","avatar_url":"https://github.com/phantasma-io.png","language":"C#","readme":"# Explorer Backend\nA backend for Phantasma explorer\n\n## Installation\n\n### User\n\nCreate user 'pha'. All following steps will be using this user and home directory '/home/pha'.\n\n### Docker\n\nInstall Docker according to the following instruction: https://docs.docker.com/engine/install/\n\nCreate folder for containers:\n```\nmkdir /home/pha/docker\n```\n\n### PostgreSQL\n\nCreate folder for PostgreSQL:\n```\nmkdir /home/pha/docker/postgresql\n```\n\nCreate /home/pha/docker/postgresql/docker-compose.yml with the following content, replacing `CHANGE_ME` with real values:\n\n```\nservices:\n  postgres:\n    image: postgres:16\n    hostname: postgres\n    container_name: postgres\n    shm_size: 4gb\n    expose:\n      - 5432\n    ports:\n      - \"5432:5432\"\n    environment:\n      POSTGRES_USER: CHANGE_ME\n      POSTGRES_PASSWORD: CHANGE_ME\n    volumes:\n      - ./postgres-db:/var/lib/postgresql/data\n      - ./postgresql.conf:/etc/postgresql/postgresql.conf\n    restart: unless-stopped\n    networks:\n     - postgresql\n    command: postgres -c config_file=/etc/postgresql/postgresql.conf\n\nnetworks:\n   postgresql:\n      name: postgresql-network\n```\n\nGet PostgreSQL configuration file from the container and put it here:\n/home/pha/docker/postgresql/postgresql.conf\n\nTo copy configuration from a running container following command can be used:\n```\ndocker cp `docker ps -aqf \"name=^postgres$\"`:/var/lib/postgresql/data/postgresql.conf /home/pha/docker/postgresql/\n```\n\nThis tool can be used to get optimized settings for postgres: https://pgtune.leopard.in.ua/\nPlace optimized settings at the start of postgresql.conf.\n\nStart PostgreSQL with following commands:\n```\ndocker compose pull\ndocker compose up -d\n```\n\n### EFCore tools\n\nInstall dotnet-sdk-8.0 using following instructions:\n\nhttps://learn.microsoft.com/dotnet/core/install/linux\n\nInstall Entity framework tools using following command:\n```\ndotnet tool install --global dotnet-ef\n```\n\n### Backend: Step 1: Prepare folders\n\nCreate following folders:\n```\nmkdir -p /home/pha/docker/explorer-backend/api\nmkdir -p /home/pha/docker/explorer-backend/database-migration\nmkdir -p /home/pha/docker/explorer-backend/worker\n```\n\nCopy content of ExplorerBackend/Backend.Service.Api/Docker folder into /home/pha/docker/explorer-backend/api.\n\nCopy content of ExplorerBackend/Backend.Service.Worker/Docker folder into /home/pha/docker/explorer-backend/worker.\n\nCopy backend's configuration file ExplorerBackend/explorer-backend-config.json to 'api/config' and 'worker/config' folders, ensuring that DatabaseConfiguration-\u003eMain and DatabaseConfiguration-\u003eApiCache sections of config contain correct settings, specifically database user name and password.\n\nCreate link to config for database-migration folder using command:\n```\nln -s /home/pha/docker/explorer-backend/worker/config/explorer-backend-config.json /home/pha/docker/explorer-backend/database-migration/explorer-backend-config.json\n```\n\nCopy files ExplorerBackend/database-api-cache-update.sh and ExplorerBackend/database-update.sh into /home/pha/docker/explorer-backend/database-migration.\n\n### Backend: Step 2: Create databases\n\nOn machine with installed dotnet-sdk-8.0 run following command to publish database migrations:\n```\nExplorerBackend/publish-db-migrations.sh\n```\n\nCopy ExplorerBackend/publish/bin to target machine to folder /home/pha/docker/explorer-backend/database-migration/bin.\n\nSwitch to /home/pha/docker/explorer-backend/database-migration/ folder and create new databases using following commands:\n\n```\nsh database-api-cache-update.sh\nsh database-update.sh\n```\n\n### Backend: Step 3: Finish deployment\n\nAdd files /home/pha/docker/explorer-backend/api/.env and /home/pha/docker/explorer-backend/worker/.env with the following content:\n```\n# Github branch to be used\nBUILD_BRANCH=main\n```\nwhere 'main' is main github branch of backend project which we use for production deployment.\n\nLaunch both API and Worker services from corresponding folders /home/pha/docker/explorer-backend/api and /home/pha/docker/explorer-backend/worker by either using sh script 'deploy.sh'\n```\ndeploy.sh\n```\nor by running commands\n```\ndocker compose pull\ndocker compose up -d\n```\n\n### Nginx\n\nSwitch to 'root' user or use sudo.\n\nInstall Nginx package.\n\nPlace list of Cloudflare IP addresses into this file:\n\n/etc/nginx/cloudflare-allow.conf\n\nContent for this file can be obtained here: https://www.cloudflare.com/ips\n\nSet these rights:\n```\nchmod 644 /etc/nginx/cloudflare-allow.conf\n```\n\nPlace phantasma.info certificate and certificate key into following locations:\n\n/etc/ssl/certs/cf-phantasma.info.pem\n\n/etc/ssl/private/cf-phantasma.info.key\n\nSet rights for these files\n\n```\nchmod 644 /etc/ssl/certs/cf-phantasma.info.pem\nchmod 600 /etc/ssl/private/cf-phantasma.info.key\n```\n\nAdd following file:\n```\n/etc/nginx/sites-available/explorer-api\n```\n\nwith the following content:\n```\nserver {\n    listen        443 ssl;\n\n    include /etc/nginx/cloudflare-allow.conf;\n    deny all;\n\n    server_name   api-explorer.phantasma.info;\n    ssl_certificate     /etc/ssl/certs/cf-phantasma.info.pem;\n    ssl_certificate_key /etc/ssl/private/cf-phantasma.info.key;\n    ssl_protocols       TLSv1 TLSv1.1 TLSv1.2;\n    ssl_ciphers         HIGH:!aNULL:!MD5;\n    location / {\n        proxy_pass         http://127.0.0.1:9000;\n        proxy_http_version 1.1;\n        proxy_set_header   Upgrade $http_upgrade;\n        proxy_set_header   Connection keep-alive;\n        proxy_set_header   Host $host;\n        proxy_cache_bypass $http_upgrade;\n        proxy_set_header   X-Forwarded-For $proxy_add_x_forwarded_for;\n        proxy_set_header   X-Forwarded-Proto $scheme;\n    }\n}\n```\n\nSet these rights:\n```\nchmod 644 /etc/nginx/sites-available/explorer-api\n```\n\nCreate link with the following command:\n```\nln -s /etc/nginx/sites-available/explorer-api /etc/nginx/sites-enabled/explorer-api\n```\n\nTest Nginx configuration using command:\n```\nsudo nginx -t\n```\n\nRestart Nginx to apply changes:\n```\nsudo /etc/init.d/nginx restart\n```\n\n### Test backend API\n\nTo test if deployment was successful, following url can be used:\n\nhttps://api-explorer.phantasma.info/\n\n## Sources structure\nFile / Folder | Description\n------------- | -------------\nBackend.Api.Client | Library used by plugins for REST calls\nBackend.Database | Everything that related to database and its objects, including EF model and migrations\nBackend.Plugins | Folder with plugins for fetching blockchains and NFTs data\nBackend.Plugins/Blockchain.Phantasma | Phantasma blockchain plugin, retrieves all necessary data from blockchain and stores it in the database\nBackend.Plugins/Nft.TTRS | 22 Racing series NFT plugin, retrieves all necessary data from 22 series site and stores it in the database\nBackend.Service.Api | 1st of 2 backend services, provides endpoints for frontend\nBackend.Service.Worker | 2nd of 2 backend services, runs available blockchain and NFT plugins to fetch necessary data and save it in the database\nBackend.PluginEngine | Plugin engine library used by both backend services, provides plugin mechanisms and interfaces\nBackend.PostgreSQLConnector | Library for raw SQL querying of PastgresSQL database, can be used with current EF database implementation\nclean.sh | Development script, cleans sources from binaries and temporal VS files. Close VS before running\ndatabase-migrations-recreate.sh | Development script, recreates \"Migrations\" folder in Database.Main, preserving previous dates in migrations file names\ndatabase-recreate.sh | Deployment script, drops \"explorer-backend\" database and creates it using migrations in Database.Main/Migrations. Database user \"postgres\" and password \"masterkey\" are used in script.\nBackend.ExplorerBackend.sln | MSVS solution for explorer backend\nexplorer-backend-config.json | Default backend configuration file, should be placed on same level as backend's bin folder\nREADME.md | This readme file\nstart-api-service.sh | Starts API service (can be replaced with the service files)\nstart-worker.sh | Starts Worker service (can be replaced with the service files)\napi-service.service | systemd service file for the API service\ndata-fetcher.service | systemd service file for the Worker service \npublish.sh | script to setup the folder sturcture we later deploy with\ninstall_files.sh | stops the services, copies current version, copies publish and overwrite folder to /opt/explorer-backend, starts and enable services\n\n*All scripts are designed to be used in OS Linux, or in OS Windows with MSYS distributive available in PATH environment variable*\n","funding_links":[],"categories":[],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fphantasma-io%2Fexplorerbackend","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fphantasma-io%2Fexplorerbackend","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fphantasma-io%2Fexplorerbackend/lists"}