This guide provides instructions and best practices for developing the Cyber Training Platform.
- Python 3.7+
- VirtualBox 7.0+
- Git
- PostgreSQL
- Node.js and npm (for frontend development)
- Your favorite IDE (VS Code recommended)
- Clone the Repository
git clone https://github.com/your-org/cyber-training-platform.git
cd cyber-training-platform- Set Up Python Environment
# Create and activate virtual environment
python -m venv venv
source venv/bin/activate # On Windows: venv\Scripts\activate
# Install dependencies
pip install -r requirements.txt- Database Setup
# Create development database
createdb cyberlab_dev
# Run migrations
alembic upgrade head- Environment Configuration
# Copy example environment file
cp example.env .env
# Edit .env with your development settings
# Make sure to set DEBUG=True for development- Frontend Setup
cd frontend
npm install- Running the Development Server
# From the project root
python -m uvicorn app.main:app --reload- Creating Database Migrations
# After making model changes
alembic revision --autogenerate -m "Description of changes"
alembic upgrade head- Running Tests
# Run all tests
pytest
# Run with coverage
pytest --cov=app tests/
# Run specific test file
pytest tests/test_specific.py- Running the Development Server
cd frontend
npm start- Building for Production
npm run build- Follow PEP 8 guidelines
- Use type hints
- Maximum line length: 88 characters (Black formatter)
- Use docstrings for functions and classes
Example:
def get_user_labs(user_id: int) -> List[Lab]:
"""
Retrieve all labs associated with a user.
Args:
user_id: The ID of the user
Returns:
List of Lab objects associated with the user
"""
return Lab.query.filter_by(user_id=user_id).all()- Use ESLint configuration
- Follow React best practices
- Use TypeScript for type safety
- Use functional components with hooks
Example:
interface LabProps {
labId: string;
name: string;
}
const Lab: React.FC<LabProps> = ({ labId, name }) => {
const [status, setStatus] = useState<string>('');
useEffect(() => {
// Effect logic here
}, [labId]);
return (
<div>
<h2>{name}</h2>
<p>Status: {status}</p>
</div>
);
};├── app/
│ ├── api/ # API endpoints
│ ├── core/ # Core functionality
│ ├── models/ # Database models
│ └── services/ # Business logic
├── frontend/
│ ├── src/
│ │ ├── components/ # React components
│ │ ├── hooks/ # Custom hooks
│ │ └── services/ # API services
│ └── public/ # Static files
└── tests/ # Test files
- Write unit tests for all new features
- Maintain test coverage above 80%
- Use pytest fixtures for common setup
- Mock external services
Example:
def test_create_lab(client, auth_headers):
response = client.post(
"/api/labs",
json={"name": "Test Lab", "template": "ubuntu"},
headers=auth_headers
)
assert response.status_code == 201
assert response.json()["name"] == "Test Lab"- Use React Testing Library
- Write tests for critical user paths
- Test component behavior, not implementation
Example:
test('renders lab details', () => {
render(<Lab labId="123" name="Test Lab" />);
expect(screen.getByText('Test Lab')).toBeInTheDocument();
});- All new endpoints must be documented using FastAPI's built-in documentation
- Include request/response examples
- Document all possible response codes
Example:
@router.post("/labs", response_model=LabResponse)
async def create_lab(
lab: LabCreate,
current_user: User = Depends(get_current_user)
) -> LabResponse:
"""
Create a new lab instance.
Args:
lab: Lab creation parameters
current_user: Currently authenticated user
Returns:
Created lab details
Raises:
HTTPException: If lab creation fails
"""
# Implementation-
Branch Naming
- Feature branches:
feature/description - Bug fixes:
fix/description - Hotfixes:
hotfix/description
- Feature branches:
-
Commit Messages
- Use present tense
- Be descriptive
- Reference issues when applicable
Example:
git commit -m "Add user authentication endpoint (#123)"- Pull Requests
- Create PR from your branch to master
- Include description of changes
- Reference related issues
- Ensure CI passes
- Get code review approval
-
Backend Debugging
- Use FastAPI's debug mode
- Check logs in
logs/app.log - Use pdb for Python debugging
import pdb; pdb.set_trace()
-
Frontend Debugging
- Use React Developer Tools
- Check browser console
- Use debugger statement
debugger;
-
Database Migrations
# Reset migrations alembic downgrade base alembic upgrade head -
Virtual Environment
# Recreate environment rm -rf venv python -m venv venv source venv/bin/activate pip install -r requirements.txt
-
Frontend Build Issues
# Clear npm cache npm cache clean --force rm -rf node_modules npm install
- Check existing issues on GitHub
- Ask in the development channel
- Contact the tech lead
- Review the troubleshooting guide
Remember to keep this guide updated as development practices evolve!