AI规范准则生成 README.md初始化

This commit is contained in:
2025-11-10 15:48:47 +08:00
parent eb8a759d4d
commit 2413baf945
5 changed files with 456 additions and 60 deletions

View File

@@ -31,7 +31,44 @@
*GATE: Must pass before Phase 0 research. Re-check after Phase 1 design.*
[Gates determined based on constitution file]
**Tech Stack Adherence**:
- [ ] Feature uses Fiber + GORM + Viper + Zap + Lumberjack.v2 + Validator + sonic JSON + Asynq + PostgreSQL
- [ ] No native calls bypass framework (no `database/sql`, `net/http`, `encoding/json` direct use)
- [ ] All HTTP operations use Fiber framework
- [ ] All database operations use GORM
- [ ] All async tasks use Asynq
**Code Quality Standards**:
- [ ] Follows Handler → Service → Store → Model architecture
- [ ] Handler layer only handles HTTP, no business logic
- [ ] Service layer contains business logic with cross-module support
- [ ] Store layer manages all data access with transaction support
- [ ] Uses dependency injection via Service/Store structs
- [ ] Unified error codes in `pkg/errors/`
- [ ] Unified API responses via `pkg/response/`
**Testing Standards**:
- [ ] Unit tests for all core business logic (Service layer)
- [ ] Integration tests for all API endpoints
- [ ] Tests use Go standard testing framework
- [ ] Tests are independent (no external service dependencies)
- [ ] Target coverage: 70%+ overall, 90%+ for core business
**User Experience Consistency**:
- [ ] All APIs use unified JSON response format
- [ ] Error responses include clear error codes and bilingual messages
- [ ] RESTful design principles followed
- [ ] Unified pagination parameters (page, page_size, total)
- [ ] Time fields use ISO 8601 format (RFC3339)
- [ ] Currency amounts use integers (cents) to avoid float precision issues
**Performance Requirements**:
- [ ] API response time (P95) < 200ms, (P99) < 500ms
- [ ] Batch operations use bulk queries/inserts
- [ ] All database queries have appropriate indexes
- [ ] List queries implement pagination (default 20, max 100)
- [ ] Non-realtime operations use async tasks
- [ ] Database and Redis connection pools properly configured
## Project Structure

View File

@@ -95,6 +95,43 @@
- **FR-006**: System MUST authenticate users via [NEEDS CLARIFICATION: auth method not specified - email/password, SSO, OAuth?]
- **FR-007**: System MUST retain user data for [NEEDS CLARIFICATION: retention period not specified]
### Technical Requirements (Constitution-Driven)
**Tech Stack Compliance**:
- [ ] All HTTP operations use Fiber framework (no `net/http` shortcuts)
- [ ] All database operations use GORM (no `database/sql` direct calls)
- [ ] All JSON operations use sonic (no `encoding/json` usage)
- [ ] All async tasks use Asynq
- [ ] All logging uses Zap + Lumberjack.v2
- [ ] All configuration uses Viper
**Architecture Requirements**:
- [ ] Implementation follows Handler → Service → Store → Model layers
- [ ] Dependencies injected via Service/Store structs
- [ ] Unified error codes defined in `pkg/errors/`
- [ ] Unified API responses via `pkg/response/`
**API Design Requirements**:
- [ ] All APIs follow RESTful principles
- [ ] All responses use unified JSON format with code/message/data/timestamp
- [ ] All error messages include error codes and bilingual descriptions
- [ ] All pagination uses standard parameters (page, page_size, total)
- [ ] All time fields use ISO 8601 format (RFC3339)
- [ ] All currency amounts use integers (cents)
**Performance Requirements**:
- [ ] API response time (P95) < 200ms
- [ ] Database queries < 50ms
- [ ] Batch operations use bulk queries
- [ ] List queries implement pagination (default 20, max 100)
- [ ] Non-realtime operations delegated to async tasks
**Testing Requirements**:
- [ ] Unit tests for all Service layer business logic
- [ ] Integration tests for all API endpoints
- [ ] Tests are independent and use mocks/testcontainers
- [ ] Target coverage: 70%+ overall, 90%+ for core business logic
### Key Entities *(include if feature involves data)*
- **[Entity 1]**: [What it represents, key attributes without implementation]

View File

