# BMC Hub - Development Guide ## ๐Ÿš€ Quick Start ### 1. Clone & Setup ```bash cd /Users/christianthomas/DEV/bmc_hub_dev cp .env.example .env ``` ### 2. Start Development Server ```bash docker-compose up -d docker-compose logs -f ``` ### 3. Verify Installation ```bash # Health check curl http://localhost:8000/health # API docs open http://localhost:8000/api/docs # Dashboard open http://localhost:8000 ``` ## ๐Ÿ“ Project Structure ``` bmc_hub/ โ”œโ”€โ”€ app/ โ”‚ โ”œโ”€โ”€ core/ # Config & database โ”‚ โ”œโ”€โ”€ models/ # Pydantic schemas โ”‚ โ”œโ”€โ”€ routers/ # API endpoints โ”‚ โ”œโ”€โ”€ services/ # Business logic โ”‚ โ””โ”€โ”€ jobs/ # Scheduled tasks โ”œโ”€โ”€ migrations/ # Database migrations โ”œโ”€โ”€ static/ # Web UI โ”œโ”€โ”€ .env.example # Local dev template โ””โ”€โ”€ .env.prod.example # Production template ``` ## ๐Ÿ”ง Development Workflow ### Adding a New Feature 1. **Database Migration** ```sql -- migrations/002_add_services.sql CREATE TABLE services ( id SERIAL PRIMARY KEY, name VARCHAR(255) NOT NULL, customer_id INTEGER REFERENCES customers(id) ); ``` 2. **Pydantic Models** ```python # app/models/schemas.py class ServiceBase(BaseModel): name: str customer_id: int class Service(ServiceBase): id: int ``` 3. **Router** ```python # app/routers/services.py from fastapi import APIRouter router = APIRouter() @router.get("/services") async def list_services(): return execute_query("SELECT * FROM services") ``` 4. **Register Router** ```python # main.py from app.routers import services app.include_router(services.router, prefix="/api/v1", tags=["Services"]) ``` ### Database Queries ```python from app.core.database import execute_query # Fetch customers = execute_query("SELECT * FROM customers WHERE id = %s", (id,)) # Insert result = execute_query( "INSERT INTO customers (name) VALUES (%s) RETURNING *", (name,) ) ``` ### Configuration ```python from app.core.config import settings if settings.ECONOMIC_READ_ONLY: logger.warning("Read-only mode") ``` ## ๐Ÿณ Docker Commands ```bash # Start docker-compose up -d # Logs docker-compose logs -f api # Restart docker-compose restart api # Stop docker-compose down # Rebuild docker-compose up -d --build ``` ## ๐Ÿšข Production Deployment ### On Live Server 1. **Clone & Setup** ```bash cd /opt git clone git@g.bmcnetworks.dk:ct/bmc_hub.git cd bmc_hub ``` 2. **Configure Environment** ```bash cp .env.prod.example .env nano .env # Set RELEASE_VERSION, credentials, etc. ``` 3. **Deploy** ```bash docker-compose -f docker-compose.prod.yml up -d --build ``` 4. **Update to New Version** ```bash # Update .env with new RELEASE_VERSION nano .env # Change to v1.2.3 # Pull and restart docker-compose -f docker-compose.prod.yml up -d --build ``` ## ๐Ÿ“Š Monitoring ### Health Checks ```bash # Simple curl http://localhost:8000/health # Detailed curl http://localhost:8000/api/v1/system/health # Config curl http://localhost:8000/api/v1/system/config ``` ### Logs ```bash # Application logs tail -f logs/app.log # Docker logs docker-compose logs -f api ``` ## ๐Ÿ” Security Checklist ### Before Production - [ ] Change `SECRET_KEY` to random value - [ ] Set strong `POSTGRES_PASSWORD` - [ ] Set `ECONOMIC_READ_ONLY=true` - [ ] Set `ECONOMIC_DRY_RUN=true` - [ ] Use tagged release version (not `latest`) - [ ] Configure proper CORS origins - [ ] Setup Nginx reverse proxy - [ ] Enable SSL/TLS ## ๐Ÿงช Testing ```bash # Install test dependencies pip install pytest pytest-cov # Run tests pytest # With coverage pytest --cov=app --cov-report=html open htmlcov/index.html ``` ## ๐Ÿ“ Git Workflow ### Development ```bash git checkout -b feature/new-feature # Make changes git add . git commit -m "Add new feature" git push origin feature/new-feature ``` ### Release ```bash # Tag release git tag v1.2.3 git push --tags # Update production .env with RELEASE_VERSION=v1.2.3 ``` ## ๐Ÿ”— Links - **API Docs**: http://localhost:8000/api/docs - **ReDoc**: http://localhost:8000/api/redoc - **Dashboard**: http://localhost:8000 - **Gitea**: https://g.bmcnetworks.dk/ct/bmc_hub ## ๐Ÿ†˜ Troubleshooting ### Port Already in Use ```bash lsof -i :8000 kill -9 ``` ### Database Connection Error ```bash docker-compose logs postgres docker-compose restart postgres ``` ### Clear Everything ```bash docker-compose down -v # WARNING: Deletes database! docker-compose up -d ``` ## ๐Ÿ“ž Support - Issues: Gitea Issues - Email: support@bmcnetworks.dk