The Smart Dictionary is a language-learning tool designed to provide real-time translations, word suggestions, and definitions, helping users improve their vocabulary while engaging with foreign texts. Built in Go, this project offers an easy-to-use API for word translations and personalized vocabulary tracking, powered by external translation APIs.
- Real-time Translation: Context-aware translation for multiple languages.
- Word Definitions: Fetch definitions for selected words in a variety of languages.
- Token-Based Authentication: JWT-based authentication for secure API access.
- Integration with GPT and External APIs: Leverages GPT models and translation services for high-quality translations.
- Dockerized Deployment: Easily build and run the application with Docker.
smart-dictionary/
├── Dockerfile # Docker image configuration
├── README.md # Project documentation
├── cmd/
│ └── main.go # Main application entry point
├── db/
│ └── init.sql # Database initialization script
├── docker-compose.yaml # Docker Compose configuration
├── go.mod # Go module file
├── go.sum # Go module dependencies
└── internal/
├── domain/ # Core domain logic
│ ├── auth.go # Authentication domain logic
│ ├── chat_gpt.go # GPT model integration
│ ├── languages.go # Supported languages definitions
│ ├── token.go # JWT token handling
│ ├── translation.go # Translation domain logic
│ └── translation_request.go # Translation request handling
├── infrastructure/ # Repositories and external service integration
│ ├── auth_repository.go # User authentication repository
│ ├── mochi_api.go # Mochi API integration for translations
│ └── translator_repository.go # Translation repository
├── middleware/ # Middleware for handling requests
│ └── auth.go # JWT authentication middleware
├── server/ # Server-related code
│ └── translator_server.go # HTTP server and API routes
└── usecase/ # Application services and business logic
├── auth_service.go # Authentication service
└── jwt.go # JWT-related business logic
To run this project locally, you'll need:
- Go (version 1.18 or higher)
- Docker (for containerized deployment)
- PostgreSQL (as the database engine)
-
Clone the repository:
git clone https://github.com/bukhavtsov/smart-dictionary.git
-
Navigate into the project directory:
cd smart-dictionary
-
Set up the environment:
Configure your environment variables by creating a
.env
file or using the provided.env.tmp
as a template.
You can run the application either directly or using Docker.
Make sure to have the necessary Go modules installed:
go mod tidy
Then, run the application:
go run cmd/main.go
The app will be available at http://localhost:8080
.
Build the Docker image:
docker build -t smart-dict .
Run the application using Docker:
docker run --env-file .env.tmp -p 8080:8080 smart-dict
Alternatively, use docker-compose
to spin up the application and any dependencies (e.g., database):
docker-compose --env-fili .env.tmp up -d
The application uses PostgreSQL as its database. You can initialize the database schema with the SQL file provided in the db/
folder. If you're using Docker, this is handled automatically by the docker-compose.yaml
file.
For manual setup:
- Create a PostgreSQL database.
- Run the
db/init.sql
script to create necessary tables.
The application exposes various endpoints for translations and user management. Below are key endpoints:
- POST
/translate
- Translate a word or phrase. - POST
/login
- User authentication. - POST
/register
- User registration. - GET
/languages
- Fetch supported languages for translation.
To run the tests:
go test ./...
Make sure that your testing environment is properly set up with mock services or a test database.
To build the Docker image:
docker build -t smart-dict .
Run the application using the built image:
docker run --env-file .env.tmp -p 8080:8080 smart-dict
You can also run the application with docker-compose
, which will handle the database and any additional services:
docker-compose up --build
Make sure to configure the .env
file with the necessary environment variables, such as:
DB_HOST
: Database hostDB_USER
: Database userDB_PASSWORD
: Database passwordJWT_SECRET
: Secret for JWT token signing
We welcome contributions! To contribute to the Smart Dictionary project:
- Fork the repository.
- Create a feature branch (
git checkout -b feature/new-feature
). - Make your changes and commit them (
git commit -m 'Add new feature'
). - Push your branch (
git push origin feature/new-feature
). - Open a pull request.
Please ensure that your code adheres to the project guidelines and includes relevant tests.
This project is licensed under the MIT License. See the LICENSE file for details.
For any issues or suggestions, feel free to create an issue in the repository or reach out to the maintainers.