@@ -48,9 +48,11 @@ description: "Task list template for feature implementation"
**Purpose**: Project initialization and basic structure
- [ ] T001 Create project structure per implementation plan
- [ ] T002 Initialize [language] project with [framework] dependencies
- [ ] T003 [P] Configure linting and formatting tools
- [ ] T001 Create project structure per implementation plan (internal/, pkg/, cmd/)
- [ ] T002 Initialize Go project with Fiber + GORM + Viper + Zap + Asynq dependencies
- [ ] T003 [P] Configure linting (golangci-lint) and formatting tools (gofmt/goimports)
- [ ] T004 [P] Setup unified error codes in pkg/errors/
- [ ] T005 [P] Setup unified API response in pkg/response/
---
@@ -60,14 +62,20 @@ description: "Task list template for feature implementation"
**⚠️ CRITICAL**: No user story work can begin until this phase is complete
Examples of foundational tasks (adjust based on your project):
Foundational tasks for 君鸿卡管系统 tech stack:
- [ ] T004 Setup database schema and migrations framework
- [ ] T005 [P] Implement authentication/authorization framework
- [ ] T006 [P] Setup API routing and middleware structure
- [ ] T007 Create base models/entities that all stories depend on
- [ ] T008 Configure error handling and logging infrastructure
- [ ] T009 Setup environment configuration management
- [ ] T006 Setup PostgreSQL database connection via GORM with connection pool (MaxOpenConns=25, MaxIdleConns=10)
- [ ] T007 Setup Redis connection with connection pool (PoolSize=10, MinIdleConns=5)
- [ ] T008 [P] Setup database migrations framework (golang-migrate or GORM AutoMigrate)
- [ ] T009 [P] Implement Fiber routing structure in internal/router/
- [ ] T010 [P] Implement Fiber middleware (authentication, logging, recovery, validation) in internal/handler/middleware/
- [ ] T011 [P] Setup Zap logger with Lumberjack rotation in pkg/logger/
- [ ] T012 [P] Setup Viper configuration management in pkg/config/
- [ ] T013 [P] Setup Asynq task queue client and server in pkg/queue/
- [ ] T014 [P] Setup Validator integration in pkg/validator/
- [ ] T015 Create base Store structure with transaction support in internal/store/
- [ ] T016 Create base Service structure with dependency injection in internal/service/
- [ ] T017 Setup sonic JSON as default serializer for Fiber
**Checkpoint**: Foundation ready - user story implementation can now begin in parallel
@@ -79,21 +87,28 @@ Examples of foundational tasks (adjust based on your project):
**Independent Test**: [How to verify this story works on its own]
### Tests for User Story 1 (OPTIONAL - only if tests requested) ⚠️
### Tests for User Story 1 (REQUIRED per Constitution - Testing Standards) ⚠️
> **NOTE: Write these tests FIRST, ensure they FAIL before implementation**
- [ ] T010 [P] [US1] Contract test for [endpoint] in tests/contract/test_[name].py
- [ ] T011 [P] [US1] Integration test for [user journey] in tests/integration/test_[name].py
- [ ] T020 [P] [US1] Unit tests for Service layer business logic in internal/service/[service]_test.go
- [ ] T021 [P] [US1] Integration tests for API endpoints in internal/handler/[handler]_test.go
- [ ] T022 [P] [US1] Transaction rollback tests for Store layer in internal/store/[store]_test.go
### Implementation for User Story 1
- [ ] T012 [P] [US1] Create [Entity1] model in src/models/[entity1].py
- [ ] T013 [P] [US1] Create [Entity2] model in src/models/[entity2].py
- [ ] T014 [US1] Implement [Service] in src/services/[service].py (depends on T012, T013)
- [ ] T015 [US1] Implement [endpoint/feature] in src/[location]/[file].py
- [ ] T016 [US1] Add validation and error handling
- [ ] T017 [US1] Add logging for user story 1 operations
- [ ] T023 [P] [US1] Create [Entity1] model with GORM tags in internal/model/[entity1].go
- [ ] T024 [P] [US1] Create [Entity2] model with GORM tags in internal/model/[entity2].go
- [ ] T025 [P] [US1] Create DTOs and request/response structs in internal/model/dto/[feature].go
- [ ] T026 [US1] Implement Store methods with GORM in internal/store/postgres/[store].go (depends on T023, T024)
- [ ] T027 [US1] Implement Service business logic in internal/service/[service].go (depends on T026)
- [ ] T028 [US1] Implement Fiber Handler in internal/handler/[handler].go (depends on T027)
- [ ] T029 [US1] Register routes in internal/router/router.go
- [ ] T030 [US1] Add validation rules using Validator in Handler
- [ ] T031 [US1] Add unified error handling using pkg/errors/ and pkg/response/
- [ ] T032 [US1] Add Zap logging with structured fields
- [ ] T033 [US1] Add database indexes for queries (if needed)
- [ ] T034 [US1] Create Asynq tasks for async operations (if needed) in internal/task/[task].go
**Checkpoint**: At this point, User Story 1 should be fully functional and testable independently
@@ -146,16 +161,24 @@ Examples of foundational tasks (adjust based on your project):
---
## Phase N: Polish & Cross-Cutting Concerns
## Phase N: Polish & Quality Gates
**Purpose**: Improvements that affect multiple user stories
**Purpose**: Improvements that affect multiple user stories and final quality checks
- [ ] TXXX [P] Documentation updates in docs/
- [ ] TXXX Code cleanup and refactoring
- [ ] TXXX Performance optimization across all stories
- [ ] TXXX [P] Additional unit tests (if requested) in tests/unit/
- [ ] TXXX Security hardening
- [ ] TXXX Performance optimization and load testing (verify P95 < 200ms, P99 < 500ms)
- [ ] TXXX [P] Additional unit tests to reach 70%+ coverage (90%+ for core business)
- [ ] TXXX Security audit (SQL injection, XSS, command injection prevention)
- [ ] TXXX Run quickstart.md validation
- [ ] TXXX Quality Gate: Run `go test ./...` (all tests pass)
- [ ] TXXX Quality Gate: Run `gofmt -l .` (no formatting issues)
- [ ] TXXX Quality Gate: Run `go vet ./...` (no issues)
- [ ] TXXX Quality Gate: Run `golangci-lint run` (no issues)
- [ ] TXXX Quality Gate: Verify test coverage with `go test -cover ./...`
- [ ] TXXX Quality Gate: Check no TODO/FIXME remains (or documented in issues)
- [ ] TXXX Quality Gate: Verify database migrations work correctly
- [ ] TXXX Quality Gate: Verify API documentation updated (if API changes)
---