Feat/backend improvements#811
Merged
GoSTEAN merged 4 commits intoMay 28, 2026
Merged
Conversation
- Add statusCode and code fields to AppError - Implement static factory methods: notFound(), unauthorized(), forbidden(), badRequest(), conflict(), internalError() - Update error middleware to include code field in response - Refactor MarketService and MarketController to use factory methods - Improves consistency and readability of error handling across backend
- Create env.ts config module with Zod schema validation - Validate all required env vars: DATABASE_URL, REDIS_URL, STELLAR_RPC_URL, ORACLE_KEYPAIR, ADMIN_JWT_SECRET, FACTORY_CONTRACT_ADDRESS - Server exits with descriptive error if validation fails - Update .env.example to document all variables with descriptions - Call validateEnv() in index.ts before starting server
- Add PlatformStats interface with totalMarkets, activeMarkets, totalVolume, totalBets - Implement getPlatformStats() service method with 60-second Redis cache - Query: COUNT(*) WHERE status='open', SUM(total_pool), COUNT(bets) - Add getPlatformStats controller endpoint - Mount GET /api/stats route for home page banner statistics
- Add PlatformStats schema to OpenAPI spec - Add GET /api/stats endpoint documentation - Create swagger.ts config module with setupSwagger() function - Mount Swagger UI at /api/docs in development mode - Serve OpenAPI spec at /openapi.yaml - Add swagger-ui-express and yaml dependencies - All endpoints now have complete request/response schemas - Spec passes OpenAPI 3.0.3 validation
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Backend Infrastructure & Documentation Improvements
Overview
This PR implements 4 critical backend features to improve error handling, configuration management, platform visibility, and API documentation.
Changes
1. AppError Utility Class with Factory Methods (#756)
AppErrorwithcodefield for error categorizationnotFound(),unauthorized(),forbidden(),badRequest(),conflict(),internalError()Benefits: Cleaner error handling, consistent error responses, easier to maintain
2. Environment Variable Validation on Startup (#757)
config/env.tswith Zod schema validationDATABASE_URL,REDIS_URL,STELLAR_RPC_URL,ORACLE_KEYPAIR,ADMIN_JWT_SECRET,FACTORY_CONTRACT_ADDRESS.env.examplewith complete documentationBenefits: Fail-fast on misconfiguration, prevents runtime errors, clear setup instructions
3. Platform Statistics Endpoint (#759)
MarketService::getPlatformStats()with 60-second Redis cache{ totalMarkets, activeMarkets, totalVolume, totalBets }COUNT(*) WHERE status='open',SUM(total_pool),COUNT(bets)GET /api/statsfor home page bannerBenefits: Real-time platform metrics, cached for performance, supports home page analytics
4. OpenAPI/Swagger Documentation (#758)
PlatformStatsschema/api/docsin development/openapi.yamlBenefits: Interactive API documentation, client code generation support, API contract clarity
Testing
Deployment Notes
swagger-ui-express,yamlCommits
feat: implement AppError utility class with factory methodsfeat: set up environment variable validation on startupfeat: implement MarketService::getPlatformStats()feat: add OpenAPI/Swagger documentationCloses #756
Closes #757
Closes #758
Closes #759