How keploy/orgchartapi works
Project Type and Purpose
• This is a backend-only, RESTful API written in C++ using the Drogon framework.
• It manages organizational data—persons, departments, and jobs—with JWT-based authentication.
• It runs in a Dockerized environment alongside a PostgreSQL database.
High-Level File Structure Analysis
• Top-level:
• main.cc, CMakeLists.txt, build scripts (build.sh, run.sh), Docker files (Dockerfile, docker-compose.yml).
• Configuration: config.json.
• Third-party libraries under third_party (Drogon, jsoncpp, jwt-cpp, libbcrypt).
• Source code:
• controllers/ (AuthController, PersonsController, DepartmentsController, JobsController)
• models/ (Person, Department, Job, User, plus JSON schemas)
• filters/ (LoginFilter for JWT validation)
• plugins/ (JwtPlugin for signing/verifying tokens)
• utils/ (generic helper functions)
• Database setup: scripts/ (SQL to create and seed DB).
• Tests under test/.
Key Architectural Patterns
• MVC-style layering:
• Routing & HTTP layer (Drogon)
• Filter/Middleware (JWT validation)
• Controller layer (request handling, input validation)
• Model/Data access layer (ORM or raw SQL via JSON models)
• Database (PostgreSQL)
• Plugin-based extension: JwtPlugin isolates token logic.
• External dependencies: jsoncpp for JSON, jwt-cpp for JWT, libbcrypt for password hashing.
Main Components
a. API Gateway / HTTP Server
• Drogon framework listening on port 3000.
b. Authentication Filter
• LoginFilter intercepts requests, validates JWT via JwtPlugin.
c. Controller Modules
• AuthController (register/login)
• PersonsController, DepartmentsController, JobsController (CRUD endpoints)
d. Model Layer
• C++ model classes representing DB tables.
• JSON schema (model.json) if relevant.
e. Database
• PostgreSQL instance (container “db”).
• SQL scripts used at startup.
f. External Libraries
• jsoncpp, jwt-cpp, libbcrypt.
g. Infrastructure
• Docker Compose orchestrating two containers: app and postgres.
• Build system (CMake).
Relationships and Data Flow
1. Client sends HTTP request →
2. Drogon HTTP Server receives →
3. LoginFilter checks Authorization header →
• If JWT missing/invalid, reject.
• If valid, attach user context to request.
4. Controller invoked based on route →
5. Controller calls Model/Database for CRUD →
6. PostgreSQL executes SQL → result returns to Controller →
7. Controller serializes response via jsoncpp →
8. HTTP Server returns JSON to Client.
For /auth routes:
• AuthController hashes password (bcrypt), stores/validates user in DB, generates JWT via JwtPlugin.