{"id":29353695,"url":"https://github.com/kanishk1420/org-chart-api-test","last_synced_at":"2026-05-14T12:34:40.044Z","repository":{"id":303195127,"uuid":"1014695955","full_name":"Kanishk1420/Org-Chart-Api-Test","owner":"Kanishk1420","description":"A RESTful API built with Drogon,, a high-performance C++ framework. This API is designed to manage organizational structures, including persons, departments, and job roles.","archived":false,"fork":false,"pushed_at":"2025-07-06T08:38:06.000Z","size":1453,"stargazers_count":1,"open_issues_count":0,"forks_count":0,"subscribers_count":0,"default_branch":"master","last_synced_at":"2025-07-06T09:32:13.926Z","etag":null,"topics":["cmake","cpp","docker","googletest","testing","vcpkg"],"latest_commit_sha":null,"homepage":"","language":"C++","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/Kanishk1420.png","metadata":{"files":{"readme":"ReadMe.md","changelog":null,"contributing":null,"funding":null,"license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null,"zenodo":null}},"created_at":"2025-07-06T08:22:40.000Z","updated_at":"2025-07-06T08:44:52.000Z","dependencies_parsed_at":"2025-07-06T09:32:18.050Z","dependency_job_id":"f0aaf75f-f3a5-4231-a669-64effb4a9a2c","html_url":"https://github.com/Kanishk1420/Org-Chart-Api-Test","commit_stats":null,"previous_names":["kanishk1420/org-chart-api-test"],"tags_count":0,"template":false,"template_full_name":null,"purl":"pkg:github/Kanishk1420/Org-Chart-Api-Test","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Kanishk1420%2FOrg-Chart-Api-Test","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Kanishk1420%2FOrg-Chart-Api-Test/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Kanishk1420%2FOrg-Chart-Api-Test/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Kanishk1420%2FOrg-Chart-Api-Test/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/Kanishk1420","download_url":"https://codeload.github.com/Kanishk1420/Org-Chart-Api-Test/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Kanishk1420%2FOrg-Chart-Api-Test/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":278399611,"owners_count":25980332,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","status":"online","status_checked_at":"2025-10-04T02:00:05.491Z","response_time":63,"last_error":null,"robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":true,"can_crawl_api":true,"host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["cmake","cpp","docker","googletest","testing","vcpkg"],"created_at":"2025-07-09T02:08:57.299Z","updated_at":"2025-10-05T01:52:55.155Z","avatar_url":"https://github.com/Kanishk1420.png","language":"C++","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Org Chart API\n\nA **RESTful API** built with [Drogon](https://github.com/drogonframework/drogon), a high-performance C++ framework. This API is designed to manage organizational structures, including persons, departments, and job roles.\n\n🔐 **All routes are protected using JWT for token-based authentication**.\n\n## 🧪 Unit Test Generator\n\nThis project includes an AI-assisted Unit Test Generator for C++ Drogon applications. The generator uses GitHub Copilot and a structured approach to create, refine, and analyze test coverage for the API.\n\n### 📝 Test Generation Approach\n\nThe test generator implements a multi-stage approach:\n\n1. **Source Code Analysis**: Automatically scans controller files to identify endpoints and routes\n2. **Prompt Generation**: Creates AI-ready prompts for GitHub Copilot\n3. **Test Generation**: Produces two types of tests:\n   - **Template-based tests**: Detailed tests with specific assertions\n   - **Stub tests**: Simplified tests that compile without external dependencies\n\n### 🛠️ Tools and Components\n\nThe test generator consists of:\n\n1. **`generate_tests.cpp`**: C++ generator script that:\n   - Scans the codebase for controllers and API endpoints\n   - Creates AI-ready prompts\n   - Generates test files from templates\n\n2. **`test_generation_config.yaml`**: Configuration file defining:\n   - Test framework (Drogon)\n   - Coverage targets\n   - Assertion types\n   - Test case categories\n\n3. **`test_template.txt`**: Template for generating structured test cases\n\n### 📊 Test Coverage Results\n\nThe generated tests achieved:\n- 100% coverage of test code (71/71 lines)\n- 40.6% coverage of Drogon core components\n- 17.3% overall project coverage (4,806/27,786 lines)\n![Coverage Report](./docs/images/Screenshot%202025-07-06%20134449.png)\n*LCOV coverage report showing line and function coverage across project components*\n\n### 🚀 How to Use the Test Generator\n\n1. **Build the Test Generator**:\n   ```bash\n   g++ generate_tests.cpp -o generate_tests\n   ```\n\n2. **Run the Generator**:\n   ```bash\n   ./generate_tests\n   ```\n\n3. **Review and Refine Generated Tests**:\n   - Examine the generated test files in the `test/` directory\n   - Use GitHub Copilot to complete test implementations\n\n4. **Run the Tests**:\n   ```bash\n   cd build\n   cmake .. -DBUILD_TESTING=ON\n   make\n   ./test/unittest\n   ```\n\n5. **Generate Coverage Report**:\n   ```bash\n   cd build\n   lcov --capture --directory . --output-file coverage.info\n   genhtml coverage.info --output-directory coverage_report\n   ```\n\n### 🐳 Testing with Docker\n\nFor a consistent testing environment, use the provided Dockerfile:\n\n```bash\ndocker build -t org-chart-tests .\ndocker run -it org-chart-tests\n```\n\nThis will build the project, run all tests, and generate a coverage report.\n\n### 📋 Test Categories\n\nThe generator creates tests for:\n- **Positive Cases**: Verify correct behavior with valid inputs\n- **Negative Cases**: Verify error handling with invalid inputs\n- **Edge Cases**: Test boundary conditions and unusual scenarios\n\n### 🔍 Controllers Tested\n\n1. **AuthController**:\n   - Register user endpoint\n   - Login user endpoint\n   \n2. **DepartmentsController**:\n   - List departments\n   - Get department by ID\n   - Create department\n   \n3. **PersonsController**:\n   - List people\n   - Get person by ID\n   - Create/update/delete person\n\n---\n\n## 📚 Endpoints\n\n| Method   | URI                                                       | Action                    |\n| -------- | --------------------------------------------------------- | ------------------------- |\n| `GET`    | `/persons?limit={}\u0026offset={}\u0026sort_field={}\u0026sort_order={}` | Retrieve all persons      |\n| `GET`    | `/persons/{id}`                                           | Retrieve a single person  |\n| `GET`    | `/persons/{id}/reports`                                   | Retrieve direct reports   |\n| `POST`   | `/persons`                                                | Create a new person       |\n| `PUT`    | `/persons/{id}`                                           | Update a person's details |\n| `DELETE` | `/persons/{id}`                                           | Delete a person           |\n\n---\n\n### 🏢 Departments\n\n| Method   | URI                                                           | Action                      |\n| -------- | ------------------------------------------------------------- | --------------------------- |\n| `GET`    | `/departments?limit={}\u0026offset={}\u0026sort_field={}\u0026sort_order={}` | Retrieve all departments    |\n| `GET`    | `/departments/{id}`                                           | Retrieve a department       |\n| `GET`    | `/departments/{id}/persons`                                   | Retrieve department members |\n| `POST`   | `/departments`                                                | Create a department         |\n| `PUT`    | `/departments/{id}`                                           | Update department info      |\n| `DELETE` | `/departments/{id}`                                           | Delete a department         |\n\n---\n\n### 💼 Jobs\n\n| Method   | URI                                                     | Action                        |\n| -------- | ------------------------------------------------------- | ----------------------------- |\n| `GET`    | `/jobs?limit={}\u0026offset={}\u0026sort_fields={}\u0026sort_order={}` | Retrieve all job roles        |\n| `GET`    | `/jobs/{id}`                                            | Retrieve a job role           |\n| `GET`    | `/jobs/{id}/persons`                                    | Retrieve people in a job role |\n| `POST`   | `/jobs`                                                 | Create a job role             |\n| `PUT`    | `/jobs/{id}`                                            | Update job role               |\n| `DELETE` | `/jobs/{id}`                                            | Delete a job role             |\n\n---\n\n### 🔐 Auth\n\n| Method | URI              | Action                              |\n| ------ | ---------------- | ----------------------------------- |\n| `POST` | `/auth/register` | Register a user and get a JWT token |\n| `POST` | `/auth/login`    | Login and receive a JWT token       |\n\n---\n\n## 📦 Two Ways to Get Started\n\nThere are two ways to run the project:\n\n### 1. **Using Docker** (Recommended for ease of setup)\n\nDocker simplifies the setup process and ensures all dependencies are handled automatically.\n\n### 2. **Manual Setup** (For those who prefer to run the project locally)  \nFollow these steps if you want to run the application without Docker, but make sure to install dependencies and configure everything manually.\n\n---\n\n## 🐳 Using Docker\n\n**1. Clone the Repository:**\n\n```bash\ngit clone https://github.com/keploy/orgChartApi.git\ncd orgChartApi\n````\n\n**2. Start the Docker Containers:**\n\nRun the following command to bring up the services (PostgreSQL and the app):\n\n```bash\ndocker-compose up\n```\n\n**3. Confirm Containers are Running:**\n\nCheck the status of your containers:\n\n```bash\ndocker-compose ps\n```\n\nYou should see two containers running: one for the PostgreSQL database and one for the application.\n\n**4. Access the Application:**\n\nThe application will be available at `http://localhost:3000` by default. You can now interact with the API using any HTTP client.\n\n### Note: Once the Application has started, See the usage guide to see how to interact with the application.\n\n---\n\n## 🖥️ Manual Setup (Without Docker)\n\nIf you prefer to manually set up the project, follow these steps.\n\n### 📦 Prerequisites\n\nMake sure you have the following tools installed on your system:\n\n* Git\n* GCC and G++\n* CMake\n* PostgreSQL\n* OpenSSL\n* libjsoncpp-dev\n* Other dependencies (listed below)\n\n\n### 📥 Install Dependencies\n\n**For Ubuntu**, run the following commands to install necessary tools:\n\n```bash\nsudo apt install git gcc g++ cmake\nsudo apt install libjsoncpp-dev     # jsoncpp\nsudo apt install uuid-dev           # uuid\nsudo apt install zlib1g-dev         # zlib\nsudo apt install openssl libssl-dev # OpenSSL \nsudo apt-get install postgresql-all # PostgreSQL (for DB support)\n```\n\n**⚠️ Note:** Install database libraries **before** installing Drogon to avoid errors.\n\n### 🐉 Drogon Installation\n\nNow, let's install Drogon:\n\n```bash\n# Clone the repository\ncd $WORK_PATH\ngit clone https://github.com/drogonframework/drogon\ncd drogon\ngit submodule update --init\nmkdir build \u0026\u0026 cd build\ncmake ..\nmake \u0026\u0026 sudo make install\n```\n\n### ✅ Verify Drogon Installation\n\nOnce Drogon is installed, you can verify it with:\n\n```bash\ndrogon_ctl -v\n```\n\nYou should see the Drogon version and other relevant information.\n\n---\n\n**Important:**  \n\nThere are **two changes in the Application** you need to make when setting it up manually:\n\n1. **Change the hostname** from `db` to `localhost` in the `config.json` file.\n2. **Change the port** from `5432` to `5433` in the `config.json` file.\n\n\n## 🗃️ Database Setup\n\n### 1. **Start PostgreSQL**\n\nTo start the PostgreSQL database locally:\n\n```bash\ndocker run --name pg -e POSTGRES_PASSWORD=password -d -p 5433:5432 postgres\n```\n\n**2. Install Postgres Client:**\n\nIf you don’t have the PostgreSQL client installed, run:\n\n```bash\nsudo apt install postgresql-client\n```\n\n**3. Create the Database:**\n\nLog into PostgreSQL and create the `org_chart` database:\n\n```bash\npsql 'postgresql://postgres:password@127.0.0.1:5433/'\nCREATE DATABASE org_chart;\n```\n\n**4. Seed the Database:**\n\nRun the following SQL files to set up the necessary tables:\n\n```bash\npsql 'postgresql://postgres:password@127.0.0.1:5433/org_chart' -f scripts/create_db.sql\npsql 'postgresql://postgres:password@127.0.0.1:5433/org_chart' -f scripts/seed_db.sql\n```\n\n---\n\n## 🏗️ Build the Project\n\n### 1. **Clone the Repository:**\n\n```bash\ngit clone https://github.com/keploy/orgChartApi.git \ncd orgChartApi\ngit submodule update --init\n```\n\n### 2. **Build the Project:**\n\nTo build the project, run the following commands:\n\n```bash\nmkdir build \u0026\u0026 cd build\ncmake ..\nmake\n```\n\n---\n\n## ▶️ Run the Application\n\nOnce the project is built, ensure that the `config.json` file is correctly configured with your database settings, then run the application:\n\n```bash\n./org_chart\n```\n\nThe app will now be running and accessible at `http://localhost:3000`.\n\n---\n\n## 💡 Usage Guide\n\n### 1. **Register a User:**\n\nInstall [HTTPie](https://httpie.io/) if you haven’t already:\n\n```bash\nsudo apt install httpie\n```\n\nTo register a new user, run:\n\n```bash\nhttp post localhost:3000/auth/register username=\"admin1\" password=\"password\"\n```\n(or)\n\n```bash\n\ncurl -X POST http://localhost:3000/auth/register \\\n  -H \"Content-Type: application/json\" \\\n  -d '{\"username\":\"admin1\",\"password\":\"password\"}'\n\n```\n\nYou will receive a JWT token as the response:\n\n```json\n{\n  \"token\": \"jwt_token_here\",\n  \"username\": \"admin1\"\n}\n```\n\n### 2. **Login:**\n\nTo log in and receive a token:\n\n```bash\nhttp post localhost:3000/auth/login username=\"admin1\" password=\"password\"\n```\n\nThe response will look like:\n\n```json\n{\n  \"token\": \"jwt_token_here\",\n  \"username\": \"admin1\"\n}\n```\n\n### 3. **Access Protected Resources:**\n\nUse the JWT token to access protected endpoints:\n\n```bash\nhttp --auth-type=bearer --auth=\"your_jwt_token\" get localhost:3000/persons offset==1 limit==25 sort_field==id sort_order==asc\n```\n\nSample response:\n\n```json\n[\n  {\n    \"id\": 2,\n    \"first_name\": \"Gary\",\n    \"last_name\": \"Reed\",\n    \"hire_date\": \"2018-04-07 01:00:00\",\n    \"job\": {\n      \"id\": 2,\n      \"title\": \"M1\"\n    },\n    \"department\": {\n      \"id\": 1,\n      \"name\": \"Product\"\n    },\n    \"manager\": {\n      \"id\": 1,\n      \"full_name\": \"Sabryna Peers\"\n    }\n  },\n  ...\n]\n```\n\n---\n\n## 🔧 Tools \u0026 Technologies Used\n\nThis project uses several specialized tools and technologies that may be unfamiliar to those new to C++ development. Here's a brief overview:\n\n### Core Technologies\n\n1. **C++**: A powerful, high-performance programming language used for system-level programming and applications requiring efficient resource usage.\n\n2. **[Drogon](https://github.com/drogonframework/drogon)**: A high-performance C++ web framework with the following features:\n   - **Fast**: Capable of handling high concurrent connections with minimal overhead\n   - **Asynchronous**: Non-blocking I/O operations for efficient resource usage\n   - **Modern**: Uses C++14/17 features for clean, maintainable code\n   - **ORM Support**: Built-in object-relational mapping for database operations\n\n3. **PostgreSQL**: A powerful, open-source relational database system used to store the application data.\n\n### Testing Tools\n\n1. **GoogleTest**: Google's C++ testing framework that provides:\n   - Easy test case creation and organization\n   - Rich set of assertions for validating results\n   - Test fixtures for sharing resources across tests\n\n2. **LCOV**: A code coverage analysis tool for C/C++ that:\n   - Collects execution data during test runs\n   - Generates HTML reports showing code coverage metrics\n   - Helps identify untested parts of the codebase\n\n3. **genhtml**: A tool that converts LCOV data into human-readable HTML reports with:\n   - Color-coded source code highlighting showing covered/uncovered lines\n   - Summary statistics for directories and files\n   - Navigation features for browsing complex codebases\n\n### Build Tools\n\n1. **CMake**: A cross-platform build system generator that:\n   - Creates build files (Makefiles, Visual Studio projects, etc.) from a single configuration\n   - Manages dependencies between components\n   - Supports build variants (debug, release, etc.)\n\n2. **Docker**: A containerization platform that:\n   - Provides consistent environments across development and production\n   - Eliminates \"works on my machine\" problems\n   - Simplifies dependency management\n\n### Development Tools\n\n1. **GitHub Copilot**: An AI pair programming tool that:\n   - Suggests code completions based on context\n   - Helps generate test cases and implementations\n   - Accelerates development by reducing boilerplate coding\n\n2. **JWT (JSON Web Tokens)**: A compact, URL-safe means of representing claims securely between parties, used for authentication in the API.\n\nFor users new to C++ development, this project uses Docker to simplify the setup process, so you can get started without installing all these tools individually.\n\n## 🧯 Troubleshooting\n\n* **OpenSSL not found?**\n  If you encounter issues with OpenSSL, point CMake to the OpenSSL installation manually:\n\n  ```bash\n  cmake -DOPENSSL_ROOT_DIR=/usr/local/opt/openssl ..\n  ```\n\n* **LSP / IntelliSense not working?**\n  Enable compile commands for better LSP support:\n\n  ```bash\n  cmake -DCMAKE_EXPORT_COMPILE_COMMANDS=ON ..\n  ```","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fkanishk1420%2Forg-chart-api-test","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fkanishk1420%2Forg-chart-api-test","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fkanishk1420%2Forg-chart-api-test/lists"}