### Project Setup and Dependencies Installation Source: https://github.com/devforth/adminforth/blob/main/adminforth/documentation/docs/tutorial/01-helloWorld.md Creates a new project directory, initializes a Node.js project, and installs necessary AdminForth and development dependencies. ```bash mkdir af-hello cd af-hello pnpm init pnpm add adminforth express@^4 @dotenvx/dotenvx @types/express typescript tsx @types/node prisma @prisma/client -D npx --yes tsc --init --module NodeNext --target ESNext ``` -------------------------------- ### Initialize Nuxt Project and Install Dependencies Source: https://github.com/devforth/adminforth/blob/main/adminforth/documentation/blog/2024-10-01-ai-blog/index.md Use this command to create a new Nuxt project, navigate into its directory, install Sass, and start the development server. ```bash npx nuxi@latest init seo cd seo npm install -D sass-embedded npm run dev ``` -------------------------------- ### Setup Terraform and Kubectl in GitHub Actions Source: https://github.com/devforth/adminforth/blob/main/adminforth/documentation/blog/2026-06-01-branch-sandboxing-k3s/index.md Installs Terraform using the `hashicorp/setup-terraform` action, preparing the environment for infrastructure management. ```yaml - name: Setup Terraform & Kubectl uses: hashicorp/setup-terraform@v3 ``` -------------------------------- ### Index.ts for AdminForth Application Setup Source: https://github.com/devforth/adminforth/blob/main/adminforth/documentation/docs/tutorial/01-helloWorld.md This file initializes the AdminForth application, configures resources, authentication, customization, and starts the server. ```typescript import express from 'express'; import AdminForth from 'adminforth'; import usersResource from "./resources/adminuser.js"; import { fileURLToPath } from 'url'; import path from 'path'; import { Filters } from 'adminforth'; import { initApi } from './api.js'; import { logger } from 'adminforth'; const ADMIN_BASE_URL = ''; export const admin = new AdminForth({ baseUrl: ADMIN_BASE_URL, auth: { usersResourceId: 'adminuser', usernameField: 'email', passwordHashField: 'password_hash', rememberMeDuration: '30d', loginBackgroundImage: 'https://images.unsplash.com/photo-1534239697798-120952b76f2b?q=80&w=3389&auto=format&fit=crop&ixlib=rb-4.0.3&ixid=M3wxMjA3fDB8MHxwaG90by1wYWdlfHx8fGVufDB8fHx8fA%3D%3D', loginBackgroundPosition: '1/2', loginPromptHTML: async () => { const adminforthUserExists = await admin.resource("adminuser").count(Filters.EQ('email', 'adminforth')) > 0; if (adminforthUserExists) { return "Please use adminforth as username and adminforth as password" } }, }, customization: { brandName: "myadmin", title: "myadmin", datesFormat: 'DD MMM', timeFormat: 'HH:mm a', showBrandNameInSidebar: true, showBrandLogoInSidebar: true, emptyFieldPlaceholder: '-', styles: { colors: { light: { primary: '#1a56db', sidebar: { main: '#f9fafb', text: '#213045' }, }, dark: { primary: '#82ACFF', sidebar: { main: '#1f2937', text: '#9ca3af' }, } } }, }, dataSources: [ { id: 'maindb', url: `${process.env.DATABASE_URL}` }, ], resources: [ usersResource ], menu: [ { type: 'heading', label: 'SYSTEM' }, { label: 'Users', icon: 'flowbite:user-solid', resourceId: 'adminuser' } ], }); if (fileURLToPath(import.meta.url) === path.resolve(process.argv[1])) { const app = express(); app.use(express.json()); initApi(app, admin); const port = 3500; admin.bundleNow({ hotReload: process.env.NODE_ENV === 'development' }).then(() => { logger.info('Bundling AdminForth SPA done.'); }); admin.express.serve(app); admin.discoverDatabases().then(async () => { if (await admin.resource('adminuser').count() === 0) { await admin.resource('adminuser').create({ email: 'adminforth', password_hash: await AdminForth.Utils.generatePasswordHash('adminforth'), role: 'superadmin', }); } }); admin.express.listen(port, () => { logger.info(`\x1b[38;5;249m ⚡ AdminForth is available at\x1b[1m\x1b[38;5;46m http://localhost:${port}${ADMIN_BASE_URL}\x1b[0m\n`); }); } ``` -------------------------------- ### Install Upload Plugin Source: https://github.com/devforth/adminforth/blob/main/adminforth/documentation/docs/tutorial/09-Plugins/05-0-upload.md Install the core upload plugin package. ```bash pnpm add @adminforth/upload --save ``` -------------------------------- ### Install Universal Search Plugin Source: https://github.com/devforth/adminforth/blob/main/adminforth/documentation/docs/tutorial/09-Plugins/18-universal-filters.md Install the package using pnpm. ```bash pnpm add @adminforth/universal-search --save ``` -------------------------------- ### Install and Configure Redis Adapter Source: https://github.com/devforth/adminforth/blob/main/adminforth/documentation/docs/tutorial/06-Adapters/07-key-value-adapters.md Install the Redis adapter and initialize it with a connection URL. ```bash pnpm add @adminforth/key-value-adapter-redis ``` ```ts import RedisKeyValueAdapter from '@adminforth/key-value-adapter-redis'; const adapter = new RedisKeyValueAdapter({ redisUrl: 'redis://localhost:6379/0', // where "/0" - is database number from 0 to 15; Redis can have up to 16 databases" }); adapter.set('test-key', 'test-value', 120); ``` -------------------------------- ### Install Text Complete dependencies Source: https://github.com/devforth/adminforth/blob/main/adminforth/documentation/docs/tutorial/09-Plugins/14-text-complete.md Install the plugin and the OpenAI adapter package via pnpm. ```bash pnpm add @adminforth/text-complete --save pnpm add @adminforth/completion-adapter-openai-responses --save ``` -------------------------------- ### Install Completion Adapter Source: https://github.com/devforth/adminforth/blob/main/adminforth/documentation/docs/tutorial/09-Plugins/26-RichEditor.md Install the OpenAI completion adapter package via pnpm. ```bash pnpm add @adminforth/completion-adapter-openai-responses --save ``` -------------------------------- ### Basic Select component setup Source: https://github.com/devforth/adminforth/blob/main/adminforth/documentation/docs/tutorial/03-Customization/15-afcl.md Initial import and reactive state setup for the Select component. ```js import { Select } from '@/afcl' const selected = ref(null) ``` -------------------------------- ### Install RAM Adapter Source: https://github.com/devforth/adminforth/blob/main/adminforth/documentation/docs/tutorial/06-Adapters/07-key-value-adapters.md Install the in-memory key-value adapter package. ```bash pnpm add @adminforth/key-value-adapter-ram ``` -------------------------------- ### Install and Configure LevelDB Adapter Source: https://github.com/devforth/adminforth/blob/main/adminforth/documentation/docs/tutorial/06-Adapters/07-key-value-adapters.md Install the LevelDB adapter and initialize it with a local database path. ```bash pnpm add @adminforth/key-value-adapter-leveldb ``` ```ts import LevelDBKeyValueAdapter from '@adminforth/key-value-adapter-leveldb'; const adapter = new LevelDBKeyValueAdapter({ dbPath: './testdb', }); adapter.set('test-key', 'test-value', 120); ``` -------------------------------- ### Install Dependencies Source: https://github.com/devforth/adminforth/blob/main/dev-demo/README.md Run this command to install all project dependencies using pnpm. ```bash pnpm ci ``` -------------------------------- ### Install Image Upload Dependencies Source: https://github.com/devforth/adminforth/blob/main/adminforth/documentation/docs/tutorial/09-Plugins/26-RichEditor.md Install the required upload and storage adapter packages. ```bash pnpm makemigration --name add_description_image ; pnpm migrate:local ``` ```bash pnpm add @adminforth/upload --save pnpm add @adminforth/storage-adapter-local --save ``` -------------------------------- ### Install Google Gemini Adapter Source: https://github.com/devforth/adminforth/blob/main/adminforth/documentation/docs/tutorial/06-Adapters/05-ai-completion-adapters.md Install the required package via pnpm. ```bash pnpm add @adminforth/completion-adapter-google-gemini ``` -------------------------------- ### Install OAuth plugin and adapters Source: https://github.com/devforth/adminforth/blob/main/adminforth/documentation/docs/tutorial/09-Plugins/11-oauth.md Install the core OAuth package and the specific adapter for the desired provider. ```bash pnpm add @adminforth/oauth --save pnpm add @adminforth/oauth-adapter-google --save ``` ```bash pnpm add @adminforth/chat-surface-adapter-telegram --save pnpm add @adminforth/oauth-adapter-telegram --save ``` -------------------------------- ### Install Quick Filters plugin Source: https://github.com/devforth/adminforth/blob/main/adminforth/documentation/docs/tutorial/09-Plugins/24-quick-filters.md Install the required package using pnpm. ```bash pnpm add @adminforth/quick-filters ``` -------------------------------- ### Install Two-Factor Authentication Plugin Source: https://github.com/devforth/adminforth/blob/main/adminforth/documentation/docs/tutorial/09-Plugins/02-TwoFactorsAuth.md Install the required package using pnpm. ```bash pnpm add @adminforth/two-factors-auth --save ``` -------------------------------- ### Install JSON Form plugin Source: https://github.com/devforth/adminforth/blob/main/adminforth/documentation/docs/tutorial/09-Plugins/29-json-form.md Install the plugin via pnpm. ```bash pnpm add @adminforth/json-form --save ``` -------------------------------- ### Install Import-Export Plugin Source: https://github.com/devforth/adminforth/blob/main/adminforth/documentation/docs/tutorial/09-Plugins/08-import-export.md Install the plugin package via pnpm. ```bash pnpm add @adminforth/import-export --save ``` -------------------------------- ### Start AdminForth Project Source: https://github.com/devforth/adminforth/blob/main/adminforth/documentation/blog/2024-10-01-ai-blog/index.md Use this command to start your AdminForth project if it was not run previously. ```bash npm start ``` -------------------------------- ### Install Helmfile and Helm-Diff Plugin Source: https://github.com/devforth/adminforth/blob/main/adminforth/documentation/blog/2025-11-04-k3s-ec2-deployment/index.md Installs Helmfile, a declarative spec for deploying Helm charts, and the Helm-Diff plugin for comparing Helm releases. Ensure you have `wget` and `tar` installed. ```bash wget -O helmfile_linux_amd64.tar.gz https://github.com/helmfile/helmfile/releases/download/v0.162.0/helmfile_0.162.0_linux_amd64.tar.gz tar -zxvf helmfile_linux_amd64.tar.gz sudo mv helmfile /usr/local/bin/helmfile rm helmfile_linux_amd64.tar.gz helm plugin install https://github.com/databus23/helm-diff ``` -------------------------------- ### Install Upload Dependencies Source: https://github.com/devforth/adminforth/blob/main/adminforth/documentation/docs/tutorial/09-Plugins/06-markdown.md Commands to install necessary packages for handling file uploads. ```bash pnpm add @adminforth/upload --save pnpm add @adminforth/storage-adapter-local --save ``` -------------------------------- ### Install GitHub OAuth adapter Source: https://github.com/devforth/adminforth/blob/main/adminforth/documentation/docs/tutorial/09-Plugins/11-oauth.md Command to install the GitHub OAuth adapter package. ```bash pnpm add @adminforth/oauth-adapter-github --save ``` -------------------------------- ### Install OpenAI Audio Adapter Source: https://github.com/devforth/adminforth/blob/main/adminforth/documentation/docs/tutorial/09-Plugins/01-agent.md Install the required package to enable voice capabilities for the agent. ```bash pnpm add @adminforth/audio-adapter-openai ``` -------------------------------- ### Database Migration and Application Start Source: https://github.com/devforth/adminforth/blob/main/adminforth/documentation/docs/tutorial/01-helloWorld.md Commands to create the database migration and start the Admin Forth application. ```bash pnpm run makemigration --name init ; pnpm run migrate:local ``` ```bash pnpm start ``` -------------------------------- ### Install Google OAuth Adapter Source: https://github.com/devforth/adminforth/blob/main/adminforth/documentation/docs/tutorial/06-Adapters/02-oauth2-adapters.md Install the Google OAuth adapter package via pnpm. ```bash pnpm add @adminforth/oauth-adapter-google ``` -------------------------------- ### Install LevelDB Key/Value Adapter Source: https://github.com/devforth/adminforth/blob/main/adminforth/documentation/docs/tutorial/06-Adapters/04-storage-adapters.md Install the required LevelDB adapter dependency for managing storage cleanup. ```bash pnpm add @adminforth/key-value-adapter-leveldb ``` -------------------------------- ### Install GitHub OAuth Adapter Source: https://github.com/devforth/adminforth/blob/main/adminforth/documentation/docs/tutorial/06-Adapters/02-oauth2-adapters.md Install the GitHub OAuth adapter package via pnpm. ```bash pnpm add @adminforth/oauth-adapter-github ``` -------------------------------- ### Install Local Storage Adapter Source: https://github.com/devforth/adminforth/blob/main/adminforth/documentation/docs/tutorial/09-Plugins/05-0-upload.md Command to install the local storage adapter package via pnpm. ```bash pnpm add @adminforth/storage-adapter-local --save ``` -------------------------------- ### Install Bulk AI Flow plugin Source: https://github.com/devforth/adminforth/blob/main/adminforth/documentation/docs/tutorial/09-Plugins/17-bulk-ai-flow.md Install the core plugin package via pnpm. ```bash pnpm add @adminforth/bulk-ai-flow --save ``` -------------------------------- ### Install Telegram Adapters Source: https://github.com/devforth/adminforth/blob/main/adminforth/documentation/docs/tutorial/06-Adapters/09-chat-surface-adapters.md Install the necessary packages for Telegram chat and OAuth integration. ```bash pnpm add @adminforth/chat-surface-adapter-telegram pnpm add @adminforth/oauth-adapter-telegram ``` -------------------------------- ### Install Keycloak OAuth Adapter Source: https://github.com/devforth/adminforth/blob/main/adminforth/documentation/docs/tutorial/06-Adapters/02-oauth2-adapters.md Install the Keycloak OAuth adapter package via pnpm. ```bash pnpm add @adminforth/oauth-adapter-keycloak ``` -------------------------------- ### Install Twitch OAuth Adapter Source: https://github.com/devforth/adminforth/blob/main/adminforth/documentation/docs/tutorial/06-Adapters/02-oauth2-adapters.md Install the Twitch OAuth adapter package via pnpm. ```bash pnpm add @adminforth/oauth-adapter-twitch ``` -------------------------------- ### Install Microsoft OAuth Adapter Source: https://github.com/devforth/adminforth/blob/main/adminforth/documentation/docs/tutorial/06-Adapters/02-oauth2-adapters.md Install the Microsoft OAuth adapter package via pnpm. ```bash pnpm add @adminforth/oauth-adapter-microsoft ``` -------------------------------- ### Run AdminForth Dev Demo Source: https://github.com/devforth/adminforth/blob/main/README.md Commands to initialize and start the development demonstration environment. ```sh cd dev-demo pnpm setup-dev-demo pnpm migrate:all pnpm start ``` -------------------------------- ### Install Login Captcha and Cloudflare Adapter Source: https://github.com/devforth/adminforth/blob/main/adminforth/documentation/docs/tutorial/09-Plugins/19-login-captcha.md Commands to install the core plugin and the required Cloudflare captcha adapter. ```bash pnpm add @adminforth/login-captcha ``` ```bash pnpm add @adminforth/login-captcha-adapter-cloudflare ``` -------------------------------- ### Install Open Signup Plugin Source: https://github.com/devforth/adminforth/blob/main/adminforth/documentation/docs/tutorial/09-Plugins/09-open-signup.md Command to add the Open Signup package to the project. ```bash pnpm add @adminforth/open-signup --save ``` -------------------------------- ### Navigate to project directory Source: https://github.com/devforth/adminforth/blob/main/adminforth/documentation/docs/tutorial/001-gettingStarted.md Change into the newly created project directory. ```bash cd myadmin # or any other name you provided ``` -------------------------------- ### Keycloak Docker Compose Configuration Source: https://github.com/devforth/adminforth/blob/main/adminforth/documentation/blog/2025-03-25-keycloack/index.md Defines the services for PostgreSQL and Keycloak in a Docker Compose setup. Ensure Docker and Docker Compose are installed. ```yaml services: pg: image: postgres:latest environment: POSTGRES_USER: demo POSTGRES_PASSWORD: demo POSTGRES_DB: demo ports: - "5432:5432" volumes: - pg-data:/var/lib/postgresql/data keycloak: image: quay.io/keycloak/keycloak:latest command: start-dev environment: - KEYCLOAK_ADMIN=admin - KEYCLOAK_ADMIN_PASSWORD=admin - DB_VENDOR=postgres - DB_ADDR=pg - DB_DATABASE=demo - DB_USER=demo - DB_PASSWORD=demo ports: - "8080:8080" depends_on: - pg volumes: - keycloak-data:/opt/keycloak/data volumes: keycloak-data: ``` -------------------------------- ### Install Docker and Start Daemon on EC2 Source: https://github.com/devforth/adminforth/blob/main/adminforth/documentation/blog/2025-02-19-compose-aws-ec2-ecr-terraform-github-actions/index.md Installs Docker and related plugins on an EC2 instance and enables the Docker daemon. It also adds the 'ubuntu' user to the 'docker' group for sudo-less Docker commands. A new SSH session is required for these group changes to take effect. ```bash apt-get update apt-get install -y --no-install-recommends \ docker-ce \ docker-ce-cli \ containerd.io \ docker-buildx-plugin \ docker-compose-plugin # Ensure Docker daemon is up systemctl enable --now docker # Allow ubuntu user to run docker without sudo (new SSH session required) usermod -aG docker ubuntu || true docker --version docker compose version echo "done" > /home/ubuntu/user_data_done ``` -------------------------------- ### Terraform User Data Script for K3s Agent Setup Source: https://github.com/devforth/adminforth/blob/main/adminforth/documentation/blog/2026-06-01-branch-sandboxing-k3s/index.md This bash script is designed to be used as user data in Terraform for AWS EC2 instances. It installs AWS CLI, sets up a cron job to refresh ECR authentication tokens for K3s, and installs the K3s agent, configuring it with instance-specific metadata. ```bash #!/bin/bash set -e apt-get update apt-get install -y awscli echo '#!/bin/bash' > /usr/local/bin/update-ecr-token.sh echo 'TOKEN=$(aws ecr get-login-password --region ${aws_region})' >> /usr/local/bin/update-ecr-token.sh echo 'mkdir -p /etc/rancher/k3s' >> /usr/local/bin/update-ecr-token.sh echo 'cat < /etc/rancher/k3s/registries.yaml' >> /usr/local/bin/update-ecr-token.sh echo 'configs:' >> /usr/local/bin/update-ecr-token.sh echo ' "${account_id}.dkr.ecr.${aws_region}.amazonaws.com":' >> /usr/local/bin/update-ecr-token.sh echo ' auth:' >> /usr/local/bin/update-ecr-token.sh echo ' username: AWS' >> /usr/local/bin/update-ecr-token.sh echo ' password: "$TOKEN"' >> /usr/local/bin/update-ecr-token.sh echo 'YAML' >> /usr/local/bin/update-ecr-token.sh echo 'systemctl restart k3s-agent || true' >> /usr/local/bin/update-ecr-token.sh chmod +x /usr/local/bin/update-ecr-token.sh /usr/local/bin/update-ecr-token.sh echo "0 */10 * * * root /usr/local/bin/update-ecr-token.sh > /var/log/ecr-cron.log 2>&1" > /etc/cron.d/update-ecr-token EC2_TOKEN=$(curl -s -X PUT "http://169.254.169.254/latest/api/token" -H "X-aws-ec2-metadata-token-ttl-seconds: 21600") INSTANCE_ID=$(curl -H "X-aws-ec2-metadata-token: $EC2_TOKEN" -s http://169.254.169.254/latest/meta-data/instance-id) AZ=$(curl -H "X-aws-ec2-metadata-token: $EC2_TOKEN" -s http://169.254.169.254/latest/meta-data/placement/availability-zone) curl -sfL https://get.k3s.io | INSTALL_K3S_VERSION="${k3s_version}" K3S_URL="https://${public_ip}:6443" K3S_TOKEN="${k3s_token}" sh -s - agent --kubelet-arg="provider-id=aws:///$AZ/$INSTANCE_ID" ``` -------------------------------- ### Terraform Null Resource for Registry Setup Source: https://github.com/devforth/adminforth/blob/main/adminforth/documentation/blog/2025-02-19-compose-ec2-deployment-github-actions-registry/index.md Uses local-exec and remote-exec provisioners to set up a local Docker registry on the EC2 instance. This includes generating authentication secrets, certificates, and starting the registry container. ```bash set -eu echo "Generating secret for local registry" sha256sum ./.keys/id_rsa | cut -d ' ' -f1 | tr -d '\n' > ./.keys/registry.pure echo "Creating htpasswd file for local registry" docker run --rm --entrypoint htpasswd httpd:2 -Bbn ci-user $(cat ./.keys/registry.pure) > ./.keys/registry.htpasswd echo "Generating server certificate for registry" openssl genrsa -out ./.keys/registry.key 4096 echo "subjectAltName=DNS:appserver.local,DNS:localhost,IP:127.0.0.1" > san.ext openssl req -new -key ./.keys/registry.key -subj "/CN=appserver.local" -addext "$(cat san.ext)" -out ./.keys/registry.csr openssl x509 -req -days 365 -CA ./.keys/ca.pem -CAkey ./.keys/ca.key -set_serial 01 -in ./.keys/registry.csr -extfile san.ext -out ./.keys/registry.crt echo "Copying registry secret files to the instance" rsync -t -avz -e "ssh -i ./.keys/id_rsa -o StrictHostKeyChecking=no" \ ./.keys/registry.* ubuntu@${aws_eip_association.eip_assoc.public_ip}:/home/ubuntu/registry-auth ``` ```bash # remove old registry if exists docker rm -f registry # run new registry docker run -d --network host \ --name registry \ --restart always \ -v /home/ubuntu/registry-data:/var/lib/registry \ -v /home/ubuntu/registry-auth:/auth\ -e "REGISTRY_AUTH=htpasswd" \ -e "REGISTRY_AUTH_HTPASSWD_REALM=Registry Realm" \ -e "REGISTRY_AUTH_HTPASSWD_PATH=/auth/registry.htpasswd" \ -e "REGISTRY_HTTP_TLS_CERTIFICATE=/auth/registry.crt" \ -e "REGISTRY_HTTP_TLS_KEY=/auth/registry.key" \ registry:2 ``` -------------------------------- ### Define Custom API Endpoint with Zod Schema Source: https://github.com/devforth/adminforth/blob/main/adminforth/documentation/docs/tutorial/03-Customization/06-customPages.md This snippet demonstrates how to define a custom GET API endpoint in `api.ts` for a dashboard. It uses `admin.express.withSchema` for validation and OpenAPI generation, and `admin.express.authorize` for authentication. Ensure Zod is installed and imported. ```typescript import type { IAdminUserExpressRequest } from 'adminforth'; import express from 'express'; import * as z from 'zod'; .... app.get(`${ADMIN_BASE_URL}/api/dashboard/`, admin.express.withSchema( { description: 'Returns aggregated apartment metrics for the custom dashboard page.', response: z.object({ apartsByDays: z.array(z.record(z.string(), z.unknown())), totalAparts: z.number(), }).catchall(z.unknown()), }, admin.express.authorize( async (req:IAdminUserExpressRequest, res: express.Response) => { const days = req.body.days || 7; const apartsByDays = admin.resource('aparts').dataConnector.client.prepare( `SELECT strftime('%Y-%m-%d', created_at) as day, COUNT(*) as count FROM apartments GROUP BY day ORDER BY day DESC LIMIT ?; ` ).all(days); const totalAparts = apartsByDays.reduce((acc: number, { count }: { count:number }) => acc + count, 0); // add listed, unlisted, listedPrice, unlistedPrice const listedVsUnlistedByDays = admin.resource('aparts').dataConnector.client.prepare( `SELECT strftime('%Y-%m-%d', created_at) as day, SUM(listed) as listed, COUNT(*) - SUM(listed) as unlisted, SUM(listed * price) as listedPrice, SUM((1 - listed) * price) as unlistedPrice FROM apartments GROUP BY day ORDER BY day DESC LIMIT ?; ` ).all(days); const apartsCountsByRooms = await admin.resource('aparts').dataConnector.client.prepare( `SELECT number_of_rooms, COUNT(*) as count FROM apartments GROUP BY number_of_rooms ORDER BY number_of_rooms; ` ).all(); const topCountries = await admin.resource('aparts').dataConnector.client.prepare( `SELECT country, COUNT(*) as count FROM apartments GROUP BY country ORDER BY count DESC LIMIT 4; ` ).all(); const totalSquare = admin.resource('aparts').dataConnector.client.prepare( `SELECT SUM(square_meter) as totalSquare FROM apartments; ` ).get(); const listedVsUnlistedPriceByDays = admin.resource('aparts').dataConnector.client.prepare( `SELECT strftime('%Y-%m-%d', created_at) as day, SUM(listed * price) as listedPrice, SUM((1 - listed) * price) as unlistedPrice FROM apartments GROUP BY day ORDER BY day DESC LIMIT ?; ` ).all(days); const totalListedPrice = Math.round(listedVsUnlistedByDays.reduce(( acc: number, { listedPrice }: { listedPrice:number } ) => acc + listedPrice, 0)); const totalUnlistedPrice = Math.round(listedVsUnlistedByDays.reduce(( acc: number, { unlistedPrice }: { unlistedPrice:number } ) => acc + unlistedPrice, 0)); res.json({ apartsByDays, totalAparts, listedVsUnlistedByDays, apartsCountsByRooms, topCountries, totalSquareMeters: totalSquare.totalSquare, totalListedPrice, totalUnlistedPrice, listedVsUnlistedPriceByDays, }); } ) ) ); ``` -------------------------------- ### Start the AdminForth server Source: https://github.com/devforth/adminforth/blob/main/adminforth/documentation/docs/tutorial/001-gettingStarted.md Command to launch the development server. ```bash pnpm start ``` -------------------------------- ### Run Deployment Script Source: https://github.com/devforth/adminforth/blob/main/adminforth/documentation/blog/2025-11-04-k3s-ec2-deployment/index.md Navigate to the deploy directory and execute the main deployment script to start the application deployment process. ```bash cd deploy ./deploy.sh ``` -------------------------------- ### Install Terraform on Ubuntu Source: https://github.com/devforth/adminforth/blob/main/adminforth/documentation/blog/2024-10-01-ai-blog/index.md Installs Terraform on Ubuntu systems using apt. Ensure you have wget and gnupg installed. ```bash wget -O- https://apt.releases.hashicorp.com/gpg | sudo gpg --dearmor -o /usr/share/keyrings/hashicorp-archive-keyring.gpg echo "deb [signed-by=/usr/share/keyrings/hashicorp-archive-keyring.gpg] https://apt.releases.hashicorp.com $(lsb_release -cs) main" | sudo tee /etc/apt/sources.list.d/hashicorp.list sudo apt update && sudo apt install terraform ``` -------------------------------- ### Install Helm Source: https://github.com/devforth/adminforth/blob/main/adminforth/documentation/blog/2025-11-04-k3s-ec2-deployment/index.md Installs Helm, a package manager for Kubernetes. This script downloads and executes the Helm installation script. ```bash curl -fsSL -o get_helm.sh https://raw.githubusercontent.com/helm/helm/main/scripts/get-helm-3 chmod 700 get_helm.sh ./get_helm.sh ``` -------------------------------- ### Install Terraform Source: https://github.com/devforth/adminforth/blob/main/adminforth/documentation/blog/2025-11-04-k3s-ec2-deployment/index.md Installs Terraform on Ubuntu using HashiCorp's official repository. Ensure you have `wget` and `gpg` installed. ```bash wget -O - https://apt.releases.hashicorp.com/gpg | sudo gpg --dearmor -o /usr/share/keyrings/hashicorp-archive-keyring.gpg echo "deb [arch=$(dpkg --print-architecture) signed-by=/usr/share/keyrings/hashicorp-archive-keyring.gpg] https://apt.releases.hashicorp.com $(lsb_release -cs) main" | sudo tee /etc/apt/sources.list.d/hashicorp.list sudo apt update && sudo apt install terraform ``` -------------------------------- ### Install Ansible Source: https://github.com/devforth/adminforth/blob/main/adminforth/documentation/blog/2025-11-04-k3s-ec2-deployment/index.md Installs Ansible on Ubuntu by adding the official Ansible PPA and then installing the package. This ensures you have the latest stable version. ```bash sudo add-apt-repository --yes --update ppa:ansible/ansible sudo apt install ansible -y ``` -------------------------------- ### Start Local Development Server Source: https://github.com/devforth/adminforth/blob/main/adminforth/documentation/README.md Starts a local development server that automatically refreshes on changes. Opens in your browser. ```bash $ yarn start ``` -------------------------------- ### Setup Resource-based Adapter Source: https://github.com/devforth/adminforth/blob/main/adminforth/documentation/docs/tutorial/06-Adapters/07-key-value-adapters.md Configure a database table and AdminForth resource to act as a key-value store. ```bash pnpm add @adminforth/key-value-adapter-resource ``` ```prisma model key_values { key String @id value String collection String? expire_at DateTime? //optional column @@index([key]) @@index([collection]) } ``` ```bash pnpm makemigration --name add-adminforth-key-value-tables ; pnpm migrate:local ``` ```ts import AdminForth, { AdminForthDataTypes } from 'adminforth'; import type { AdminForthResourceInput, AdminUser } from 'adminforth'; async function allowedForSuperAdmins({ adminUser }: { adminUser: AdminUser }): Promise { return adminUser.dbUser.role === 'superadmin'; } export default { dataSource: 'maindb', table: 'key_values', resourceId: 'key_values', label: 'Key values', columns: [ { name: 'key', primaryKey: true, type: AdminForthDataTypes.STRING, }, { name: 'value', type: AdminForthDataTypes.STRING, }, { name: 'collection', type: AdminForthDataTypes.STRING, }, { name: 'expire_at', type: AdminForthDataTypes.DATETIME, } ], options: { allowedActions: { list: allowedForSuperAdmins, show: allowedForSuperAdmins, create: false, edit: false, delete: false, }, }, } as AdminForthResourceInput; ``` ```ts import key_value_resource from './resources/key_value_resource.js'; export const admin = new AdminForth({ ... resources: [ ... key_value_resource, ], ... }); ``` ```ts import ResourceKeyValueAdapter from '@adminforth/key-value-adapter-resource' const adapter = new ResourceKeyValueAdapter({ resourceId: 'key_values', keyField: 'key', valueField: 'value', collectionField: 'collection', expireField: 'expire_at' }) ``` -------------------------------- ### Initialize AdminForth with an existing database Source: https://github.com/devforth/adminforth/blob/main/README.md Use this command to create a new project connected to an existing database URL. The project will require manual setup of the adminuser table. ```bash npx adminforth create-app --app-name myadmin --db "postgresql://user:password@localhost:5432/dbname" cd myadmin ``` -------------------------------- ### Install Many2Many Plugin Source: https://github.com/devforth/adminforth/blob/main/adminforth/documentation/docs/tutorial/09-Plugins/22-many2many.md Install the required package via pnpm. ```bash pnpm add @adminforth/many2many ``` -------------------------------- ### Install and configure Node.js version Source: https://github.com/devforth/adminforth/blob/main/adminforth/documentation/docs/tutorial/001-gettingStarted.md Use these commands to ensure the environment meets the Node v20+ requirement. ```bash nvm install 20 nvm alias default 20 nvm use 20 ``` -------------------------------- ### Install Markdown Plugin Source: https://github.com/devforth/adminforth/blob/main/adminforth/documentation/docs/tutorial/09-Plugins/06-markdown.md Command to install the Markdown plugin package. ```bash pnpm add @adminforth/markdown --save ``` -------------------------------- ### Initialize a new AdminForth plugin Source: https://github.com/devforth/adminforth/blob/main/adminforth/documentation/docs/tutorial/10-Advanced/01-plugin-development.md Use the CLI to create the directory structure and boilerplate files for a new plugin. ```bash mkdir -p af-plugin-chatgpt cd af-plugin-chatgpt npx adminforth create-plugin ``` -------------------------------- ### Initialize Plugin Frontend Dependencies Source: https://github.com/devforth/adminforth/blob/main/adminforth/documentation/docs/tutorial/10-Advanced/01-plugin-development.md Commands to initialize the npm package and install the required suggestion input dependency. ```bash cd af-plugin-chatgpt/custom pnpm init -y ``` ```bash pnpm i vue-suggestion-input -D ``` -------------------------------- ### Install Background Jobs Plugin Source: https://github.com/devforth/adminforth/blob/main/adminforth/documentation/docs/tutorial/09-Plugins/23-background-jobs.md Install the plugin package using pnpm. ```bash pnpm add @adminforth/background-jobs ``` -------------------------------- ### Create database indexes Source: https://github.com/devforth/adminforth/blob/main/adminforth/documentation/docs/tutorial/03-Customization/11-dataApi.md SQL examples for creating indexes to support the performance of the listed queries. ```sql CREATE INDEX idx_users_role ON users(role, createdAt); CREATE INDEX idx_users_name_role ON users(name, role); ``` -------------------------------- ### Install Dashboard Package Source: https://github.com/devforth/adminforth/blob/main/adminforth/documentation/docs/tutorial/09-Plugins/27-0-dashboard.md Install the required npm package for the dashboard plugin. ```bash pnpm add @adminforth/dashboard --save ``` -------------------------------- ### Install Rich Editor Plugin Source: https://github.com/devforth/adminforth/blob/main/adminforth/documentation/docs/tutorial/09-Plugins/26-RichEditor.md Install the required package via pnpm. ```bash pnpm add @adminforth/rich-editor --save ``` -------------------------------- ### Copilot Instructions for Context7 Source: https://github.com/devforth/adminforth/blob/main/adminforth/documentation/blog/2025-10-21-context7-setup/index.md Add this content to `.github/copilot-instructions.md` to instruct GitHub Copilot to always use Context7 MCP for code generation, setup, configuration, and documentation. ```txt Always use context7 when I need code generation, setup or configuration steps, or library/API documentation. This means you should automatically use the Context7 MCP tools to resolve library id and get library docs without me having to explicitly ask. ``` -------------------------------- ### Install Audit Log Plugin Source: https://github.com/devforth/adminforth/blob/main/adminforth/documentation/docs/tutorial/09-Plugins/04-AuditLog.md Install the required package using pnpm. ```bash pnpm add @adminforth/audit-log --save ``` -------------------------------- ### Install Slack Notification Plugin Source: https://github.com/devforth/adminforth/blob/main/adminforth/documentation/blog/2025-01-19-how-adminforth-manages-version/index.md Install the semantic-release-slack-bot plugin as a development dependency. ```sh npm i -D semantic-release-slack-bot ``` -------------------------------- ### Install Telegram OAuth adapter Source: https://github.com/devforth/adminforth/blob/main/adminforth/documentation/docs/tutorial/09-Plugins/11-oauth.md Command to install the Telegram OAuth adapter package. ```bash pnpm add @adminforth/oauth-adapter-telegram --save ``` -------------------------------- ### Create New AdminForth Project Source: https://github.com/devforth/adminforth/blob/main/adminforth/documentation/blog/2024-10-01-ai-blog/index.md Initializes a new AdminForth application with the specified name. Navigate to the project directory after creation. ```bash npx adminforth create-app --app-name ai-blog ``` -------------------------------- ### Scaffold project with existing database Source: https://github.com/devforth/adminforth/blob/main/adminforth/documentation/docs/tutorial/001-gettingStarted.md Use this command to initialize a project when you already have a database schema. The CLI will not generate Prisma files for this path. ```bash npx adminforth create-app --app-name myadmin --db "postgresql://user:password@localhost:5432/dbname" ``` -------------------------------- ### Install Foreign Inline Show Plugin Source: https://github.com/devforth/adminforth/blob/main/adminforth/documentation/docs/tutorial/09-Plugins/15-ForeignInlineShow.md Install the plugin package via pnpm. ```bash pnpm add @adminforth/foreign-inline-show --save ``` -------------------------------- ### Initialize AdminForth with a new database Source: https://github.com/devforth/adminforth/blob/main/README.md Use this path to scaffold a standalone application with a local SQLite database. This includes commands for running migrations and starting the development server. ```bash npx adminforth create-app --app-name myadmin cd myadmin pnpm makemigration --name init && pnpm migrate:local pnpm dev ```