| # 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. |
|
|