🏗️ Architecture
graph TD
subgraph Client["Frontend Client"]
UI[React UI]
end
subgraph Server["Go Fiber Server (main.go)"]
Main[Main Function]
ENV[Load Environment]
DB[MongoDB Connection]
Router[Fiber Router]
subgraph Endpoints["API Endpoints"]
GET[GET /api/todos]
POST[POST /api/todos]
PATCH[PATCH /api/todos/:id]
DELETE[DELETE /api/todos/:id]
end
subgraph Handlers["Handler Functions"]
getTodos
createTodo
updateTodo
deleteTodo
end
end
subgraph Database["MongoDB Atlas"]
Collection["Collection: todos</br>Database: golang_db"]
end
%% Main Application Flow
Main --> ENV
ENV --> DB
Main --> Router
Router --> Endpoints
%% Connect Endpoints to Handlers
GET --> getTodos
POST --> createTodo
PATCH --> updateTodo
DELETE --> deleteTodo
%% Connect Handlers to Database
getTodos --> Collection
createTodo --> Collection
updateTodo --> Collection
deleteTodo --> Collection
%% Client Interaction
UI <--> GET
UI <--> POST
UI <--> PATCH
UI <--> DELETE
%% Styling
classDef server fill:#f9f,stroke:#333,stroke-width:2px
classDef database fill:#b5d8ff,stroke:#333,stroke-width:2px
classDef client fill:#baffc9,stroke:#333,stroke-width:2px
classDef endpoint fill:#fff5ba,stroke:#333,stroke-width:2px
class Server server
class Database database
class Client client
class GET,POST,PATCH,DELETE endpoint
Before you begin, ensure you have the following installed:
git clone https://github.com/vigneshs-dev/golang-to-do-app.git
cd golang-to-do-app
go mod download
Create a .env
file in the root directory:
MONGODB_URI=your_mongodb_connection_string
PORT=5000
ENV=development
Replace your_mongodb_connection_string
with your MongoDB Atlas connection string or local MongoDB URL.
go run main.go
The server will start on http://localhost:5000
Navigate to the client directory:
cd client
Install dependencies:
npm install
Create a .env
file in the client directory:
VITE_API_URL=http://localhost:5000/api
Start the development server:
npm run dev
The frontend will start on http://localhost:5173
project-root/
├── 📜 main.go # Main backend server file
├── 📦 go.mod # Go modules file
├── 📋 go.sum # Go modules checksum
├── 🔒 .env # Backend environment variables
├── 📁 client/ # Frontend React application
│ ├── 📁 src/
│ ├── 📦 package.json
│ ├── 🔒 .env # Frontend environment variables
│ └── ...
└── 📖 README.md
Method | Endpoint | Description |
---|---|---|
GET |
/api/todos |
Get all todos |
POST |
/api/todos |
Create a new todo |
PATCH |
/api/todos/:id |
Update todo status |
DELETE |
/api/todos/:id |
Delete a todo |
Start the backend server:
go run main.go
In a separate terminal, start the frontend development server:
cd client
npm run dev
Build the frontend:
cd client
npm run build
Build the backend:
go build -o app
The application is deployed on Railway.app. For local development, follow the installation steps above.
Variable | Description |
---|---|
MONGODB_URI |
MongoDB connection string |
PORT |
Application port |
ENV |
Set to "production" |
🔴 MongoDB Connection Failed
🔴 Port Already in Use
🔴 API Calls Failed
🔴 Build Failures
npm cache clean --force
rm -rf node_modules
npm install
git checkout -b feature/AmazingFeature
)git commit -m 'Add some AmazingFeature'
)git push origin feature/AmazingFeature
)This project is licensed under the MIT License - see the LICENSE file for details