This guide will help you set up your development environment and get started with contributing to Memex.
- Go 1.21 or later
- Git
- Clone the repository:
git clone https://github.com/yourusername/memex.git
cd memex
- Install dependencies:
go mod download
- Build the binaries:
# Build CLI tool
go build -o ~/bin/memex ./cmd/memex
# Build web server
go build -o ~/bin/memexd ./cmd/memexd
.
├── cmd/ # Command-line tools
│ ├── memex/ # CLI tool
│ └── memexd/ # Web server
├── internal/ # Internal packages
│ └── memex/
│ ├── core/ # Core DAG types
│ ├── storage/ # DAG storage implementation
│ ├── commands.go # CLI commands
│ ├── config.go # Configuration
│ └── editor.go # Text editor
├── pkg/ # Public API
│ └── memex/ # Client library
├── test/ # Test files
└── docs/ # Documentation
- Create a new branch for your feature:
git checkout -b feature/your-feature-name
-
Make your changes and write tests
-
Run tests:
go test ./...
- Format code:
go fmt ./...
- Create a repository:
memex init testrepo
- Start the server:
memexd -addr :3000 -path testrepo.mx
- Access the web interface:
- Open
http://localhost:3000
in your browser
# Run all tests
go test ./...
# Run tests with coverage
go test -cover ./...
# Run tests for a specific package
go test ./internal/memex/storage/...
- Place tests in the test/ directory
- Test both DAG structure and content storage
- Verify link relationships
- Ensure acyclic property is maintained
Example:
func TestAddNode(t *testing.T) {
tests := []struct {
name string
content []byte
nodeType string
meta map[string]any
wantErr bool
}{
{
name: "valid node",
content: []byte("test content"),
nodeType: "file",
meta: map[string]any{"filename": "test.txt"},
wantErr: false,
},
// Add more test cases
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
// Test implementation
})
}
}
- Define type in core/types.go:
// In core/types.go
const (
NodeTypeFile = "file"
NodeTypeNote = "note"
NodeTypeYourType = "yourtype"
)
- Add handling in storage implementation
- Define type constants:
const (
LinkTypeRef = "ref"
LinkTypeYourType = "yourtype"
)
- Update link validation if needed
- Add handler to cmd/memexd/main.go:
func (s *Server) handleNewEndpoint(w http.ResponseWriter, r *http.Request) {
// Implementation
}
- Register route in main():
http.HandleFunc("/newpath", server.handleNewEndpoint)
-
DAG Operations
- Validate links to maintain acyclic property
- Handle node versions properly
- Maintain referential integrity
-
Error Handling
- Use meaningful error messages
- Wrap errors with context
- Handle all error cases
-
Documentation
- Document node and link types
- Include graph structure examples
- Keep documentation up to date
-
Testing
- Test graph operations thoroughly
- Verify DAG properties
- Use table-driven tests
-
Git Commits
- Write clear commit messages
- Keep commits focused
- Reference issues in commits
- Check existing documentation
- Look through issues
- Ask questions in discussions