1.7.0 β€’ Published 10 months ago

@bruxx/cli-tool v1.7.0

Weekly downloads
-
License
MIT
Repository
-
Last release
10 months ago

BRUXX CLI πŸ”₯

Overview

BRX TEMPLATE is a production-ready boilerplate for modern React projects. It eliminates the tedious setup process, letting you jump straight into coding with a preconfigured, optimized environment. Built with best practices, it’s designed for scalability, maintainability, and rapid deployment.

Why BRX TEMPLATE?

  • Zero Setup Hassle: Preconfigured tools save hours of initial setup.
  • Modern Stack: Leverages Vite, React, TypeScript, and more for a cutting-edge dev experience.
  • Production-Ready: Includes Docker, CI/CD, linting, and testing out of the box.
  • Focus on Code: Spend time building features, not configuring tools.

Prerequisites

Before you begin, ensure you have:

  • Node.js: Version 18+ (check with node -v; .nvmrc specifies the exact version).
  • npm: Version 8+ (comes with Node.js; verify with npm -v).
  • Docker: Optional, for containerized deployment (install from docker.com).
  • Git: For cloning and version control.

Installation

Step 1: Install the BRX CLI

The BRX CLI simplifies project creation. Install it globally:

npm install -g @bruxx/cli-tool

Step 2: Create Your Project

Run the CLI to scaffold your project:

npx create-brx-app

Follow the prompts to name your project (e.g., my-app).
The CLI sets up the directory, installs dependencies, and initializes Git.

Step 3: Navigate to Your Project

cd my-app

Step 4: Configure Environment

Copy .env.example to .env and adjust variables as needed:

cp .env.example .env

Example .env:

VITE_PORT=8080
VITE_BACKEND_API_BASE_URL=https://api.example.com
  • VITE_BACKEND_API_BASE_URL: Set to your API’s base URL (e.g., https://jsonplaceholder.typicode.com for testing).
  • No need to set NODE_ENV; it’s managed automatically ("test" for tests, "development"/"production" otherwise).

Project Structure

Here’s a quick overview of key directories and files:

my-app/
β”œβ”€β”€ .github/              # GitHub Actions for CI/CD
β”œβ”€β”€ .husky/               # Git hooks (e.g., linting on commit)
β”œβ”€β”€ src/                  # Source code
β”‚   β”œβ”€β”€ __tests__/        # Unit tests
β”‚   β”œβ”€β”€ assets/           # Static assets (images, fonts)
β”‚   β”œβ”€β”€ components/       # Reusable UI components
β”‚   β”œβ”€β”€ lib/              # Utilities and API logic
β”‚   β”‚   β”œβ”€β”€ api/          # API controllers and services
β”‚   β”œβ”€β”€ routes/           # TanStack Router routes
β”‚   β”œβ”€β”€ store/            # Zustand state management
β”‚   β”œβ”€β”€ types/            # TypeScript types
β”‚   β”œβ”€β”€ app.tsx           # Root component
β”‚   β”œβ”€β”€ env.ts            # Environment variable validation
β”‚   β”œβ”€β”€ main.tsx          # Entry point
β”‚   β”œβ”€β”€ router.tsx        # Router setup
β”œβ”€β”€ .env                  # Environment variables
β”œβ”€β”€ Dockerfile            # Docker configuration
β”œβ”€β”€ package.json          # Scripts and dependencies
β”œβ”€β”€ vite.config.ts        # Vite configuration

Running the Project

Development

Start the dev server:

npm run dev
  • Opens at http://localhost:8080 (or your VITE_PORT).
  • Hot Module Replacement (HMR) enabled via Vite.

Build

Compile for production:

npm run build
  • Output goes to ./dist.

Preview

Test the production build locally:

npm run preview

Test

Run unit tests with Vitest:

npm run test
  • Sets NODE_ENV="test" automatically, using an empty baseUrl for API mocks.

Core Features

API Integration

BRX TEMPLATE provides two API controllers for seamless HTTP requests:

  • ControllerWithAuth: For authenticated endpoints (requires a token).
  • ControllerWithoutAuth: For public endpoints (no token needed).

Example: Fetching Posts

Authenticated Request (e.g., user-specific posts):

// src/lib/api/controllers/post-controller.ts
import ControllerWithAuth from "@/lib/api/controllers/main/controller-with-auth";
import type { Post } from "@/types";

export default class PostController extends ControllerWithAuth {
  async getUserPosts(userId: number): Promise<Post[]> {
    return this.get(`/users/${userId}/posts`);
  }
}

export const { getUserPosts } = new PostController();

// Usage in a component
import { createQueryMethod } from "@/lib/api/query-methods";

const { data: posts } = createQueryMethod({
  key: ["user-posts", userId],
  fn: async () => {
    return await getUserPosts({ userId });
  },
}).useHook();

Unauthenticated Request (e.g., public posts):

import ControllerWithoutAuth from "@/lib/api/controllers/main/controller-without-auth";
import type { Posts } from "@/types";

export default class PostController extends ControllerWithoutAuth {
  constructor() {
    super();
  }

  async getAllPosts({ limit }: { limit?: number }) {
    try {
      const query = new URLSearchParams();

      if (limit) {
        query.append("_limit", String(limit));
      }

      return await this.apiService.get<Posts>(`/posts?${query}`);
    } catch (error) {
      this.handleError(error);
    }
  }
}

export const { getAllPosts } = new PostController();

// Usage in a component
const { data, isLoading, error } = createQueryMethod({
  key: ["posts", limit],
  fn: async () => {
    return await getAllPosts({ limit });
  },
}).useHook();

Deployment

Docker

Build and run with Docker:

docker build -t my-app .
docker run -p 8080:8080 my-app

CI/CD

GitHub Actions workflows in .github/workflows/ handle linting, testing, and deployment.
Configure secrets in your GitHub repo (e.g., DOCKERHUB_TOKEN).

Contributing

  • Issues: Report bugs or suggest features on GitHub.
  • Pull Requests: Fork, modify, and submit a PR with clear descriptions.

Next Steps

  • Explore src/lib/api/ for API logic.
  • Add routes in src/routes/.
  • Customize src/store/ for state needs.
  • Write tests in src/__tests__/.

Happy coding with BRX TEMPLATE! πŸš€

1.7.0

10 months ago

1.6.0

10 months ago

1.5.0

10 months ago

1.4.0

10 months ago

1.3.0

10 months ago

1.2.0

10 months ago

1.1.0

10 months ago

1.0.9

10 months ago

1.0.8

11 months ago

1.0.7

11 months ago

1.0.6

11 months ago

1.0.5

11 months ago

1.0.4

11 months ago

1.0.3

11 months ago

1.0.2

11 months ago

1.0.1

11 months ago

1.0.0

11 months ago