How freyam13/asset-grouping-service works
Project type and purpose
• This is a backend REST API service (FastAPI) for dynamic grouping of cloud assets based on configurable rules.
• Key purpose: expose endpoints for asset and rule creation/update, evaluate grouping logic in real-time, and return grouped assets.
a. API Layer
• FastAPI app (src/main.py)
• Routes module (src/api/routes.py)
• OpenAPI/Swagger UI (automatic via FastAPI)
b. Service Layer
• GroupingService (src/services/grouping.py)
• Business logic for rule evaluation and group assignment
c. Data Models
• Pydantic schemas (src/models/schemas.py) representing Asset, Tag, GroupingRule, Condition, Operator enum
d. Persistence / Data Store
• In-memory storage or stub repository (future DB integration)
• Placeholder for assets and rules collections
e. Clients / Consumers
• REST clients (e.g., CLI, UI, other services) calling HTTP endpoints
• Tests (pytest suite under tests/)
• Authentication & Authorization service
• Monitoring & Metrics
• Caching layer
Relationships and data flow
1. Client HTTP Request → FastAPI Router
2. Router validates request via Pydantic schema → constructs model instance
3. Router calls Service Layer method (e.g., create_asset, create_rule)
4. Service Layer retrieves/stores data in Data Store, evaluates grouping logic:
– Iterate rules
– Match conditions against asset fields
– Assign group_name
5. Service returns domain model → Router serializes to JSON → HTTP Response
6. Swagger UI / OpenAPI generates interactive docs from route metadata
Architectural patterns & design principles
• Layered architecture (Adapter/Controller layer vs. Service layer vs. Model layer)
• Separation of concerns: no business logic in route handlers
• Dependency injection (FastAPI’s built-in DI for services)
• Pydantic for validation and type safety
• Clear boundaries for future extension (DB, auth, caching)