mirror of
https://github.com/SamyRai/tercul-backend.git
synced 2025-12-27 04:01:34 +00:00
This commit introduces a new application layer to the codebase, which decouples the GraphQL resolvers from the data layer. The resolvers now call application services, which in turn call the repositories. This change improves the separation of concerns and makes the code more testable and maintainable. Additionally, this commit introduces dataloaders to solve the N+1 problem in the GraphQL resolvers. The dataloaders are used to batch and cache database queries, which significantly improves the performance of the API. The following changes were made: - Created application services for most of the domains. - Refactored the GraphQL resolvers to use the new application services. - Implemented dataloaders for the `Author` aggregate. - Updated the `app.Application` struct to hold the application services instead of the repositories. - Fixed a large number of compilation errors in the test files that arose from these changes. There are still some compilation errors in the `internal/adapters/graphql/integration_test.go` file. These errors are due to the test files still trying to access the repositories directly from the `app.Application` struct. The remaining work is to update these tests to use the new application services.
5.2 KiB
5.2 KiB
TODO List for Tercul Go Application
High Priority
[ ] Architecture Refactor (DDD-lite)
- [~] Resolvers call application services only; add dataloaders per aggregate (High, 3d)
- Status: Partially complete. Many resolvers still call repositories directly. Dataloaders are not implemented.
- Next Steps: Refactor remaining resolvers to use application services. Implement dataloaders to solve N+1 problems.
- Adopt migrations tool (goose/atlas/migrate); move SQL to
internal/data/migrations(High, 2d)- Status: Partially complete.
gooseis added as a dependency, but no migration files have been created. - Next Steps: Create initial migration files from the existing schema. Move all schema changes to new migration files.
- Status: Partially complete.
- Observability: centralize logging; add Prometheus metrics and OpenTelemetry tracing; request IDs (High, 3d)
- Status: Partially complete. OpenTelemetry and Prometheus libraries are added, but not integrated. The current logger is a simple custom implementation.
- Next Steps: Integrate OpenTelemetry for tracing. Add Prometheus metrics to the application. Implement a structured, centralized logging solution.
- CI: add
make lint test test-integrationand integration tests with Docker compose (High, 2d)- Status: Partially complete. CI runs tests and linting, and uses docker-compose to set up DB and Redis. No
Makefileexists. - Next Steps: Create a
Makefilewithlint,test, andtest-integrationtargets.
- Status: Partially complete. CI runs tests and linting, and uses docker-compose to set up DB and Redis. No
[ ] Features
- Implement analytics data collection (High, 3d)
- Status: Mostly complete. The analytics service is implemented with most of the required features.
- Next Steps: Review and complete any missing analytics features.
Medium Priority
[ ] Performance Improvements
- Implement batching for Weaviate operations (Medium, 2d)
- Add performance benchmarks for critical paths (Medium, 2d)
- Add benchmarks for text analysis (sequential vs concurrent) and cache hit/miss rates
[ ] Code Quality & Architecture
- Expand Weaviate client to support all models (Medium, 2d)
- Add code documentation and API docs (Medium, 2d)
- Replace bespoke cached repositories with decorators in
internal/data/cache(reads only; deterministic invalidation) (Medium, 2d) - Config: replace ad-hoc config with env parsing + validation (e.g., koanf/envconfig); no globals (Medium, 1d)
[ ] Testing
- Add performance benchmarks for critical paths (Medium, 2d)
- Add benchmarks for text analysis (sequential vs concurrent) and cache hit/miss rates
[ ] Monitoring & Logging
- Add monitoring for background jobs and API endpoints (Medium, 2d)
- Add metrics for linguistics: analysis duration, cache hit/miss, provider usage
Low Priority
[ ] Testing
- Refactor
RunTransactionalto be mock-friendly (Low, 1d)
Completed
- Add comprehensive input validation for all GraphQL mutations (High, 2d) - Partially complete. Core mutations are validated.
- Create skeleton packages:
cmd/,internal/platform/,internal/domain/,internal/app/,internal/data/,internal/adapters/graphql/,internal/jobs/ - Move infra to
internal/platform/*(config,db,cache,auth,http,log,search) - Wire DI in
cmd/api/main.goand expose anApplicationfacade to adapters - Unify GraphQL under
internal/adapters/graphqland updategqlgen.yml; moveschema.graphqlsand resolvers - Introduce Unit-of-Work:
platform/db.WithTx(ctx, func(ctx) error)and repo factory for*sql.DB/*sql.Tx - Split write vs read paths for
work(commands.go, queries.go); make read models cacheable - Restructure
models/*into domain aggregates with constructors and invariants - Security: move JWT/middleware to
internal/platform/auth; add authz policy helpers (e.g.,CanEditWork) - Search: move Weaviate client/schema to
internal/platform/search, optional domain interface - Background jobs: move to
cmd/workerandinternal/jobs/*; ensure idempotency and lease - Python ops: move scripts to
/ops/migrationand/ops/analysis; keep outputs under/ops/migration/outputs/ - Cleanup: delete dead packages (
store, duplicaterepositories); consolidate tointernal/data/sql - Add integration tests for GraphQL API and background jobs (High, 3d) - Partially complete. Core mutations are tested.
- Stabilize non-linguistics tests and interfaces (High, 2d)
- Fix
graphmocks to accept context in service interfaces - Update
repositoriestests (missingTestModel) and align with new repository interfaces - Update
servicestests to pass context and implement missing repo methods in mocks
- Fix
- Full Test Coverage (High, 5d):
- Write unit tests for all models, repositories, and services.
- Refactor existing tests to use mocks instead of a real database.
- Refactor domains to be more testable and decoupled, with 100% unit test coverage and logging.
localizationdomainauthdomaincopyrightdomainmonetizationdomainsearchdomainworkdomain
TODO items include context, priority, and estimated effort. Update this list after each milestone.