Skip to content

Commit 15b6552

Browse files
author
DeanLuus22021994
committed
refactor: reorganize infrastructure module into subdirectories by purpose
Following same methodology as Dapr components restructure. Directory Structure: - core/base.py (was base.py) - core/config.py (was config.py) - builders/dockerfile_builder.py (was dockerfile_builder.py) - factories/factories.py (was factories.py) - health/health_checks.py (was health_checks.py) - models/pydantic_models.py (was pydantic_models.py) - testing/fixtures.py (was fixtures.py) - cli.py (stays at root) - __init__.py (updated imports) Rationale: - Groups files by purpose (core, builders, factories, health, models, testing) - Follows proper coding methodology and separation of concerns - Makes codebase more maintainable and discoverable - Easier to add new components of same type - Aligns with Dapr components directory organization Updated: - infrastructure/__init__.py: Updated all imports to use new paths - infrastructure/README.md: Added directory tree diagram and updated module table All imports now use: infrastructure.core.base, infrastructure.health.health_checks, etc.
1 parent 3472890 commit 15b6552

File tree

9 files changed

+56
-17
lines changed

9 files changed

+56
-17
lines changed

.devcontainer/infrastructure/README.md

Lines changed: 40 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -17,18 +17,48 @@ python -m infrastructure.cli generate-dockerfile --type dev --output Dockerfile.
1717
python -m infrastructure.cli generate-dapr --output .devcontainer/dapr-components
1818
```
1919

20+
## Directory Structure
21+
22+
Components are organized by purpose in subdirectories:
23+
24+
```text
25+
infrastructure/
26+
├── core/ # Foundational classes
27+
│ ├── __init__.py
28+
│ ├── base.py # Abstract base classes
29+
│ └── config.py # Configuration dataclasses
30+
├── builders/ # Builder patterns
31+
│ ├── __init__.py
32+
│ └── dockerfile_builder.py # Template Method for Dockerfiles
33+
├── factories/ # Factory patterns
34+
│ ├── __init__.py
35+
│ └── factories.py # Service and component factories
36+
├── health/ # Health check strategies
37+
│ ├── __init__.py
38+
│ └── health_checks.py # Strategy pattern implementations
39+
├── models/ # Data models
40+
│ ├── __init__.py
41+
│ └── pydantic_models.py # Pydantic validation models
42+
├── testing/ # Test utilities
43+
│ ├── __init__.py
44+
│ └── fixtures.py # Pytest fixtures
45+
├── cli.py # Command-line interface
46+
├── __init__.py # Module exports
47+
└── README.md
48+
```
49+
2050
## Architecture
2151

22-
| Module | Purpose |
23-
|--------|---------|
24-
| `base.py` | Abstract base classes (ContainerService, DatabaseService, MessageBrokerService) |
25-
| `health_checks.py` | Health check strategies (HTTP, TCP, Command, Redis, Postgres, Dapr) |
26-
| `config.py` | Configuration dataclasses (EnvironmentConfig, ServiceConfig, DockerComposeConfig) |
27-
| `pydantic_models.py` | Enhanced Pydantic models with validation |
28-
| `factories.py` | Factory classes (ServiceFactory, DaprComponentFactory) |
29-
| `dockerfile_builder.py` | Template Method for Dockerfile generation |
30-
| `cli.py` | Command-line interface |
31-
| `fixtures.py` | Pytest fixtures for testing |
52+
| Module | Location | Purpose |
53+
|--------|----------|---------|
54+
| `base.py` | `core/` | Abstract base classes (ContainerService, DatabaseService, MessageBrokerService) |
55+
| `config.py` | `core/` | Configuration dataclasses (EnvironmentConfig, ServiceConfig, DockerComposeConfig) |
56+
| `dockerfile_builder.py` | `builders/` | Template Method for Dockerfile generation |
57+
| `factories.py` | `factories/` | Factory classes (ServiceFactory, DaprComponentFactory) |
58+
| `health_checks.py` | `health/` | Health check strategies (HTTP, TCP, Command, Redis, Postgres, Dapr) |
59+
| `pydantic_models.py` | `models/` | Enhanced Pydantic models with validation |
60+
| `fixtures.py` | `testing/` | Pytest fixtures for testing |
61+
| `cli.py` | root | Command-line interface |
3262

3363
## Design Patterns
3464

.devcontainer/infrastructure/__init__.py

Lines changed: 16 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -6,15 +6,24 @@
66
- Abstraction: ABC for interface contracts
77
- Polymorphism: Multiple implementations of common interfaces
88
- Encapsulation: Internal state management
9+
10+
Directory Structure:
11+
- core/: Base classes and configuration
12+
- builders/: Dockerfile generation (Template Method pattern)
13+
- factories/: Component factories (Factory pattern)
14+
- health/: Health check strategies (Strategy pattern)
15+
- models/: Pydantic models for validation
16+
- testing/: Test fixtures and utilities
17+
- cli.py: Command-line interface
918
"""
1019

11-
from .base import (
20+
from .core.base import (
1221
Port,
1322
ContainerService,
1423
DatabaseService,
1524
MessageBrokerService,
1625
)
17-
from .health_checks import (
26+
from .health.health_checks import (
1827
HealthCheck,
1928
HttpHealthCheck,
2029
TcpHealthCheck,
@@ -23,30 +32,30 @@
2332
PostgresHealthCheck,
2433
DaprHealthCheck,
2534
)
26-
from .config import (
35+
from .core.config import (
2736
EnvironmentConfig,
2837
ServiceConfig,
2938
DockerComposeConfig,
3039
)
31-
from .pydantic_models import (
40+
from .models.pydantic_models import (
3241
EnvironmentConfigModel,
3342
ServiceConfigModel,
3443
DockerComposeConfigModel,
3544
PortModel,
3645
)
37-
from .factories import (
46+
from .factories.factories import (
3847
DaprComponentFactory,
3948
ServiceFactory,
4049
)
41-
from .dockerfile_builder import (
50+
from .builders.dockerfile_builder import (
4251
DockerfileBuilder,
4352
DevelopmentDockerfileBuilder,
4453
ProductionDockerfileBuilder,
4554
)
4655
from .cli import InfrastructureCLI
4756

4857
# Fixtures are imported separately in conftest.py
49-
# from .fixtures import *
58+
# from .testing.fixtures import *
5059

5160
__all__ = [
5261
# Base classes
File renamed without changes.

0 commit comments

Comments
 (0)