2025-03-20 17:33:57 +07:00
|
|
|
# Axum SurrealDB Boilerplate
|
2025-02-08 01:16:14 +07:00
|
|
|
|
|
|
|
|
## Features
|
|
|
|
|
|
2025-03-20 17:33:57 +07:00
|
|
|
- **Authentication Ready**: Preconfigured authentication and middleware for secure API access.
|
|
|
|
|
- **Database Integration**: SurrealDB seamlessly integrated as an Axum Extension.
|
|
|
|
|
- **CORS Handling**: Fine-tuned CORS management with Tower HTTP `CorsLayer`.
|
|
|
|
|
- **API Documentation**: Fully documented with OpenAPI and Swagger UI.
|
|
|
|
|
- **Optimized for Performance**: Asynchronous, lightweight, and scalable architecture.
|
2025-02-08 01:16:14 +07:00
|
|
|
|
|
|
|
|
## Prerequisites
|
|
|
|
|
|
2025-03-20 17:33:57 +07:00
|
|
|
- **Rust**: Install Rust from [rust-lang.org](https://www.rust-lang.org/).
|
|
|
|
|
- **Database**: Set up a SurrealDB instance and configure connection details.
|
|
|
|
|
- **Docker**: Required for containerized deployment, install from [docker.com](https://www.docker.com/).
|
|
|
|
|
- **Nix (Optional)**: For reproducible builds, install from [nixos.org](https://nixos.org/).
|
2025-02-08 01:16:14 +07:00
|
|
|
|
|
|
|
|
## Getting Started
|
|
|
|
|
|
|
|
|
|
1. **Clone the Repository**:
|
|
|
|
|
|
2025-03-20 17:33:57 +07:00
|
|
|
- `git clone https://github.com/maulanasdqn/axum-surrealdb-boilerplate`
|
2025-02-08 01:16:14 +07:00
|
|
|
|
|
|
|
|
2. **Set Up Environment Variables**:
|
|
|
|
|
|
2025-03-20 17:33:57 +07:00
|
|
|
- Copy `.env.example` and rename it to `.env`
|
2025-02-08 01:16:14 +07:00
|
|
|
|
2025-03-20 17:33:57 +07:00
|
|
|
- **Windows**: Run the script: `./apply-env.ps1`
|
|
|
|
|
- **Unix-based systems (Linux, macOS, BSD)**: Run the script: `./apply-env.sh`
|
2025-02-08 01:16:14 +07:00
|
|
|
|
|
|
|
|
3. **Install Dependencies**:
|
|
|
|
|
|
2025-03-20 17:33:57 +07:00
|
|
|
- `cargo install .`
|
2025-02-08 01:16:14 +07:00
|
|
|
|
2025-03-20 17:33:57 +07:00
|
|
|
4. **Setup Database**:
|
2025-02-08 01:16:14 +07:00
|
|
|
|
2025-03-20 17:33:57 +07:00
|
|
|
- Install the surrealDB
|
|
|
|
|
- **Windows**: `iwr https://windows.surrealdb.com -useb | iex`
|
|
|
|
|
- **Unix-based systems (Linux, macOS, BSD)**: `curl -sSf https://install.surrealdb.com | sh`
|
|
|
|
|
- Start the database `surreal start --user root --pass root`
|
2025-02-08 01:16:14 +07:00
|
|
|
|
2025-03-20 17:33:57 +07:00
|
|
|
5. **Start the Server**:
|
2025-02-08 01:16:14 +07:00
|
|
|
|
2025-03-20 17:33:57 +07:00
|
|
|
- Install Cargo Watch `cargo install cargo-watch`
|
|
|
|
|
- Run it with cargo watch `cargo watch -x run`
|
2025-02-08 01:16:14 +07:00
|
|
|
|
2025-03-20 17:33:57 +07:00
|
|
|
The API will be available at `http://localhost:3000/docs`.
|
2025-02-08 01:16:14 +07:00
|
|
|
|
|
|
|
|
## Docker
|
|
|
|
|
|
|
|
|
|
1. **Build the Docker Image**:
|
|
|
|
|
|
|
|
|
|
2. **Run the Docker Container**:
|
|
|
|
|
|
2025-03-20 17:33:57 +07:00
|
|
|
The API will be accessible at `http://localhost:3000/docs`.
|
2025-02-08 01:16:14 +07:00
|
|
|
|
2025-03-20 17:33:57 +07:00
|
|
|
## Using Nix as Builder (Optional)
|
2025-02-08 01:16:14 +07:00
|
|
|
|
|
|
|
|
1. **Install Nix**:
|
|
|
|
|
|
2025-03-20 17:33:57 +07:00
|
|
|
2. **Enter Nix Shell or Use Nix Flakes**:
|
2025-02-08 01:16:14 +07:00
|
|
|
|
|
|
|
|
3. **Build the Project**:
|
|
|
|
|
|
|
|
|
|
4. **Run the Server**:
|
|
|
|
|
|
|
|
|
|
## Contributing
|
|
|
|
|
|
2025-03-20 17:33:57 +07:00
|
|
|
Contributions are welcome! Fork the repository and create a pull request with your improvements.
|
2025-02-08 01:16:14 +07:00
|
|
|
|
|
|
|
|
## License
|
|
|
|
|
|
|
|
|
|
This project is licensed under the MIT License. See the [LICENSE](LICENSE) file for details.
|
|
|
|
|
|
|
|
|
|
## Acknowledgements
|
|
|
|
|
|
|
|
|
|
- [Axum](https://github.com/tokio-rs/axum)
|
2025-03-20 17:33:57 +07:00
|
|
|
- [SurrealDB](https://github.com/surrealdb/surrealdb)
|