https://github.com/ruivalim/bmx-stack
This modern boilerplate combines Bun, Mongoose, Express, and TypeScript to give you the thrill of speed and control while building web applications. Whether you're racing through REST APIs or performing tricks with static routes, BMX-Stack is here to help you land clean every time.
https://github.com/ruivalim/bmx-stack
bun docker docker-compose express mongoose typescript
Last synced: 2 months ago
JSON representation
This modern boilerplate combines Bun, Mongoose, Express, and TypeScript to give you the thrill of speed and control while building web applications. Whether you're racing through REST APIs or performing tricks with static routes, BMX-Stack is here to help you land clean every time.
- Host: GitHub
- URL: https://github.com/ruivalim/bmx-stack
- Owner: Ruivalim
- License: mit
- Created: 2024-11-28T18:35:43.000Z (over 1 year ago)
- Default Branch: main
- Last Pushed: 2025-01-04T03:52:34.000Z (over 1 year ago)
- Last Synced: 2025-02-23T02:44:47.821Z (over 1 year ago)
- Topics: bun, docker, docker-compose, express, mongoose, typescript
- Language: TypeScript
- Homepage:
- Size: 123 KB
- Stars: 1
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# **BMX-Stack**
BMX-Stack: It's not just about riding bikesβit's about riding the **web development rails**! π΄π»
This modern boilerplate combines **Bun**, **Mongoose**, **Express**, and **TypeScript** to give you the thrill of speed and control while building web applications. Whether you're racing through REST APIs or performing tricks with static routes, BMX-Stack is here to help you land clean every time.
---
## **Features**
- **π οΈ REST Route Generator**: Automate the creation of models, controllers, and routes for REST APIs with built-in validation.
- **π Static Route Generator**: Quickly scaffold HTML pages and serve them with Express.
- **πΌοΈ Handlebars Support**: Dynamically render HTML templates using Handlebars for robust server-side rendering.
- **π Fast Runtime**: Powered by Bun for unparalleled speed and performance.
- **πΎ MongoDB Integration**: Effortless database connectivity and schema management with Mongoose.
- **π TypeScript Support**: Type-safe development for smoother rides.
- **π¦ Docker Support**: Easily containerize your application using the provided Dockerfile and Docker Compose setup.
- **π Production Optimization**: Build highly optimized production-ready Docker images.
---
## **Getting Started**
### Prerequisites
- **[Bun](https://bun.sh/)** installed
- **MongoDB** instance (local or cloud)
- **Docker** (super recommended for ease of setup and production builds)
---
### Installation
1. **Create Project with Bun Create**
```bash
bun create https://github.com/Ruivalim/bmx-stack ./myproj
cd ./myproj
```
2. **Set Up Environment Variables**
Create a `.env` file in the root directory and configure the following:
```env
PORT=3000
MONGO_URI=mongodb://mongo:27017/bmx-stack
NODE_ENV=development
```
3. **Run the Project**
Start the development server:
```bash
docker compose up --watch
```
The server will start on `http://localhost:3000`.
---
### Project Structure
```
bmx-stack/
βββ Dockerfile # Production-ready Docker configuration
βββ bun.lockb # Bun lock file
βββ dev.Dockerfile # Docker configuration for development
βββ docker-compose.yaml # Docker Compose setup
βββ public/ # Static HTML files and assets
βββ scripts/ # Utility scripts
β βββ build.sh # Production build script
β βββ generate.ts # Route and model generation script
β βββ generateStaticRoutes.ts # Static route generator script
βββ src/ # Application source code
β βββ app.ts # Express app setup
β βββ config/ # Database configuration
β β βββ database.ts
β βββ controllers/ # Route controllers
β β βββ healthController.ts
β βββ middleware/ # Custom middleware
β β βββ validationMiddleware.ts
β βββ models/ # Mongoose models
β βββ routes/ # API and static routes
β β βββ healthRoute.ts
β βββ routesLoader.ts # Dynamic route loader
β βββ server.ts # Server entry point
β βββ validations/ # Reusable validation functions
β β βββ boolean.ts
β β βββ date.ts
β β βββ email.ts
β β βββ number.ts
β β βββ objectId.ts
β β βββ string.ts
β βββ views/ # Handlebars templates
β βββ home.handlebars # Main page template
β βββ layouts/ # Handlebars layouts
β β βββ main.handlebars
β βββ partials/ # Handlebars partials
β βββ footer.handlebars
β βββ header.handlebars
βββ tsconfig.json # TypeScript configuration
```
---
## **Usage**
### Generate a Static Route
Generate a new static route and HTML file:
```bash
bun run generate
```
1. Select **Static Route**.
2. Enter the name of the route.
3. The script will create:
- A static HTML file in `public/`.
- A route file in `src/routes/`.
---
### Generate a RESTful Route
Generate a RESTful route with a model, controller, and validation:
```bash
bun run generate
```
1. Select **REST Route**.
2. Enter the name of the model (in PascalCase).
3. The script will create:
- A Mongoose model in `src/models/`.
- A controller with CRUD operations in `src/controllers/`.
- A RESTful route with basic validation in `src/routes/`.
---
### Handlebars Support
Handlebars templates are located in the `src/views/` directory, with support for layouts and partials.
#### Example Usage:
Render a Handlebars template in your route:
```typescript
res.render('home', { title: 'Welcome!', message: 'Hello, Handlebars!' });
```
Use the `main` layout (`layouts/main.handlebars`) and include reusable partials (e.g., `partials/header.handlebars`).
---
## **Production Optimization**
The `build.sh` script prepares your project for production by:
- Compiling the application using **Bun**.
- Minifying JavaScript and CSS assets.
- Copying the necessary files to a `dist` directory.
### Steps to Build a Production Image
1. Build the Docker image:
```bash
docker build . -t image:tag
```
2. Run the container:
```bash
docker run -p 3000:3000 image:tag
```
The resulting image is optimized for production.
---
## **Contributing**
We welcome contributions! If you'd like to improve BMX-Stack, please feel free to fork the repository, create a feature branch, and submit a pull request.
---
## **License**
This project is licensed under the [MIT License](LICENSE).
---
## **Author**
Created by **[Rui Valim](https://github.com/Ruivalim)**.
Feel free to reach out with suggestions, feedback, or just to say hi! π΄π»