Skip to content
This repository was archived by the owner on Sep 18, 2026. It is now read-only.

Latest commit

 

History

1 Commit

Folders and files

Repository files navigation

Accounts Backend Practice Run

A Go-based HTTP service for managing accounts and todos, built as a practice run project with various TODOs to be implemented.

Project Overview

This is a backend service that demonstrates a typical Go web application structure with authentication, database integration, and RESTful API design. The repository contains a skeleton for an API of Todos application.

Architecture

The project follows a clean architecture pattern with the following structure:

  • cmd/: CLI commands and HTTP server setup
  • internal/app/: Application initialization and routing
  • internal/config/: Configuration management
  • internal/controllers/: HTTP handlers
  • internal/model/: Data models and business logic
  • database/: Database schema and migrations

Features

Current Implementation

  • ✅ HTTP server with graceful shutdown
  • ✅ Status endpoint for health checks
  • ✅ Panic recovery middleware
  • ✅ Request logging middleware
  • ✅ Configuration management with environment variables
  • ✅ Docker support with MySQL database
  • ✅ Access token model structure

Technology Stack

  • Language: Go 1.24.4
  • Web Framework: Gorilla Mux
  • CLI Framework: Cobra
  • Database: MySQL 8.0.39
  • Containerization: Docker & Docker Compose
  • Logging: Structured logging with slog

Dependencies

github.com/gorilla/mux v1.8.1
github.com/spf13/cobra v1.10.1
github.com/spf13/pflag v1.0.9

Getting Started

Prerequisites

  • Go 1.24.4 or later
  • Docker and Docker Compose
  • Make (optional, for using Makefile commands)

Setup

  1. Clone the repository

    git clone <repository-url>
    cd accounts-backend-practice-run
  2. Start the database

    make prepare

    This will start a MySQL container with the required configuration.

  3. Run database migrations (after implementing schema)

    make migrate
  4. Start the application

    make run

    The server will start on port 8080 (default) or the port specified in the PORT environment variable.

Manual Setup

If you prefer not to use Make:

# Start MySQL container
docker compose -p acc up -d mysql --wait

# Run the application
go run . public

Configuration

The application uses environment variables for configuration:

  • PORT: HTTP server port (default: 8080)
  • MYSQLDSN: MySQL connection string (format: mysql://user:password@host:port/database)

API Endpoints

Current Endpoints

  • GET /status - Health check endpoint

Planned Endpoints (to be implemented)

  • POST /todos - Create a new todo
  • GET /todos - List all todos
  • GET /todos/{id} - Get a specific todo
  • PUT /todos/{id} - Update a todo
  • DELETE /todos/{id} - Delete a todo

Development

Project Structure

.
├── cmd/                          # CLI commands
│   ├── public_http.go           # HTTP server command
│   └── root.go                  # Root command setup
├── internal/
│   ├── app/
│   │   ├── app.go              # Application initialization
│   │   └── router.go           # Route setup (TODO: add todo routes)
│   ├── config/
│   │   └── config.go           # Configuration management
│   ├── controllers/
│   │   ├── common.go           # Common controller utilities
│   │   ├── status.go           # Status controller
│   │   └── middlewares/
│   │       ├── panic_recover.go # Panic recovery middleware
│   │       ├── request_logger.go # Request logging middleware
│   │       └── token.go        # Token authentication (TODO)
│   └── model/
│       ├── access_token.go     # Access token model
│       └── context.go          # Context utilities
├── database/
│   └── schema.sql              # Database schema (TODO)
├── docker-compose.yml          # Development environment
├── docker-compose.prod.yml     # Production environment
├── Dockerfile                  # Application container
├── Makefile                    # Development commands
└── main.go                     # Application entry point

Available Make Commands

  • make prepare - Start required containers (MySQL)
  • make migrate - Run database migrations
  • make run - Start the application
  • make clean - Clean up containers and volumes

Docker Support

The project includes Docker configuration for both development and production:

  • Development: docker-compose.yml with MySQL and volume mounting
  • Production: docker-compose.prod.yml with optimized settings

The challenge

This project serves as a practice run with the following key tasks to complete:

  1. 🔄 Database Schema (database/schema.sql) Model the following entities in the database:
  • Todo

    • id - UUID (primary key)
    • title - String
    • description - String
    • completed - Boolean
    • organizationId - UUID
    • accountId - UUID
    • createdAt - Timestamp
    • updatedAt - Timestamp
  • Comment

    • id - UUID (primary key)
    • text - String
    • todoId - UUID (foreign key referencing Todo)
    • accountId - UUID
    • createdAt - Timestamp
  1. 🔄 Authentication Middleware (internal/controllers/middlewares/token.go): The server should verify the access token and obtain its details.

  2. 🔄 Todo API (internal/app/router.go, internal/controllers/, internal/models, internal/repositories) Implement the following API endpoints. Each endpoint should be protected using the bearer-auth plugin and should only allow access to todos and comments for the current organization:

    • GET /todos - Get all todos
    • POST /todos - Create a new todo
    • PATCH /todos/:id - Update a todo
    • DELETE /todos/:id - Delete a todo
    • GET /todos/:id - Get a todo by id together with all comments
    • POST /todos/:id/comments - Create a new comment for a todo
  3. 🔄 Websockets API Implement WebSocket support. Every change made by a user, should be propagated to every user from the same organization that is currently connected via websocket.

  4. 🔄 Dockerization (./Dockerfile) Prepare the application for containerization using Docker. See docker-compose.prod.yml for the expected configuration.

License

This project is for educational and practice purposes.

About

No description, website, or topics provided.

Resources

Stars

0 stars

Watchers

0 watching

Forks

Releases

Packages

Used by

Contributors

Languages