A high-performance, production-ready full-stack Todo application built with Drogon C++ Framework for the backend, Next.js 15 for the frontend, and PostgreSQL as the database. Features include JWT authentication, RESTful API, Docker containerization, and Kubernetes deployment with CI/CD pipeline.
- Features
- Tech Stack
- Architecture
- Prerequisites
- Installation & Setup
- API Documentation
- Deployment
- Project Structure
- Contributing
- License
- π High-Performance: Built with Drogon, one of the fastest C++ web frameworks
- π JWT Authentication: Secure token-based authentication with bcrypt password hashing
- π CRUD Operations: Complete Todo management (Create, Read, Update, Delete)
- ποΈ PostgreSQL Integration: Robust ORM support with Drogon's built-in mapper
- π‘οΈ Custom Middleware: Authentication filters and error handling
- π CORS Support: Pre-configured CORS for frontend integration
- π₯ Health Check: Built-in health monitoring endpoint
- π¦ Docker Ready: Multi-stage builds for optimized production images
- β‘ Next.js 15: Latest React framework with Turbopack
- π¨ Modern UI: Tailwind CSS with Radix UI components
- π Real-time Updates: Seamless todo management interface
- π― Type-Safe: Full TypeScript implementation
- π± Responsive Design: Mobile-first approach
- π³ Docker & Docker Compose: Containerized development and production
- βΈοΈ Kubernetes Ready: Complete K8s manifests with Ingress
- π CI/CD Pipeline: Jenkins integration with automated builds
- π ArgoCD: GitOps-based continuous deployment
- π Secrets Management: Kubernetes secrets for sensitive data
- Framework: Drogon v1.9.0 (C++20)
- Database: PostgreSQL 15
- Authentication: JWT-CPP, Bcrypt.cpp
- ORM: Drogon ORM
- Build System: CMake 3.5+
- Framework: Next.js 15.2.4
- Language: TypeScript 5
- Styling: Tailwind CSS 4
- UI Components: Radix UI, Lucide Icons
- HTTP Client: Axios
- Containerization: Docker, Docker Compose
- Orchestration: Kubernetes
- CI/CD: Jenkins, ArgoCD
- Ingress: NGINX Ingress Controller
βββββββββββββββ ββββββββββββββββ ββββββββββββββββ
β Next.js ββββββββββΆβ Drogon C++ ββββββββββΆβ PostgreSQL β
β Frontend β HTTP β Backend β ORM β Database β
β (Port 3000)β β (Port 3001) β β (Port 5432) β
βββββββββββββββ ββββββββββββββββ ββββββββββββββββ
β β
β β
βΌ βΌ
βββββββββββββββ ββββββββββββββββ
β Docker β β Kubernetes β
β Compose β β Cluster β
βββββββββββββββ ββββββββββββββββ
- Docker (20.10+)
- Docker Compose (2.0+)
- C++20 compiler (GCC 10+/Clang 10+/MSVC 2019+)
- CMake (3.5+)
- PostgreSQL (15+)
- Drogon Framework (v1.9.0)
- Node.js (20+) - only if working on the frontend
my-fastest-drogon-app-cpp/
βββ CMakeLists.txt
βββ config.json
βββ config.docker.json
βββ Dockerfile # production (multi-stage)
βββ Dockerfile.dev # development image with entrypoint
βββ docker-compose.yml # postgres service (API optional)
βββ db.dockerfile # builds DB image seeded with init.sql
βββ init.sql # DB schema (users, todos)
βββ Jenkinsfile # CI pipeline: build, push, retag k8s, push changes
βββ scripts/
β βββ dev-entrypoint.sh
βββ src/
β βββ main.cc
β βββ controllers/
β β βββ api_v1_User.{h,cc}
β β βββ api_v1_todos.{h,cc}
β β βββ api_v1_health.{h,cc}
β βββ filters/
β β βββ auth.{h,cc}
β β βββ CorsMiddleware.{h,cc}
β βββ models/
β β βββ Users.{h,cc}
β β βββ Todos.{h,cc}
β β βββ model.json
β βββ utils/
β βββ AppError.{h,cc}
β βββ token.{h,cc}
βββ k8s/
β βββ namespace.yaml
β βββ ingress.yaml
β βββ app/
β β βββ deployment.yaml
β β βββ secret.yaml
β β βββ svc.yaml
β βββ db/
β βββ deployment.yaml
β βββ pv.yaml
β βββ pvc.yaml
β βββ secrets.yaml
β βββ svc.yaml
βββ dependencies/ # vendored jwt-cpp, Bcrypt (used via CMake)
Note: Folders build/, pgdata/, uploads/ excluded. Frontend has its own README in frontend/.
Two configs are provided; Drogon auto-loads config.json from the working directory.
config.json(local): connects to127.0.0.1:5432config.docker.json(containers): connects to servicepostgres
Example (local config.json):
{
"listeners": [{ "address": "0.0.0.0", "port": 3001 }],
"db_clients": [{
"rdbms": "postgresql",
"host": "127.0.0.1",
"port": 5432,
"dbname": "userdb",
"user": "postgres",
"password": "postgres",
"is_fast": false
}]
}JWT secret (required by src/utils/token.cc):
- Local/dev: set environment variable
JWT_SECRET - Kubernetes: provided through
k8s/app/secret.yaml(key:jwt_secret)
-
Start PostgreSQL with Docker Compose
docker-compose up -d postgres
-
Build and run the application
docker build -t drogon-app:latest -f Dockerfile . docker run --rm -p 3001:3001 -e JWT_SECRET=your-secret-key drogon-app:latest
-
Install Drogon (build from source v1.9.0 as shown in
setup.md) -
Build the application
mkdir build cd build cmake .. -DCMAKE_BUILD_TYPE=Debug cmake --build . -j
-
Setup database and run
# Ensure PostgreSQL is running and load the schema psql -h 127.0.0.1 -U postgres -d userdb -f ../init.sql # Set JWT secret and run $Env:JWT_SECRET="your-secret-key-here" .\my_drogon_app.exe
Backend will read
config.jsonand listen on port 3001.
Base URL: http://localhost:3001/api/v1
- POST
/User/signupβ Register (name, email, password) β returns JWT - POST
/User/loginβ Login (email, password) β returns JWT - GET
/User/profileβ Get user profile (requiresAuthorization: Bearer <token>)
- POST
/todos/createβ Create todo{ title, completed } - GET
/todos/getAllβ List all todos for authenticated user - GET
/todos/{id}β Get single todo by ID - GET
/todos/getAll/{completion}β Filter todos by completion status (true/false) - PUT
/todos/update/{id}β Update todo{ title, completed } - DELETE
/todos/delete/{id}β Delete todo
- GET
/health/β Service status
CORS is handled globally in src/main.cc and via CorsMiddleware.
-
Create namespace
kubectl apply -f k8s/namespace.yaml
-
Deploy PostgreSQL database
kubectl apply -f k8s/db/
-
Deploy application
kubectl apply -f k8s/app/
-
Setup Ingress
kubectl apply -f k8s/ingress.yaml
-
Verify deployment
kubectl get pods -n drogon-project kubectl get svc -n drogon-project kubectl get ingress -n drogon-project
Jenkins Pipeline (Jenkinsfile):
- Validates parameters (requires
BACKEND_DOCKER_TAG) - Cleans workspace and clones repository
- Builds Docker image and pushes to Docker Hub (requires
dockerhubCredentials) - Updates
k8s/app/deployment.yamlimage tag - Commits changes back to repository (requires
Github-Cred)
ArgoCD: Helper scripts and documentation in k8s/ for GitOps-style continuous deployment.
src/utils/token.ccreadsJWT_SECRETfrom environment variable- ORM models are mapped in
src/models/*.ccandmodel.json(tables: users, todos) src/filters/auth.*injectsuserIdandemailinto request parameters after JWT validationinit.sqlcreatesusersandtodostables with foreign keys and timestamps
-
Define route in controller header (
src/controllers/api_v1_User.h):METHOD_ADD(User::newEndpoint, "/newPath", Post, "auth"); void newEndpoint(const HttpRequestPtr& req, std::function<void (const HttpResponsePtr &)> &&callback);
-
Implement method (
src/controllers/api_v1_User.cc):void User::newEndpoint(const HttpRequestPtr& req, std::function<void (const HttpResponsePtr &)> &&callback) { try { auto json = req->getJsonObject(); // Your logic here Json::Value response; response["status"] = "success"; auto resp = HttpResponse::newHttpJsonResponse(response); callback(resp); } catch (const std::exception &e) { auto resp = HttpResponse::newHttpResponse(); resp->setStatusCode(k500InternalServerError); resp->setBody(e.what()); callback(resp); } }
-
Rebuild and test:
cd build cmake --build . -j .\my_drogon_app.exe
-
Update database schema (
init.sql):CREATE TABLE new_table ( id SERIAL PRIMARY KEY, field1 VARCHAR(255) NOT NULL, created_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP );
-
Update model configuration (
src/models/model.json):{ "tables": ["users", "todos", "new_table"] } -
Generate model classes:
drogon_ctl create model src/models/model.json
-
Update CMakeLists.txt to include the new model source files and rebuild
-
Port Already in Use
# Find and stop the process using port 3001 Get-Process -Id (Get-NetTCPConnection -LocalPort 3001).OwningProcess | Stop-Process
-
Database Connection Failed
- Ensure PostgreSQL is running
- Check database credentials in
config.json - Verify database exists:
psql -h localhost -U postgres -d userdb
-
Build Errors
- Ensure Drogon is properly installed
- Check CMake version:
cmake --version - Verify C++20 compiler support
-
Docker Issues
# Reset Docker containers docker-compose down -v docker-compose up -d
- Fork the repository
- Create a feature branch:
git checkout -b feature-name - Make your changes and test thoroughly
- Commit:
git commit -m 'Add feature' - Push:
git push origin feature-name - Submit a pull request
MIT License Β© 2025 Suryansh Verma - see LICENSE file for details.
- Drogon Framework - High-performance C++ web framework
- PostgreSQL - Robust database system
- JWT-CPP - JWT token library
- BCrypt - Password hashing
Built with β€οΈ using C++20 and Drogon Framework