mirror of
https://github.com/TracksApp/tracks.git
synced 2026-02-02 14:11:46 +01:00
Rewrite Tracks application in Golang
This commit introduces a complete rewrite of the Tracks GTD application in Go (Golang), providing a modern, performant alternative to the Ruby on Rails implementation. ## Architecture & Technology Stack - Language: Go 1.21+ - Web Framework: Gin - ORM: GORM with SQLite/MySQL/PostgreSQL support - Authentication: JWT with bcrypt password hashing - Clean Architecture: Separated models, services, handlers, and middleware ## Implemented Features ### Core Models - User: Authentication and user management - Context: GTD contexts (@home, @work, etc.) - Project: Project grouping and tracking - Todo: Task management with state machine (active, completed, deferred, pending) - Tag: Flexible tagging system with polymorphic associations - Dependency: Todo dependencies with circular dependency detection - Preference: User preferences and settings - Note: Project notes - Attachment: File attachment support (model only) - RecurringTodo: Recurring task template (model only) ### API Endpoints **Authentication:** - POST /api/auth/login - User login - POST /api/auth/register - User registration - POST /api/auth/logout - User logout - GET /api/me - Get current user **Todos:** - GET /api/todos - List todos with filtering - POST /api/todos - Create todo - GET /api/todos/:id - Get todo details - PUT /api/todos/:id - Update todo - DELETE /api/todos/:id - Delete todo - POST /api/todos/:id/complete - Mark as completed - POST /api/todos/:id/activate - Mark as active - POST /api/todos/:id/defer - Defer to future date - POST /api/todos/:id/dependencies - Add dependency - DELETE /api/todos/:id/dependencies/:successor_id - Remove dependency **Projects:** - GET /api/projects - List projects - POST /api/projects - Create project - GET /api/projects/:id - Get project details - PUT /api/projects/:id - Update project - DELETE /api/projects/:id - Delete project - POST /api/projects/:id/complete - Complete project - POST /api/projects/:id/activate - Activate project - POST /api/projects/:id/hide - Hide project - POST /api/projects/:id/review - Mark as reviewed - GET /api/projects/:id/stats - Get project statistics **Contexts:** - GET /api/contexts - List contexts - POST /api/contexts - Create context - GET /api/contexts/:id - Get context details - PUT /api/contexts/:id - Update context - DELETE /api/contexts/:id - Delete context - POST /api/contexts/:id/hide - Hide context - POST /api/contexts/:id/activate - Activate context - POST /api/contexts/:id/close - Close context - GET /api/contexts/:id/stats - Get context statistics ### Business Logic **Todo State Management:** - Active: Ready to work on - Completed: Finished tasks - Deferred: Future actions (show_from date) - Pending: Blocked by dependencies **Dependency Management:** - Create blocking relationships between todos - Automatic state transitions when blocking todos complete - Circular dependency detection - Automatic unblocking when prerequisites complete **Tag System:** - Polymorphic tagging for todos and recurring todos - Automatic tag creation on first use - Tag cloud support **Project & Context Tracking:** - State management (active, hidden, closed/completed) - Statistics and health indicators - Review tracking for projects ### Infrastructure **Configuration:** - Environment-based configuration - Support for SQLite, MySQL, and PostgreSQL - Configurable JWT secrets and token expiry - Flexible server settings **Database:** - GORM for ORM - Automatic migrations - Connection pooling - Multi-database support **Authentication & Security:** - JWT-based authentication - Bcrypt password hashing - Secure cookie support - Token refresh mechanism **Docker Support:** - Multi-stage Dockerfile for optimized builds - Docker Compose with PostgreSQL - Volume mounting for data persistence - Production-ready configuration ## Project Structure ``` cmd/tracks/ # Application entry point internal/ config/ # Configuration management database/ # Database setup and migrations handlers/ # HTTP request handlers middleware/ # Authentication middleware models/ # Database models services/ # Business logic layer ``` ## Documentation - README_GOLANG.md: Comprehensive documentation - .env.example: Configuration template - API documentation included in README - Code comments for complex logic ## Future Work The following features from the original Rails app are not yet implemented: - Recurring todo instantiation logic - Email integration (Mailgun/CloudMailin) - Advanced statistics and analytics - Import/Export functionality (CSV, YAML, XML) - File upload handling for attachments - Mobile views - RSS/Atom feeds - iCalendar export ## Benefits Over Rails Version - Performance: Compiled binary, lower resource usage - Deployment: Single binary, no runtime dependencies - Type Safety: Compile-time type checking - Concurrency: Better handling of concurrent requests - Memory: Lower memory footprint - Portability: Easy cross-platform compilation ## Testing The code structure supports testing, though tests are not yet implemented. Future work includes adding unit and integration tests.
This commit is contained in:
parent
6613d33f10
commit
f0eb4bdef5
29 changed files with 4100 additions and 104 deletions
89
Dockerfile
89
Dockerfile
|
|
@ -1,66 +1,49 @@
|
|||
ARG RUBY_VERSION=3.3
|
||||
FROM ruby:${RUBY_VERSION} AS base
|
||||
# Build stage
|
||||
FROM golang:1.21-alpine AS builder
|
||||
|
||||
# Install build dependencies
|
||||
RUN apk add --no-cache git gcc musl-dev sqlite-dev
|
||||
|
||||
# Set working directory
|
||||
WORKDIR /app
|
||||
RUN touch /etc/app-env
|
||||
|
||||
RUN apt-get update && apt-get install -y npm netcat-openbsd
|
||||
RUN npm install -g yarn
|
||||
RUN gem install bundler
|
||||
# Copy go mod files
|
||||
COPY go.mod go.sum ./
|
||||
|
||||
RUN mkdir /app/log
|
||||
# Download dependencies
|
||||
RUN go mod download
|
||||
|
||||
COPY COPYING /app/
|
||||
COPY config /app/config/
|
||||
COPY config/database.docker.yml /app/config/database.yml
|
||||
COPY config/site.docker.yml /app/config/site.yml
|
||||
# Copy source code
|
||||
COPY . .
|
||||
|
||||
COPY bin /app/bin/
|
||||
COPY script /app/script/
|
||||
COPY public /app/public/
|
||||
COPY vendor /app/vendor/
|
||||
# Build the application
|
||||
RUN CGO_ENABLED=1 GOOS=linux go build -a -installsuffix cgo -o tracks ./cmd/tracks
|
||||
|
||||
COPY .yardopts /app/
|
||||
COPY Rakefile /app/
|
||||
COPY config.ru /app/
|
||||
COPY docker-entrypoint.sh /app/
|
||||
# Runtime stage
|
||||
FROM alpine:latest
|
||||
|
||||
COPY lib /app/lib/
|
||||
COPY app /app/app/
|
||||
COPY db /app/db/
|
||||
# Install runtime dependencies
|
||||
RUN apk --no-cache add ca-certificates sqlite-libs
|
||||
|
||||
# Use glob to omit error if the .git directory doesn't exists (in case the
|
||||
# code is from a release archive, not a Git clone)
|
||||
COPY .gi[t] /app/.git
|
||||
# Create app user
|
||||
RUN addgroup -g 1000 tracks && \
|
||||
adduser -D -u 1000 -G tracks tracks
|
||||
|
||||
COPY Gemfile* /app/
|
||||
# Set working directory
|
||||
WORKDIR /app
|
||||
|
||||
ENTRYPOINT ["/app/docker-entrypoint.sh"]
|
||||
# Copy binary from builder
|
||||
COPY --from=builder /app/tracks .
|
||||
|
||||
# Create data directory
|
||||
RUN mkdir -p /app/data /app/uploads && \
|
||||
chown -R tracks:tracks /app
|
||||
|
||||
# Switch to non-root user
|
||||
USER tracks
|
||||
|
||||
# Expose port
|
||||
EXPOSE 3000
|
||||
CMD ["./bin/rails", "server", "-b", "0.0.0.0"]
|
||||
|
||||
FROM base AS precompile
|
||||
RUN bundle config set deployment true
|
||||
RUN bundle install --jobs 4
|
||||
RUN RAILS_GROUPS=assets bundle exec rake assets:precompile
|
||||
|
||||
# Build the environment-specific stuff
|
||||
FROM base AS production
|
||||
RUN bundle config set without assets
|
||||
RUN bundle config --global frozen 1
|
||||
RUN bundle install --jobs 4
|
||||
COPY --from=precompile /app/public/assets /app/public/assets
|
||||
|
||||
FROM base AS test
|
||||
COPY test /app/test/
|
||||
# For testing the API client
|
||||
COPY doc /app/doc/
|
||||
RUN bundle config set without assets
|
||||
RUN bundle config set with development test
|
||||
RUN bundle config --global frozen 1
|
||||
RUN bundle install --jobs 4
|
||||
COPY --from=precompile /app/public/assets /app/public/assets
|
||||
|
||||
FROM base AS development
|
||||
RUN bundle config set with development test
|
||||
RUN bundle install --jobs 4
|
||||
# Run the application
|
||||
CMD ["./tracks"]
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue