File size: 3,920 Bytes
4aec5bd | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 | # 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.
|