|
| 1 | +# Design and Principles |
| 2 | + |
| 3 | +- Simple python template I am experimenting with around a set of overlapping concepts with a Fastapi implementation: |
| 4 | + - Domain Driven Design (DDD) |
| 5 | + - Clean architecture |
| 6 | + - Ports & Adapters |
| 7 | + - Vertical slice |
| 8 | + |
| 9 | +## Core System Components |
| 10 | + |
| 11 | +- The main application logic is in app. |
| 12 | +- Feature flags and configuration settings are in config.py. |
| 13 | + |
| 14 | +## Code styles |
| 15 | + |
| 16 | +- Use PEP 8 and pythonic code |
| 17 | +- Use type hints |
| 18 | +- Functions: Use `snake_case` |
| 19 | +- Variables: Use `snake_case` |
| 20 | +- Constants: Use `UPPER_CASE` |
| 21 | +- Classes: Use `CamelCase` |
| 22 | +- Use `loguru` for logging |
| 23 | +- Use `pydantic` for data validation |
| 24 | +- Use `sqlmodel` for database interactions |
| 25 | +- Use `pydantic-settings` for configuration |
| 26 | +- Use `python-dotenv` for environment variables |
| 27 | +- Use `pytest` for testing |
| 28 | +- Use `pytest-cov` for coverage |
| 29 | +- Use `uv` for dependency management |
| 30 | + |
| 31 | +## Data & Storage |
| 32 | + |
| 33 | +- Support for Sqlite and Postgres via sqlmodel. |
| 34 | +- Use `atlas` for database migrations |
| 35 | +- Use `migrations` directory for migration files |
| 36 | +- Use Bytebase and Supabase style guides |
| 37 | +- Identifier Style: snake_case, lowercase, descriptive |
| 38 | +- Table Names: snake_case, plural, no prefixes, descriptive |
| 39 | +- Column Names: snake_case, singular, descriptive, avoid generic, with `_id` |
| 40 | +- Data Types: Prefer specific types, ENUM for small sets, avoid CHAR(n) |
| 41 | +- Query Formatting: Lowercase keywords, whitespace, clear indentation |
| 42 | +- Functions: Lowercase, snake_case |
| 43 | +- Constraints: Explicit, descriptive names |
| 44 | + |
| 45 | +## Testing & Debugging |
| 46 | + |
| 47 | +- Unit, component and integration tests in app/tests |
| 48 | +- Create unit and component tests first before writing the actual code |
| 49 | +- Follow code implementation with integration tests |
| 50 | + |
| 51 | +## Workflow and developer interaction |
| 52 | + |
| 53 | +- TBD |
| 54 | + |
| 55 | +## Bash commands |
| 56 | + |
| 57 | +- Running api server: |
| 58 | + |
| 59 | +```bash |
| 60 | +uv run fastapi dev main.py |
| 61 | +``` |
| 62 | + |
| 63 | +- Running tests: |
| 64 | + |
| 65 | +```bash |
| 66 | +uv run pytest |
| 67 | +``` |
| 68 | + |
| 69 | +- Running database and migrations: |
| 70 | + |
| 71 | +```bash |
| 72 | +docker compose up |
| 73 | +docker compose down -v |
| 74 | +``` |
| 75 | + |
| 76 | +- Various migration commands depending on database type: |
| 77 | + |
| 78 | +```bash |
| 79 | +atlas schema inspect -u "sqlite://file?cache=shared&mode=memory" --format "{{ sql . }}" |
| 80 | +atlas schema inspect -u "sqlite://issues.db" --format "{{ sql . }}" > migrate.sql |
| 81 | +atlas schema inspect -u "postgres://app_user:change_this_password@localhost:5432/app_database?sslmode=disable" --schema "issue_analysis" --format "{{ sql . }}" |
| 82 | + |
| 83 | +atlas schema apply --url "sqlite://issues.db" --to "file://migrate.sql" --dev-url "sqlite://file?mode=memory" --dry-run |
| 84 | +atlas schema apply --url "sqlite://issues.db" --to "file://migrate.sql" --dev-url "sqlite://file?mode=memory" |
| 85 | + |
| 86 | +atlas schema apply --url "postgres://app_user:change_this_password@localhost:5432/app_database?sslmode=disable" --to "file://./migrations/migrate.sql" --dev-url "docker://postgres/17" --dry-run |
| 87 | +atlas schema apply --url "postgres://app_user:change_this_password@localhost:5432/app_database?sslmode=disable" --to "file://./migrations/migrate.sql" --dev-url "docker://postgres/17" |
| 88 | +``` |
0 commit comments