How danshaders/kege-by-danshaders works
Project type and purpose
• This is a full-stack web application (“kege-by-danshaders”).
• Frontend: a React/TypeScript single-page application under ui/.
• Backend: a high-performance C++ HTTP/FCGI service under api/, talking to PostgreSQL.
• Deployment: containerized services orchestrated via docker-compose.yml, using Nginx as a reverse proxy and Postgres for persistence.
• Additional components: Protobuf definitions under proto/ for API schema; developer tools in tools/.
File structure
• Top-level directories:
• api/: CMake-based C++ service, with headers in api/include/async, api/include/routes, implementations in api/src/.
• ui/: React/TSX code, CSS, static HTML entry point, build scripts in build.mjs.
• proto/: .proto files defining messages and service contracts.
• meta/: Dockerfiles, CMake fragments, Nginx config, Postgres init scripts—deployment manifests.
• tools/: standalone CLI utilities (e.g., diff-proto, sql-typer) built with CMake.
• Configuration: docker-compose.yml ties services together.
• Build: multiple CMake projects for the API and tools.
a. Main components
• Frontend SPA (browser)
• Nginx reverse proxy (container)
• C++ API service (FastCGI)
• PostgreSQL database
• Optional tooling/CI containers (for codegen or migrations)
b. Relationships and data flow
1. User interacts with the SPA → HTTP(S) requests
2. Nginx routes frontend asset requests to the static server or proxies API requests to FastCGI
3. API service processes requests via an async event loop, executes SQL (via async/pq), applies business routes (api/include/routes/*.h)
4. API returns JSON over FastCGI → Nginx → Browser
5. Database persists and retrieves data; init scripts under meta/postgres/ run at container startup
6. Protobuf definitions under proto/ document the API schema (used for code generation or cross-service communication)
c. Architectural patterns and design principles
• Asynchronous, non-blocking I/O with an event loop (libev-event-loop)
• Modular route handlers (each REST endpoint in api/routes/)
• Separation of concerns: transport (FastCGI), business logic (routes), data access (async/pq)
• SPA-style client with unidirectional data flow and React component hierarchy
• Containerization and infrastructure as code (Docker, Compose, Nginx, Postgres)
d. Key technologies and frameworks
• C++17 (CMake, coroutines via async/coro.h)
• FastCGI (via fcgx.h)
• libev for event handling
• PostgreSQL driver (async/pq)
• React + TypeScript (bundled via ui/build.mjs)
• Protobuf for API contracts
• Nginx for TLS, proxying, static hosting