π» Development Guide - CidadΓ£o.AI Backend
Author: Anderson Henrique da Silva Last Updated: 2025-10-03 (SΓ£o Paulo, Brazil)
This directory contains comprehensive developer guides and implementation references for contributing to the CidadΓ£o.AI Backend project.
π Available Guides
Getting Started
- CONTRIBUTING.md - Complete contribution guide
- Code standards and conventions
- Git workflow and commit guidelines
- Pull request process
- Development environment setup
Implementation Guides
CONVERSATIONAL_AI_IMPLEMENTATION.md - Conversational AI system
- Portuguese intent detection
- Multi-agent dialogue flow
- Context management
- Response generation
INDEX_CHAT_IMPLEMENTATION.md - Chat implementation details
- Real-time chat architecture
- SSE streaming responses
- Message handling patterns
- Error recovery strategies
maritaca_integration.md - Maritaca LLM integration
- API integration patterns
- Optimization techniques
- Rate limiting and caching
- Cost optimization
Technical Implementation
CORS_CONFIGURATION.md - CORS setup and security
- Production-ready CORS configuration
- Security best practices
- Vercel/HuggingFace deployment specifics
CURSOR_PAGINATION_IMPLEMENTATION.md - Cursor-based pagination
- Efficient pagination for large datasets
- Performance optimizations
- API design patterns
GZIP_COMPRESSION_IMPLEMENTATION.md - Response compression
- GZIP middleware configuration
- Compression strategies
- Performance impact analysis
FRONTEND_INTEGRATION_GUIDE.md - Frontend integration
- API client setup
- Authentication flow
- WebSocket integration
- Error handling patterns
Code Examples
- examples/ - Working code examples
- Integration examples
- Agent usage patterns
- API client implementations
π Quick Start for Developers
1. Environment Setup
# Clone the repository
git clone https://github.com/anderson-ufrj/cidadao.ai-backend
cd cidadao.ai-backend
# Install dependencies
make install-dev
# Copy environment template
cp .env.example .env
# Edit .env with your configuration
2. Run Development Server
# Start backend with hot reload
make run-dev
# Or directly with Python
python -m src.api.app
3. Run Tests
# Run all tests with coverage (80% minimum required)
make test
# Run specific test categories
make test-unit # Unit tests only
make test-agents # Multi-agent tests
make test-integration # Integration tests
4. Code Quality Checks
# Format code
make format
# Lint code
make lint
# Type checking
make type-check
# Run all checks
make check
# Full CI locally
make ci
π Development Workflow
1. Before Starting
- Read CONTRIBUTING.md
- Set up pre-commit hooks (optional but recommended)
- Join our communication channels (if available)
2. During Development
- Follow code standards from CONTRIBUTING.md
- Write tests for new features (TDD approach)
- Update documentation as you code
- Run
make checkfrequently
3. Before Committing
- Run
make cito ensure all checks pass - Write descriptive commit messages (conventional commits)
- Update relevant documentation
- Add tests for new functionality
4. Pull Request
- Follow PR template guidelines
- Ensure CI passes
- Request review from maintainers
- Address review feedback promptly
ποΈ Architecture References
For architectural decisions and patterns:
π€ Agent Development
For creating or modifying agents:
π§ Common Development Tasks
Adding a New Agent
- Create agent class in
src/agents/ - Register in
src/agents/__init__.py - Add tests in
tests/unit/agents/ - Create documentation in
docs/agents/ - Update agent status document
Adding a New API Endpoint
- Create/update router in
src/api/routers/ - Add endpoint to
src/api/app.py - Write integration tests
- Update API documentation
- Add to API_ENDPOINTS_MAP.md
Performance Optimization
- Profile the code to identify bottlenecks
- Implement caching where appropriate
- Use async/await for I/O operations
- Add monitoring metrics
- Document optimizations
π Testing Strategy
- Unit Tests: Test individual components in isolation
- Integration Tests: Test component interactions
- Agent Tests: Test multi-agent coordination
- Performance Tests: Benchmark critical paths
- Security Tests: Validate authentication and authorization
Target: 80% code coverage (enforced in CI)
π Security Considerations
- Never commit secrets or API keys
- Use environment variables for configuration
- Follow OWASP security best practices
- Validate all user inputs
- Implement rate limiting on public endpoints
- Keep dependencies updated
π Debugging Tips
# Enable debug logging for agents
import logging
logging.getLogger("src.agents").setLevel(logging.DEBUG)
# Use pdb for interactive debugging
import pdb; pdb.set_trace()
# Profile performance
from src.core.monitoring import agent_metrics
# Metrics automatically collected
π Additional Resources
π€ Getting Help
If you encounter issues:
- Check Troubleshooting Guide
- Search existing GitHub issues
- Review relevant documentation
- Create a new issue with detailed information
Happy coding! π
Remember: Quality over speed. Write tests, document your code, and follow best practices.