How shikihtm/blog-backend works
This is a Go backend for a personal blog: it serves MDX-authored posts and stores engagement counters in SQLite. The main workflow starts with HTTP requests routed to post handlers, which retrieve metadata/content or update counters through the repository; post creation writes MDX files. A separate startup-and-watch workflow syncs post metadata into SQLite. Authentication supports login and protects post creation. The README documents view/like endpoints; the sampled route registration does not show those routes, so that connection is documented rather than inferred from handler code.
Main entry points: main.go API startup · post_hanlder.go Post handlers · repository.go Blog repository · mdx_watcher.go Post sync watcher
Components 14
Service runtime
- API startup
cmd/api/main.go - Domain models
internal/model/post.go
HTTP and auth
- Post handlers
internal/handler/post/post_hanlder.go - Login handler
internal/handler/auth/authentication.go - Auth config
internal/handler/auth/config.go - Cookie auth
middleware/authentication.go
Post content
- MDX posts
posts/tai-sao-nhan-doi-mang.mdx - Post sync watcher
internal/repository/mdx_watcher.go - MDX reader
internal/repository/mdx.go
Persistence
- Blog repository
internal/repository/repository.go - Post metadata sync
internal/repository/post-repository.go - SQLite bootstrap
internal/database/sqlite.go - SQLite store
Other components
- Blog client
Connections 21
- Blog client → API startup: sends HTTP requests
README.md - API startup → SQLite bootstrap: initializes
cmd/api/main.go - API startup → Auth config: loads config
cmd/api/main.go - API startup → Blog repository: constructs repository
cmd/api/main.go - API startup → Post handlers: registers routes
cmd/api/main.go - API startup → Login handler: registers routes
cmd/api/main.go - API startup → Post sync watcher: starts sync and watch
cmd/api/main.go - SQLite bootstrap → SQLite store: creates schema
internal/database/sqlite.go - Blog repository → SQLite store: queries and updates
internal/repository/repository.go - Post handlers → Blog repository: requests post operations
internal/handler/post/post_hanlder.go - Post handlers → Cookie auth: protects creation route
internal/handler/post/post_hanlder.go - Post handlers → MDX posts: writes created post
internal/handler/post/post_hanlder.go - Login handler → Domain models: uses user and claims
internal/handler/auth/authentication.go - Cookie auth → Domain models: parses JWT claims
middleware/authentication.go - Blog repository → MDX reader: reads metadata and body
internal/repository/repository.go - MDX reader → MDX posts: reads and parses
internal/repository/mdx.go - Post sync watcher → Post metadata sync: syncs changed slugs
internal/repository/mdx_watcher.go - Post metadata sync → MDX reader: reads post metadata
internal/repository/post-repository.go - Post metadata sync → SQLite store: upserts stats
internal/repository/post-repository.go - Post sync watcher → MDX posts: monitors directory
internal/repository/mdx_watcher.go - Post handlers → Blog repository: increments views and likes
README.md