ai-dev-template-backup / docs /ARCHITECTURE.md
Jordandevlog's picture
Duplicate from Jordandevlog/ai-dev-template
4aec5bd
|
Raw
History Blame Contribute Delete
3.92 kB
# Architecture Design
> **AI Context**: This document defines WHERE files go and WHAT each file does. Follow this structure exactly.
## Directory Tree
```
src/
β”œβ”€β”€ core/
β”‚ β”œβ”€β”€ __init__.py
β”‚ β”œβ”€β”€ models.py # Data models / ORM definitions
β”‚ β”œβ”€β”€ database.py # DB connection, sessions, migrations
β”‚ └── config.py # Settings, environment variables (pydantic-settings)
β”œβ”€β”€ api/
β”‚ β”œβ”€β”€ __init__.py
β”‚ β”œβ”€β”€ routes.py # HTTP endpoint definitions
β”‚ β”œβ”€β”€ schemas.py # Pydantic request/response models
β”‚ └── dependencies.py # FastAPI/Flask dependency injection (auth, DB)
β”œβ”€β”€ services/
β”‚ β”œβ”€β”€ __init__.py
β”‚ β”œβ”€β”€ [feature]_service.py # Business logic (one per major feature)
β”‚ └── email_service.py # External integrations
β”œβ”€β”€ utils/
β”‚ β”œβ”€β”€ __init__.py
β”‚ β”œβ”€β”€ validators.py # Input validation helpers
β”‚ β”œβ”€β”€ exceptions.py # Custom exception classes
β”‚ └── logger.py # Logging configuration
└── main.py # Application entry point
tests/
β”œβ”€β”€ conftest.py # pytest fixtures, shared setup
β”œβ”€β”€ unit/ # Unit tests (isolated, fast)
β”‚ β”œβ”€β”€ test_models.py
β”‚ β”œβ”€β”€ test_validators.py
β”‚ └── test_services.py
β”œβ”€β”€ integration/ # Integration tests (DB, external APIs)
β”‚ β”œβ”€β”€ test_api.py
β”‚ └── test_database.py
└── e2e/ # End-to-end tests (full flow)
└── test_[feature].py
docs/
β”œβ”€β”€ PRD.md # Requirements (SOURCE OF TRUTH)
β”œβ”€β”€ ARCHITECTURE.md # This file (FILE MAP)
β”œβ”€β”€ CONTEXT.md # Coding standards
└── decisions/ # Architecture Decision Records (ADRs)
└── 001-use-fastapi.md
agents/
β”œβ”€β”€ smolagent_runner.py # Python agent with local Ollama
└── multiagent_workflow.py # Multi-agent orchestration
scripts/
β”œβ”€β”€ setup.sh # One-command project setup
β”œβ”€β”€ start-ollama.sh # Start optimized local Ollama server
└── lint.sh # Run all linters and formatters
```
## File Responsibilities
| File | Responsibility | Key Classes/Functions | Dependencies |
|------|---------------|----------------------|--------------|
| `core/config.py` | Environment config, secrets | `Settings` (pydantic) | `pydantic-settings` |
| `core/models.py` | ORM models | `User`, `Post` | SQLAlchemy/Pydantic |
| `core/database.py` | DB engine, sessions | `get_db()`, `Base`, `engine` | `core/models` |
| `api/schemas.py` | API I/O models | `UserCreate`, `UserResponse` | Pydantic |
| `api/dependencies.py` | Dependency injection | `get_current_user()`, `get_db()` | `core/database` |
| `api/routes.py` | HTTP handlers | `create_user()`, `get_posts()` | `services/`, `schemas/` |
| `services/*_service.py` | Business logic | `create_user()`, `send_email()` | `core/models`, external APIs |
| `utils/validators.py` | Validation | `validate_email()`, `validate_password()` | regex, stdlib |
| `utils/exceptions.py` | Custom errors | `ValidationError`, `NotFoundError` | stdlib |
| `utils/logger.py` | Logging setup | `get_logger()` | `logging` module |
| `main.py` | App factory | `create_app()` | Everything |
## Data Flow
```
[Client] β†’ [Routes] β†’ [Dependencies] β†’ [Services] β†’ [Models/DB]
↓ ↓
[Schemas] [External APIs]
↓
[Validators]
```
## Module Dependencies
- `api` depends on: `services`, `core`, `utils`
- `services` depends on: `core`, `utils`
- `core` depends on: `utils` (exceptions, validators)
- `utils` depends on: NOTHING (stdlib only)
- **Rule**: No circular dependencies. `utils` is the leaf. `api` is the root.