How nycu-sdc/cli-forum works
Project Type and Purpose
• CLI-Forum is a full-stack, two-component system comprised of:
a. A command-line interface client (“cli/”) for end users to interact with the forum.
b. A Go-based RESTful API backend (“backend/”) that manages users, posts, and comments and provides authentication, authorization, and observability.
• The backend uses OpenTelemetry (via Vector and Tempo) for logging, metrics, and traces.
File Structure
• Top-level components:
• .github/ – CI/CD workflows for building, testing, and linting.
• backend/ – Go REST API server, internal business logic, database migrations, OpenAPI spec, observability configs.
• cli/ – Go-based CLI client that calls the backend API.
• backend/internal/ contains layered subpackages:
• auth, jwt – authentication and JWT middleware.
• user, post, comment – domain logic with models, SQL queries (via sqlc), service and handler layers.
• database – migration scripts and full schema builder.
• middleware.go, logger.go, validator.go – cross-cutting concerns.
• observe/ – Docker-Compose file orchestrating Vector (logs), Tempo (traces), etc.
• Configuration files: config.yaml, openapi.yaml, sqlc.yaml, Dockerfiles, Makefiles.
README Insights
• RESTful API endpoints for user auth, post and comment CRUD.
• CLI uses those endpoints over HTTP.
• Observability integration for logging/tracing.
• Best practices, experimentation, and learning.
Components
a. CLI Application
• Shows: cli/main.go invokes HTTP calls
b. API Gateway / Backend Service
• HTTP Server (OpenAPI-generated router)
• Middleware chain: Logger → Auth/JWT → Validator → Error Handler
• Domain Services: UserService, PostService, CommentService
• Database Layer: sqlc-generated stores, migrations
c. Database
• Contains: user, post, comment tables (migrations in backend/internal/database/migrations/)
d. Observability Stack
• Sub-components: Vector (logs), Tempo (traces) configured by backend/observe/
e. External Systems (if any)
• E.g., Docker daemon, CI/CD pipeline (.github) – optional high-level note
Architectural Patterns and Design Principles
• Layered architecture in backend/internal/:
• Transport (handlers) → Service → Store → Database
• Separation of concerns: middleware, business logic, data access
• Configuration-as-code: YAML for OpenAPI, sqlc, Docker-Compose, app config
• Test coverage: handler tests in internal/post and internal/comment