-
Notifications
You must be signed in to change notification settings - Fork 0
Architecture Overview
Gary Norman edited this page Oct 7, 2025
·
2 revisions
Codex follows a clean architecture pattern with clear separation of concerns.
codex/
├── cmd/server/ # Application entry point
│ ├── main.go # Server initialization, CLI
│ ├── migrations.go # Database migrations
│ └── seed.go # Database seeding
├── internal/
│ ├── app/ # App initialization & config
│ ├── db/ # Database connection
│ ├── dao/ # Generic data access layer
│ ├── sqlite/ # SQLite implementations
│ ├── models/ # Data models
│ ├── service/ # Business logic
│ ├── http/
│ │ ├── handlers/ # HTTP handlers
│ │ ├── middleware/ # Middleware (auth, logging)
│ │ └── routes/ # Router & DI registry
│ └── view/ # Template rendering
├── migrations/ # SQL schema files
├── assets/ # Static files (CSS, JS, icons)
└── scripts/ # Build & deployment scripts
The application uses manual dependency injection via internal/http/routes/registry.go:
- Create flat handlers (Session, Reaction, Auth)
- Create handlers with single-level deps (Comment, Channel)
- Create complex handlers (User, Post, Home)
- Wire into RouteHandler struct
All database operations use a generic DAO with type safety:
type DAO[T models.DBModel] struct {
// Generic CRUD operations
}Provides: All(), GetByID(), Insert(), Update(), Delete()
All models implement the DBModel interface:
type DBModel interface {
TableName() string
}Struct fields use db tags for column mapping.
- Templates parsed once at startup
-
TempHelperprovides access to App instance - Custom template functions for common operations
- Composed from partials (
.tmplfiles)
- Session tokens stored in cookies
-
authmiddleware extracts user - Context injection via
WithUsermiddleware - Handlers access user from
r.Context()
Uses enhanced servemux with method-based routing:
POST /register
GET /post/{postId}Core entities:
- Users - User accounts and authentication
- Posts - Forum posts
- Comments - Threaded discussions
- Reactions - Likes/dislikes
- Channels - Topic organization
- Memberships - User-channel relationships
- Flags - Content moderation
- Loyalty - User engagement tracking
- Saved - Bookmarked posts
- Mods - Channel moderators
- Rules - Channel guidelines
- Images - Media uploads
- MutedChannels - Hidden channels
- Backend: Go 1.22+
-
Database: SQLite3 (
github.com/mattn/go-sqlite3) - Routing: Standard library enhanced servemux
-
Templates: Go
html/template - Frontend: Vanilla JavaScript, CSS, HTML
- Build: Make
- Containerization: Docker
Environment variables loaded from .env:
DB_ENV=dev
DB_PATH=./identifier.sqlite- Database indexes for common queries
- Template caching
- Static file serving
- Connection pooling
- Graceful shutdown (10s timeout)
- pprof server on
localhost:6060 - Colored console output (Catppuccin Mocha)
- Interactive build menu
- Automatic migrations