Lately, I’ve been delving in web development, mostly on the backend side, and since C++ is the language I’m most comfortable with, I stuck with it.
However, every time I started a new project, I ran into the same problem: setting everything up from scratch. That always took time away from actually building features.
So I decided to fix that.
A C++ Backend Template 🧩
I decided to put together a small, opinionated, but easy-to-use template for C++ backend applications that aims to provide a solid starting point for new projects.
It comes with:
- Docker & Docker Compose support for reproducible builds and easy deployment
- vcpkg as the package manager
- CMake as the build system
- Predefined clang-format rules to keep the codebase consistent
You can check it out here.
The template uses C++23 by default and is built around Crow, a lightweight and fast C++ web framework with similarities to Python's Flask that keeps things simple while still being powerful.
Getting Started 🚀
Dependencies
Make sure you have the following installed:
- C++ compiler (needed in local environment)
- CMake (3.14.0+)
- vcpkg
- Docker and Docker compose
- clang-format (optional, used to format code)
1. Clone the repository
git clone https://github.com/landiluigi746/cpp-backend-template.git
cd cpp-backend-template
From here, you can either rename the project (in CMake, Docker and Docker Compose configs) or directly start building on top of it.
2. Prepare local development environment
Run the following command to generate CMake project files to prepare your local environment:
make devenv
Then, rename the .env.sample file with environment variables to .env and change them if you want.
3. Start the app under Docker containers:
Now build and start the app under Docker with the following command, which under the hood calls Docker compose to build and start all containers.
make up
4. Try if it works
Open your browser and go to http://localhost:<PORT in your .env>. If you see 'Hello world!', you've made it. You got it up and running!
Start building 🛠️
From this point on, you can:
- Add new routes using Crow
- Introduce new dependencies via vcpkg
- Extend the Docker/Docker Compose setup for databases, caches, or other services
- Adjust formatting rules or build options to match your preferences
Let me know what you think! This template is meant to evolve and improve over time, so feedback and contributions are more than welcome. Happy coding!
Top comments (0)