x/ref: Restructure debug,logreader,pprof,repository,stats,vtrace.

services/mgmt/debug          -> services/debug/debuglib/dispatcher.go
services/mgmt/logreader/impl -> services/logreader/logreaderlib
services/mgmt/pprof/impl     -> services/pprof/pproflib
services/mgmt/pprof/client   -> services/pprof/pproflib
services/mgmt/repository     -> services/repository
services/mgmt/stats          -> services/stats
services/mgmt/stats/impl     -> services/stats/statslib
services/mgmt/vtrace/impl    -> services/vtrace/vtracelib

Change-Id: I3dadc6ff0c07330a16d6db281bf7ed034bc9c45f
diff --git a/cmd/debug/impl.go b/cmd/debug/impl.go
index fa4e3a1..8ec5265 100644
--- a/cmd/debug/impl.go
+++ b/cmd/debug/impl.go
@@ -28,7 +28,7 @@
 	"v.io/x/lib/cmdline"
 	"v.io/x/ref/lib/glob"
 	"v.io/x/ref/lib/signals"
-	"v.io/x/ref/services/mgmt/pprof/client"
+	"v.io/x/ref/services/pprof/pproflib"
 )
 
 var (
@@ -471,7 +471,7 @@
 		return showPProfProfiles(cmd, name)
 	}
 	profile := args[1]
-	listener, err := client.StartProxy(gctx, name)
+	listener, err := pproflib.StartProxy(gctx, name)
 	if err != nil {
 		return err
 	}
@@ -531,7 +531,7 @@
 		return cmd.UsageErrorf("proxy: incorrect number of arguments, got %d, want %d", got, want)
 	}
 	name := args[0]
-	listener, err := client.StartProxy(gctx, name)
+	listener, err := pproflib.StartProxy(gctx, name)
 	if err != nil {
 		return err
 	}
diff --git a/cmd/mgmt/device/publish.go b/cmd/mgmt/device/publish.go
index 3743625..df6a2b1 100644
--- a/cmd/mgmt/device/publish.go
+++ b/cmd/mgmt/device/publish.go
@@ -22,7 +22,7 @@
 
 	"v.io/x/lib/cmdline"
 	"v.io/x/ref/services/mgmt/lib/binary"
-	irepos "v.io/x/ref/services/mgmt/repository"
+	"v.io/x/ref/services/repository"
 )
 
 // TODO(caprita): Add unit test.
@@ -120,7 +120,7 @@
 	profiles := []string{fmt.Sprintf("%s-%s", goos, goarch)}
 	// TODO(caprita): use a label e.g. "prod" instead of "0".
 	appVON := naming.Join(applicationService, binaryName, "0")
-	appClient := irepos.ApplicationClient(appVON)
+	appClient := repository.ApplicationClient(appVON)
 	// NOTE: If profiles contains more than one entry, this will return only
 	// the first match.  But presumably that's ok, since we're going to set
 	// the envelopes for all the profiles to the same envelope anyway below.
@@ -132,7 +132,7 @@
 		return err
 	}
 	envelope.Binary.File = binaryVON
-	if err := irepos.ApplicationClient(appVON).Put(gctx, profiles, envelope); err != nil {
+	if err := repository.ApplicationClient(appVON).Put(gctx, profiles, envelope); err != nil {
 		return err
 	}
 	fmt.Fprintf(cmd.Stdout(), "Published %q\n", appVON)
diff --git a/lib/stats/histogram/histogram.go b/lib/stats/histogram/histogram.go
index 4277d6f..c9b329b 100644
--- a/lib/stats/histogram/histogram.go
+++ b/lib/stats/histogram/histogram.go
@@ -11,7 +11,7 @@
 
 	"v.io/v23/verror"
 	"v.io/x/ref/lib/stats/counter"
-	"v.io/x/ref/services/mgmt/stats"
+	"v.io/x/ref/services/stats"
 )
 
 const pkgPath = "v.io/x/ref/lib/stats/histogram"
diff --git a/lib/stats/stats_test.go b/lib/stats/stats_test.go
index be5f3ed..4115942 100644
--- a/lib/stats/stats_test.go
+++ b/lib/stats/stats_test.go
@@ -13,7 +13,7 @@
 	libstats "v.io/x/ref/lib/stats"
 	"v.io/x/ref/lib/stats/counter"
 	"v.io/x/ref/lib/stats/histogram"
-	istats "v.io/x/ref/services/mgmt/stats"
+	s_stats "v.io/x/ref/services/stats"
 )
 
 func doGlob(root, pattern string, since time.Time, includeValues bool) ([]libstats.KeyValue, error) {
@@ -226,17 +226,17 @@
 	expected = []libstats.KeyValue{
 		libstats.KeyValue{
 			Key: "rpc/test/hhh",
-			Value: istats.HistogramValue{
+			Value: s_stats.HistogramValue{
 				Count: 2,
 				Sum:   3,
 				Min:   1,
 				Max:   2,
-				Buckets: []istats.HistogramBucket{
-					istats.HistogramBucket{LowBound: 0, Count: 0},
-					istats.HistogramBucket{LowBound: 1, Count: 1},
-					istats.HistogramBucket{LowBound: 2, Count: 1},
-					istats.HistogramBucket{LowBound: 3, Count: 0},
-					istats.HistogramBucket{LowBound: 4, Count: 0},
+				Buckets: []s_stats.HistogramBucket{
+					s_stats.HistogramBucket{LowBound: 0, Count: 0},
+					s_stats.HistogramBucket{LowBound: 1, Count: 1},
+					s_stats.HistogramBucket{LowBound: 2, Count: 1},
+					s_stats.HistogramBucket{LowBound: 3, Count: 0},
+					s_stats.HistogramBucket{LowBound: 4, Count: 0},
 				},
 			},
 		},
@@ -257,17 +257,17 @@
 	expected = []libstats.KeyValue{
 		libstats.KeyValue{
 			Key: "rpc/test/hhh/delta1m",
-			Value: istats.HistogramValue{
+			Value: s_stats.HistogramValue{
 				Count: 2,
 				Sum:   5,
 				Min:   2,
 				Max:   3,
-				Buckets: []istats.HistogramBucket{
-					istats.HistogramBucket{LowBound: 0, Count: 0},
-					istats.HistogramBucket{LowBound: 1, Count: 0},
-					istats.HistogramBucket{LowBound: 2, Count: 1},
-					istats.HistogramBucket{LowBound: 3, Count: 1},
-					istats.HistogramBucket{LowBound: 4, Count: 0},
+				Buckets: []s_stats.HistogramBucket{
+					s_stats.HistogramBucket{LowBound: 0, Count: 0},
+					s_stats.HistogramBucket{LowBound: 1, Count: 0},
+					s_stats.HistogramBucket{LowBound: 2, Count: 1},
+					s_stats.HistogramBucket{LowBound: 3, Count: 1},
+					s_stats.HistogramBucket{LowBound: 4, Count: 0},
 				},
 			},
 		},
diff --git a/profiles/internal/rpc/debug_test.go b/profiles/internal/rpc/debug_test.go
index 74681ca..0e8e46e 100644
--- a/profiles/internal/rpc/debug_test.go
+++ b/profiles/internal/rpc/debug_test.go
@@ -19,7 +19,7 @@
 	"v.io/x/ref/lib/stats"
 	"v.io/x/ref/profiles/internal/rpc/stream/manager"
 	tnaming "v.io/x/ref/profiles/internal/testing/mocks/naming"
-	"v.io/x/ref/services/mgmt/debug"
+	"v.io/x/ref/services/debug/debuglib"
 	"v.io/x/ref/test/testutil"
 )
 
@@ -36,7 +36,7 @@
 	pclient.AddToRoots(bclient)                    // Client recognizes "server" as a root of blessings.
 	pclient.BlessingStore().Set(bclient, "server") // Client presents bclient to server
 
-	debugDisp := debug.NewDispatcher(vlog.Log.LogDir, nil)
+	debugDisp := debuglib.NewDispatcher(vlog.Log.LogDir, nil)
 
 	sm := manager.InternalNew(naming.FixedRoutingID(0x555555555))
 	defer sm.Shutdown()
diff --git a/profiles/internal/rt/runtime_test.go b/profiles/internal/rt/runtime_test.go
index fd07d04..dc4e23e 100644
--- a/profiles/internal/rt/runtime_test.go
+++ b/profiles/internal/rt/runtime_test.go
@@ -14,7 +14,7 @@
 
 	"v.io/x/ref/lib/flags"
 	"v.io/x/ref/profiles/internal/rt"
-	"v.io/x/ref/services/mgmt/debug"
+	"v.io/x/ref/services/debug/debuglib"
 	"v.io/x/ref/test/testutil"
 )
 
@@ -138,7 +138,7 @@
 	defer shutdown()
 
 	oldDebugDisp := r.GetReservedNameDispatcher(ctx)
-	newDebugDisp := debug.NewDispatcher(vlog.Log.LogDir, nil)
+	newDebugDisp := debuglib.NewDispatcher(vlog.Log.LogDir, nil)
 
 	nctx := r.SetReservedNameDispatcher(ctx, newDebugDisp)
 	debugDisp := r.GetReservedNameDispatcher(nctx)
diff --git a/profiles/roaming/roaminginit.go b/profiles/roaming/roaminginit.go
index b117402..9edddc6 100644
--- a/profiles/roaming/roaminginit.go
+++ b/profiles/roaming/roaminginit.go
@@ -33,7 +33,7 @@
 	_ "v.io/x/ref/profiles/internal/rpc/protocols/ws"
 	_ "v.io/x/ref/profiles/internal/rpc/protocols/wsh"
 	grt "v.io/x/ref/profiles/internal/rt"
-	"v.io/x/ref/services/mgmt/debug"
+	"v.io/x/ref/services/debug/debuglib"
 
 	// TODO(cnicolaou,ashankar): move this into flags.
 	sflag "v.io/x/ref/security/flag"
@@ -61,7 +61,7 @@
 		Addrs: rpc.ListenAddrs(lf.Addrs),
 		Proxy: lf.ListenProxy,
 	}
-	reservedDispatcher := debug.NewDispatcher(vlog.Log.LogDir, sflag.NewAuthorizerOrDie())
+	reservedDispatcher := debuglib.NewDispatcher(vlog.Log.LogDir, sflag.NewAuthorizerOrDie())
 
 	ac := appcycle.New()
 
diff --git a/profiles/static/staticinit.go b/profiles/static/staticinit.go
index fca56cd..8458777 100644
--- a/profiles/static/staticinit.go
+++ b/profiles/static/staticinit.go
@@ -21,7 +21,7 @@
 	_ "v.io/x/ref/profiles/internal/rpc/protocols/ws"
 	_ "v.io/x/ref/profiles/internal/rpc/protocols/wsh"
 	grt "v.io/x/ref/profiles/internal/rt"
-	"v.io/x/ref/services/mgmt/debug"
+	"v.io/x/ref/services/debug/debuglib"
 
 	// TODO(cnicolaou,ashankar): move this into flags.
 	sflag "v.io/x/ref/security/flag"
@@ -45,7 +45,7 @@
 		Addrs: rpc.ListenAddrs(lf.Addrs),
 		Proxy: lf.ListenProxy,
 	}
-	reservedDispatcher := debug.NewDispatcher(vlog.Log.LogDir, sflag.NewAuthorizerOrDie())
+	reservedDispatcher := debuglib.NewDispatcher(vlog.Log.LogDir, sflag.NewAuthorizerOrDie())
 
 	ac := appcycle.New()
 
diff --git a/services/application/application/impl.go b/services/application/application/impl.go
index 2f1b543..c0b5e1d 100644
--- a/services/application/application/impl.go
+++ b/services/application/application/impl.go
@@ -18,7 +18,7 @@
 	"v.io/v23/context"
 	"v.io/v23/services/application"
 	"v.io/x/lib/cmdline"
-	"v.io/x/ref/services/mgmt/repository"
+	"v.io/x/ref/services/repository"
 )
 
 func getEnvelopeJSON(app repository.ApplicationClientMethods, profiles string) ([]byte, error) {
diff --git a/services/application/application/impl_test.go b/services/application/application/impl_test.go
index 1cbcac5..dc93bb8 100644
--- a/services/application/application/impl_test.go
+++ b/services/application/application/impl_test.go
@@ -21,7 +21,7 @@
 	"v.io/x/lib/vlog"
 
 	_ "v.io/x/ref/profiles"
-	"v.io/x/ref/services/mgmt/repository"
+	"v.io/x/ref/services/repository"
 	"v.io/x/ref/test"
 )
 
diff --git a/services/application/applicationd/acl_test.go b/services/application/applicationd/acl_test.go
index 28701c5..bfefc2f 100644
--- a/services/application/applicationd/acl_test.go
+++ b/services/application/applicationd/acl_test.go
@@ -23,7 +23,7 @@
 	"v.io/x/ref/lib/signals"
 	appd "v.io/x/ref/services/application/applicationd"
 	mgmttest "v.io/x/ref/services/mgmt/lib/testutil"
-	"v.io/x/ref/services/mgmt/repository"
+	"v.io/x/ref/services/repository"
 	"v.io/x/ref/test"
 	"v.io/x/ref/test/testutil"
 )
diff --git a/services/application/applicationd/dispatcher.go b/services/application/applicationd/dispatcher.go
index 04c03e8..4c5aa1c 100644
--- a/services/application/applicationd/dispatcher.go
+++ b/services/application/applicationd/dispatcher.go
@@ -15,7 +15,7 @@
 
 	"v.io/x/ref/services/mgmt/lib/acls"
 	"v.io/x/ref/services/mgmt/lib/fs"
-	"v.io/x/ref/services/mgmt/repository"
+	"v.io/x/ref/services/repository"
 )
 
 // dispatcher holds the state of the application repository dispatcher.
diff --git a/services/application/applicationd/impl_test.go b/services/application/applicationd/impl_test.go
index 9dd1b7a..d61c7dd 100644
--- a/services/application/applicationd/impl_test.go
+++ b/services/application/applicationd/impl_test.go
@@ -19,7 +19,7 @@
 
 	appd "v.io/x/ref/services/application/applicationd"
 	mgmttest "v.io/x/ref/services/mgmt/lib/testutil"
-	"v.io/x/ref/services/mgmt/repository"
+	"v.io/x/ref/services/repository"
 	"v.io/x/ref/test"
 	"v.io/x/ref/test/testutil"
 )
diff --git a/services/application/applicationd/service.go b/services/application/applicationd/service.go
index a2064ee..9632cdf 100644
--- a/services/application/applicationd/service.go
+++ b/services/application/applicationd/service.go
@@ -9,7 +9,7 @@
 
 	"v.io/x/ref/services/mgmt/lib/acls"
 	"v.io/x/ref/services/mgmt/lib/fs"
-	"v.io/x/ref/services/mgmt/repository"
+	"v.io/x/ref/services/repository"
 
 	"v.io/v23/naming"
 	"v.io/v23/rpc"
diff --git a/services/mgmt/debug/dispatcher.go b/services/debug/debuglib/dispatcher.go
similarity index 74%
rename from services/mgmt/debug/dispatcher.go
rename to services/debug/debuglib/dispatcher.go
index db4c8ed..55f44a5 100644
--- a/services/mgmt/debug/dispatcher.go
+++ b/services/debug/debuglib/dispatcher.go
@@ -2,7 +2,7 @@
 // Use of this source code is governed by a BSD-style
 // license that can be found in the LICENSE file.
 
-package debug
+package debuglib
 
 import (
 	"strings"
@@ -11,10 +11,10 @@
 	"v.io/v23/rpc"
 	"v.io/v23/security"
 
-	logreaderimpl "v.io/x/ref/services/mgmt/logreader/impl"
-	pprofimpl "v.io/x/ref/services/mgmt/pprof/impl"
-	statsimpl "v.io/x/ref/services/mgmt/stats/impl"
-	vtraceimpl "v.io/x/ref/services/mgmt/vtrace/impl"
+	"v.io/x/ref/services/logreader/logreaderlib"
+	"v.io/x/ref/services/pprof/pproflib"
+	"v.io/x/ref/services/stats/statslib"
+	"v.io/x/ref/services/vtrace/vtracelib"
 )
 
 // dispatcher holds the state of the debug dispatcher.
@@ -53,13 +53,13 @@
 	}
 	switch parts[0] {
 	case "logs":
-		return logreaderimpl.NewLogFileService(d.logsDirFunc(), suffix), d.auth, nil
+		return logreaderlib.NewLogFileService(d.logsDirFunc(), suffix), d.auth, nil
 	case "pprof":
-		return pprofimpl.NewPProfService(), d.auth, nil
+		return pproflib.NewPProfService(), d.auth, nil
 	case "stats":
-		return statsimpl.NewStatsService(suffix, 10*time.Second), d.auth, nil
+		return statslib.NewStatsService(suffix, 10*time.Second), d.auth, nil
 	case "vtrace":
-		return vtraceimpl.NewVtraceService(), d.auth, nil
+		return vtracelib.NewVtraceService(), d.auth, nil
 	}
 	return nil, d.auth, nil
 }
diff --git a/services/mgmt/debug/dispatcher_test.go b/services/debug/debuglib/dispatcher_test.go
similarity index 99%
rename from services/mgmt/debug/dispatcher_test.go
rename to services/debug/debuglib/dispatcher_test.go
index 30d065a..00cdea1 100644
--- a/services/mgmt/debug/dispatcher_test.go
+++ b/services/debug/debuglib/dispatcher_test.go
@@ -2,7 +2,7 @@
 // Use of this source code is governed by a BSD-style
 // license that can be found in the LICENSE file.
 
-package debug
+package debuglib
 
 import (
 	"fmt"
diff --git a/services/mgmt/logreader/impl/v23_internal_test.go b/services/debug/debuglib/v23_internal_test.go
similarity index 95%
copy from services/mgmt/logreader/impl/v23_internal_test.go
copy to services/debug/debuglib/v23_internal_test.go
index f3c1179..cdbaeda 100644
--- a/services/mgmt/logreader/impl/v23_internal_test.go
+++ b/services/debug/debuglib/v23_internal_test.go
@@ -4,7 +4,7 @@
 
 // This file was auto-generated via go generate.
 // DO NOT UPDATE MANUALLY
-package impl
+package debuglib
 
 import "testing"
 import "os"
diff --git a/services/mgmt/logreader/impl/logfile.go b/services/logreader/logreaderlib/logfile.go
similarity index 96%
rename from services/mgmt/logreader/impl/logfile.go
rename to services/logreader/logreaderlib/logfile.go
index 10d9db4..26f89a6 100644
--- a/services/mgmt/logreader/impl/logfile.go
+++ b/services/logreader/logreaderlib/logfile.go
@@ -2,11 +2,11 @@
 // Use of this source code is governed by a BSD-style
 // license that can be found in the LICENSE file.
 
-// Package impl implements the LogFile interface from
+// Package logreaderlib implements the LogFile interface from
 // v.io/v23/services/logreader, which can be used to allow remote access to log
 // files, and the Globbable interface from v.io/v23/services/mounttable to find
 // the files in a logs directory.
-package impl
+package logreaderlib
 
 import (
 	"io"
@@ -21,7 +21,7 @@
 	"v.io/x/lib/vlog"
 )
 
-const pkgPath = "v.io/x/ref/services/mgmt/logreader/impl"
+const pkgPath = "v.io/x/ref/services/logreader/logreaderlib"
 
 var (
 	errOperationFailed = verror.Register(pkgPath+".errOperationFailed", verror.NoRetry, "{1:}{2:} operation failed{:_}")
diff --git a/services/mgmt/logreader/impl/logfile_test.go b/services/logreader/logreaderlib/logfile_test.go
similarity index 97%
rename from services/mgmt/logreader/impl/logfile_test.go
rename to services/logreader/logreaderlib/logfile_test.go
index 8e9d229..e94b4d2 100644
--- a/services/mgmt/logreader/impl/logfile_test.go
+++ b/services/logreader/logreaderlib/logfile_test.go
@@ -2,7 +2,7 @@
 // Use of this source code is governed by a BSD-style
 // license that can be found in the LICENSE file.
 
-package impl_test
+package logreaderlib_test
 
 import (
 	"io/ioutil"
@@ -19,7 +19,7 @@
 	"v.io/v23/verror"
 
 	_ "v.io/x/ref/profiles"
-	"v.io/x/ref/services/mgmt/logreader/impl"
+	"v.io/x/ref/services/logreader/logreaderlib"
 	"v.io/x/ref/test"
 )
 
@@ -54,7 +54,7 @@
 }
 
 func (d *logFileDispatcher) Lookup(suffix string) (interface{}, security.Authorizer, error) {
-	return impl.NewLogFileService(d.root, suffix), nil, nil
+	return logreaderlib.NewLogFileService(d.root, suffix), nil, nil
 }
 
 func writeAndSync(t *testing.T, w *os.File, s string) {
diff --git a/services/mgmt/logreader/impl/reader.go b/services/logreader/logreaderlib/reader.go
similarity index 98%
rename from services/mgmt/logreader/impl/reader.go
rename to services/logreader/logreaderlib/reader.go
index a63d2a1..9cc23f4 100644
--- a/services/mgmt/logreader/impl/reader.go
+++ b/services/logreader/logreaderlib/reader.go
@@ -2,7 +2,7 @@
 // Use of this source code is governed by a BSD-style
 // license that can be found in the LICENSE file.
 
-package impl
+package logreaderlib
 
 import (
 	"bytes"
diff --git a/services/mgmt/logreader/impl/reader_test.go b/services/logreader/logreaderlib/reader_test.go
similarity index 98%
rename from services/mgmt/logreader/impl/reader_test.go
rename to services/logreader/logreaderlib/reader_test.go
index 60134e6..fec4faa 100644
--- a/services/mgmt/logreader/impl/reader_test.go
+++ b/services/logreader/logreaderlib/reader_test.go
@@ -2,7 +2,7 @@
 // Use of this source code is governed by a BSD-style
 // license that can be found in the LICENSE file.
 
-package impl
+package logreaderlib
 
 import (
 	"io"
diff --git a/services/mgmt/logreader/impl/v23_internal_test.go b/services/logreader/logreaderlib/v23_internal_test.go
similarity index 94%
copy from services/mgmt/logreader/impl/v23_internal_test.go
copy to services/logreader/logreaderlib/v23_internal_test.go
index f3c1179..bcdf9fb 100644
--- a/services/mgmt/logreader/impl/v23_internal_test.go
+++ b/services/logreader/logreaderlib/v23_internal_test.go
@@ -4,7 +4,7 @@
 
 // This file was auto-generated via go generate.
 // DO NOT UPDATE MANUALLY
-package impl
+package logreaderlib
 
 import "testing"
 import "os"
diff --git a/services/mgmt/debug/v23_internal_test.go b/services/mgmt/debug/v23_internal_test.go
deleted file mode 100644
index 6fbfd3a..0000000
--- a/services/mgmt/debug/v23_internal_test.go
+++ /dev/null
@@ -1,17 +0,0 @@
-// Copyright 2015 The Vanadium Authors. All rights reserved.
-// Use of this source code is governed by a BSD-style
-// license that can be found in the LICENSE file.
-
-// This file was auto-generated via go generate.
-// DO NOT UPDATE MANUALLY
-package debug
-
-import "testing"
-import "os"
-
-import "v.io/x/ref/test"
-
-func TestMain(m *testing.M) {
-	test.Init()
-	os.Exit(m.Run())
-}
diff --git a/services/mgmt/device/impl/dispatcher.go b/services/mgmt/device/impl/dispatcher.go
index 632654a..2ec2dcb 100644
--- a/services/mgmt/device/impl/dispatcher.go
+++ b/services/mgmt/device/impl/dispatcher.go
@@ -14,10 +14,10 @@
 
 	"v.io/x/ref/security/agent"
 	"v.io/x/ref/security/agent/keymgr"
+	"v.io/x/ref/services/logreader/logreaderlib"
 	idevice "v.io/x/ref/services/mgmt/device"
 	"v.io/x/ref/services/mgmt/device/config"
 	"v.io/x/ref/services/mgmt/lib/acls"
-	logsimpl "v.io/x/ref/services/mgmt/logreader/impl"
 
 	"v.io/v23"
 	"v.io/v23/context"
@@ -295,7 +295,7 @@
 				if err != nil {
 					return nil, nil, err
 				}
-				return logsimpl.NewLogFileService(logsDir, suffix), appSpecificAuthorizer, nil
+				return logreaderlib.NewLogFileService(logsDir, suffix), appSpecificAuthorizer, nil
 			case "pprof", "stats":
 				info, err := loadInstanceInfo(nil, appInstanceDir)
 				if err != nil {
diff --git a/services/mgmt/device/starter/starter.go b/services/mgmt/device/starter/starter.go
index da097f4..a854f24 100644
--- a/services/mgmt/device/starter/starter.go
+++ b/services/mgmt/device/starter/starter.go
@@ -16,7 +16,7 @@
 
 	"v.io/x/lib/netstate"
 	"v.io/x/ref/profiles/roaming"
-	"v.io/x/ref/services/mgmt/debug"
+	"v.io/x/ref/services/debug/debuglib"
 	"v.io/x/ref/services/mgmt/device/config"
 	"v.io/x/ref/services/mgmt/device/impl"
 	"v.io/x/ref/services/mgmt/lib/acls"
@@ -217,7 +217,7 @@
 		return nil, err
 	}
 
-	debugDisp := debug.NewDispatcher(vlog.Log.LogDir, debugAuth)
+	debugDisp := debuglib.NewDispatcher(vlog.Log.LogDir, debugAuth)
 
 	ctx = v23.SetReservedNameDispatcher(ctx, debugDisp)
 
diff --git a/services/mgmt/pprof/client/v23_internal_test.go b/services/mgmt/pprof/client/v23_internal_test.go
deleted file mode 100644
index 245e39a..0000000
--- a/services/mgmt/pprof/client/v23_internal_test.go
+++ /dev/null
@@ -1,17 +0,0 @@
-// Copyright 2015 The Vanadium Authors. All rights reserved.
-// Use of this source code is governed by a BSD-style
-// license that can be found in the LICENSE file.
-
-// This file was auto-generated via go generate.
-// DO NOT UPDATE MANUALLY
-package client
-
-import "testing"
-import "os"
-
-import "v.io/x/ref/test"
-
-func TestMain(m *testing.M) {
-	test.Init()
-	os.Exit(m.Run())
-}
diff --git a/services/mgmt/stats/impl/v23_internal_test.go b/services/mgmt/stats/impl/v23_internal_test.go
deleted file mode 100644
index f3c1179..0000000
--- a/services/mgmt/stats/impl/v23_internal_test.go
+++ /dev/null
@@ -1,17 +0,0 @@
-// Copyright 2015 The Vanadium Authors. All rights reserved.
-// Use of this source code is governed by a BSD-style
-// license that can be found in the LICENSE file.
-
-// This file was auto-generated via go generate.
-// DO NOT UPDATE MANUALLY
-package impl
-
-import "testing"
-import "os"
-
-import "v.io/x/ref/test"
-
-func TestMain(m *testing.M) {
-	test.Init()
-	os.Exit(m.Run())
-}
diff --git a/services/mgmt/vtrace/impl/v23_internal_test.go b/services/mgmt/vtrace/impl/v23_internal_test.go
deleted file mode 100644
index f3c1179..0000000
--- a/services/mgmt/vtrace/impl/v23_internal_test.go
+++ /dev/null
@@ -1,17 +0,0 @@
-// Copyright 2015 The Vanadium Authors. All rights reserved.
-// Use of this source code is governed by a BSD-style
-// license that can be found in the LICENSE file.
-
-// This file was auto-generated via go generate.
-// DO NOT UPDATE MANUALLY
-package impl
-
-import "testing"
-import "os"
-
-import "v.io/x/ref/test"
-
-func TestMain(m *testing.M) {
-	test.Init()
-	os.Exit(m.Run())
-}
diff --git a/services/mgmt/pprof/client/proxy.go b/services/pprof/pproflib/proxy.go
similarity index 96%
rename from services/mgmt/pprof/client/proxy.go
rename to services/pprof/pproflib/proxy.go
index eab49fc..edd7414 100644
--- a/services/mgmt/pprof/client/proxy.go
+++ b/services/pprof/pproflib/proxy.go
@@ -2,12 +2,13 @@
 // Use of this source code is governed by a BSD-style
 // license that can be found in the LICENSE file.
 
-// Package client implement a client-side proxy of a vanadium server's pprof
-// interface.
+// Package pproflib defines a client-side proxy and server-side implementation
+// of the v.io/v23/services/pprof interface.
+//
 // It is functionally equivalent to http://golang.org/pkg/net/http/pprof/,
-// except that the data comes from a remote vanadium server, and the handlers are
-// not registered in DefaultServeMux.
-package client
+// except that the data comes from a remote vanadium server, and the handlers
+// are not registered in DefaultServeMux.
+package pproflib
 
 import (
 	"bufio"
diff --git a/services/mgmt/pprof/client/proxy_test.go b/services/pprof/pproflib/proxy_test.go
similarity index 86%
rename from services/mgmt/pprof/client/proxy_test.go
rename to services/pprof/pproflib/proxy_test.go
index 052e8dc..34afb6f 100644
--- a/services/mgmt/pprof/client/proxy_test.go
+++ b/services/pprof/pproflib/proxy_test.go
@@ -2,7 +2,7 @@
 // Use of this source code is governed by a BSD-style
 // license that can be found in the LICENSE file.
 
-package client_test
+package pproflib_test
 
 import (
 	"fmt"
@@ -14,8 +14,7 @@
 	"v.io/v23/security"
 
 	_ "v.io/x/ref/profiles"
-	"v.io/x/ref/services/mgmt/pprof/client"
-	"v.io/x/ref/services/mgmt/pprof/impl"
+	"v.io/x/ref/services/pprof/pproflib"
 	"v.io/x/ref/test"
 )
 
@@ -42,10 +41,10 @@
 	if err != nil {
 		t.Fatalf("failed to listen: %v", err)
 	}
-	if err := s.ServeDispatcher("", &dispatcher{impl.NewPProfService()}); err != nil {
+	if err := s.ServeDispatcher("", &dispatcher{pproflib.NewPProfService()}); err != nil {
 		t.Fatalf("failed to serve: %v", err)
 	}
-	l, err := client.StartProxy(ctx, endpoints[0].Name())
+	l, err := pproflib.StartProxy(ctx, endpoints[0].Name())
 	if err != nil {
 		t.Fatalf("failed to start proxy: %v", err)
 	}
diff --git a/services/mgmt/pprof/impl/server.go b/services/pprof/pproflib/server.go
similarity index 86%
rename from services/mgmt/pprof/impl/server.go
rename to services/pprof/pproflib/server.go
index a373cbf..57a143a 100644
--- a/services/mgmt/pprof/impl/server.go
+++ b/services/pprof/pproflib/server.go
@@ -2,8 +2,7 @@
 // Use of this source code is governed by a BSD-style
 // license that can be found in the LICENSE file.
 
-// Package impl is the server-side implementation of the pprof interface.
-package impl
+package pproflib
 
 import (
 	"os"
@@ -12,11 +11,11 @@
 	"time"
 
 	"v.io/v23/rpc"
-	spprof "v.io/v23/services/pprof"
+	s_pprof "v.io/v23/services/pprof"
 	"v.io/v23/verror"
 )
 
-const pkgPath = "v.io/x/ref/services/mgmt/pprof/impl"
+const pkgPath = "v.io/x/ref/services/pprof/pproflib"
 
 // Errors
 var (
@@ -26,7 +25,7 @@
 
 // NewPProfService returns a new pprof service implementation.
 func NewPProfService() interface{} {
-	return spprof.PProfServer(&pprofService{})
+	return s_pprof.PProfServer(&pprofService{})
 }
 
 type pprofService struct {
@@ -52,7 +51,7 @@
 // addresses that pprof needs. Passing debug=1 adds comments translating
 // addresses to function names and line numbers, so that a programmer
 // can read the profile without tools.
-func (pprofService) Profile(call spprof.PProfProfileServerCall, name string, debug int32) error {
+func (pprofService) Profile(call s_pprof.PProfProfileServerCall, name string, debug int32) error {
 	profile := pprof.Lookup(name)
 	if profile == nil {
 		return verror.New(errNoProfile, call.Context(), name)
@@ -65,7 +64,7 @@
 
 // CPUProfile enables CPU profiling for the requested duration and
 // streams the profile data.
-func (pprofService) CpuProfile(call spprof.PProfCpuProfileServerCall, seconds int32) error {
+func (pprofService) CpuProfile(call s_pprof.PProfCpuProfileServerCall, seconds int32) error {
 	if seconds <= 0 || seconds > 3600 {
 		return verror.New(errInvalidSeconds, call.Context(), seconds)
 	}
diff --git a/services/mgmt/logreader/impl/v23_internal_test.go b/services/pprof/pproflib/v23_internal_test.go
similarity index 95%
rename from services/mgmt/logreader/impl/v23_internal_test.go
rename to services/pprof/pproflib/v23_internal_test.go
index f3c1179..266140e 100644
--- a/services/mgmt/logreader/impl/v23_internal_test.go
+++ b/services/pprof/pproflib/v23_internal_test.go
@@ -4,7 +4,7 @@
 
 // This file was auto-generated via go generate.
 // DO NOT UPDATE MANUALLY
-package impl
+package pproflib
 
 import "testing"
 import "os"
diff --git a/services/profile/profile/impl.go b/services/profile/profile/impl.go
index a23f0e3..03bc0ef 100644
--- a/services/profile/profile/impl.go
+++ b/services/profile/profile/impl.go
@@ -11,8 +11,8 @@
 	"v.io/v23/context"
 	"v.io/v23/services/build"
 	"v.io/x/lib/cmdline"
-	"v.io/x/ref/services/mgmt/repository"
 	"v.io/x/ref/services/profile"
+	"v.io/x/ref/services/repository"
 )
 
 var cmdLabel = &cmdline.Command{
diff --git a/services/profile/profile/impl_test.go b/services/profile/profile/impl_test.go
index 6bde5b6..04a47b2 100644
--- a/services/profile/profile/impl_test.go
+++ b/services/profile/profile/impl_test.go
@@ -19,8 +19,8 @@
 	"v.io/x/lib/vlog"
 
 	_ "v.io/x/ref/profiles"
-	"v.io/x/ref/services/mgmt/repository"
 	"v.io/x/ref/services/profile"
+	"v.io/x/ref/services/repository"
 	"v.io/x/ref/test"
 )
 
diff --git a/services/profile/profiled/dispatcher.go b/services/profile/profiled/dispatcher.go
index 4b43fc7..171b7f8 100644
--- a/services/profile/profiled/dispatcher.go
+++ b/services/profile/profiled/dispatcher.go
@@ -11,7 +11,7 @@
 	"v.io/v23/security"
 
 	"v.io/x/ref/services/mgmt/lib/fs"
-	"v.io/x/ref/services/mgmt/repository"
+	"v.io/x/ref/services/repository"
 )
 
 // dispatcher holds the state of the profile repository dispatcher.
diff --git a/services/profile/profiled/impl_test.go b/services/profile/profiled/impl_test.go
index 635b26e..4903e8c 100644
--- a/services/profile/profiled/impl_test.go
+++ b/services/profile/profiled/impl_test.go
@@ -14,8 +14,8 @@
 	"v.io/v23/naming"
 	"v.io/v23/services/build"
 
-	"v.io/x/ref/services/mgmt/repository"
 	"v.io/x/ref/services/profile"
+	"v.io/x/ref/services/repository"
 	"v.io/x/ref/test"
 )
 
diff --git a/services/profile/profiled/service.go b/services/profile/profiled/service.go
index a7ecc90..7b0cc1b 100644
--- a/services/profile/profiled/service.go
+++ b/services/profile/profiled/service.go
@@ -8,8 +8,8 @@
 	"errors"
 
 	"v.io/x/ref/services/mgmt/lib/fs"
-	"v.io/x/ref/services/mgmt/repository"
 	"v.io/x/ref/services/profile"
+	"v.io/x/ref/services/repository"
 
 	"v.io/v23/naming"
 	"v.io/v23/rpc"
diff --git a/services/mgmt/repository/repository.vdl b/services/repository/repository.vdl
similarity index 100%
rename from services/mgmt/repository/repository.vdl
rename to services/repository/repository.vdl
diff --git a/services/mgmt/repository/repository.vdl.go b/services/repository/repository.vdl.go
similarity index 99%
rename from services/mgmt/repository/repository.vdl.go
rename to services/repository/repository.vdl.go
index 1be9637..806c856 100644
--- a/services/mgmt/repository/repository.vdl.go
+++ b/services/repository/repository.vdl.go
@@ -182,7 +182,7 @@
 // descApplication hides the desc to keep godoc clean.
 var descApplication = rpc.InterfaceDesc{
 	Name:    "Application",
-	PkgPath: "v.io/x/ref/services/mgmt/repository",
+	PkgPath: "v.io/x/ref/services/repository",
 	Doc:     "// Application describes an application repository internally. Besides\n// the public Application interface, it allows to add and remove\n// application envelopes.",
 	Embeds: []rpc.EmbedDesc{
 		{"Application", "v.io/v23/services/repository", "// Application provides access to application envelopes. An\n// application envelope is identified by an application name and an\n// application version, which are specified through the object name,\n// and a profile name, which is specified using a method argument.\n//\n// Example:\n// /apps/search/v1.Match([]string{\"base\", \"media\"})\n//   returns an application envelope that can be used for downloading\n//   and executing the \"search\" application, version \"v1\", runnable\n//   on either the \"base\" or \"media\" profile."},
@@ -359,7 +359,7 @@
 // descProfile hides the desc to keep godoc clean.
 var descProfile = rpc.InterfaceDesc{
 	Name:    "Profile",
-	PkgPath: "v.io/x/ref/services/mgmt/repository",
+	PkgPath: "v.io/x/ref/services/repository",
 	Doc:     "// Profile describes a profile internally. Besides the public Profile\n// interface, it allows to add and remove profile specifications.",
 	Embeds: []rpc.EmbedDesc{
 		{"Profile", "v.io/v23/services/repository", "// Profile abstracts a device's ability to run binaries, and hides\n// specifics such as the operating system, hardware architecture, and\n// the set of installed libraries. Profiles describe binaries and\n// devices, and are used to match them."},
diff --git a/services/mgmt/stats/impl/stats.go b/services/stats/statslib/stats.go
similarity index 95%
rename from services/mgmt/stats/impl/stats.go
rename to services/stats/statslib/stats.go
index 503420a..76bf03e 100644
--- a/services/mgmt/stats/impl/stats.go
+++ b/services/stats/statslib/stats.go
@@ -2,9 +2,9 @@
 // Use of this source code is governed by a BSD-style
 // license that can be found in the LICENSE file.
 
-// Package impl implements the Stats interface from
+// Package statslib implements the Stats interface from
 // v.io/v23/services/stats.
-package impl
+package statslib
 
 import (
 	"reflect"
@@ -26,7 +26,7 @@
 	watchFreq time.Duration
 }
 
-const pkgPath = "v.io/x/ref/services/mgmt/stats/impl"
+const pkgPath = "v.io/x/ref/services/stats/statslib"
 
 var (
 	errOperationFailed = verror.Register(pkgPath+".errOperationFailed", verror.NoRetry, "{1:}{2:} operation failed{:_}")
diff --git a/services/mgmt/stats/impl/stats_test.go b/services/stats/statslib/stats_test.go
similarity index 89%
rename from services/mgmt/stats/impl/stats_test.go
rename to services/stats/statslib/stats_test.go
index ca5a184..eae18e0 100644
--- a/services/mgmt/stats/impl/stats_test.go
+++ b/services/stats/statslib/stats_test.go
@@ -2,7 +2,7 @@
 // Use of this source code is governed by a BSD-style
 // license that can be found in the LICENSE file.
 
-package impl_test
+package statslib_test
 
 import (
 	"reflect"
@@ -21,8 +21,8 @@
 	libstats "v.io/x/ref/lib/stats"
 	"v.io/x/ref/lib/stats/histogram"
 	_ "v.io/x/ref/profiles"
-	istats "v.io/x/ref/services/mgmt/stats"
-	"v.io/x/ref/services/mgmt/stats/impl"
+	s_stats "v.io/x/ref/services/stats"
+	"v.io/x/ref/services/stats/statslib"
 	"v.io/x/ref/test"
 	"v.io/x/ref/test/testutil"
 )
@@ -33,7 +33,7 @@
 }
 
 func (d *statsDispatcher) Lookup(suffix string) (interface{}, security.Authorizer, error) {
-	return impl.NewStatsService(suffix, 100*time.Millisecond), nil, nil
+	return statslib.NewStatsService(suffix, 100*time.Millisecond), nil, nil
 }
 
 func startServer(t *testing.T, ctx *context.T) (string, func()) {
@@ -166,17 +166,17 @@
 		if err != nil {
 			t.Errorf("unexpected error: %v", err)
 		}
-		want := vdl.ValueOf(istats.HistogramValue{
+		want := vdl.ValueOf(s_stats.HistogramValue{
 			Count: 10,
 			Sum:   45,
 			Min:   0,
 			Max:   9,
-			Buckets: []istats.HistogramBucket{
-				istats.HistogramBucket{LowBound: 0, Count: 1},
-				istats.HistogramBucket{LowBound: 1, Count: 2},
-				istats.HistogramBucket{LowBound: 3, Count: 4},
-				istats.HistogramBucket{LowBound: 7, Count: 3},
-				istats.HistogramBucket{LowBound: 15, Count: 0},
+			Buckets: []s_stats.HistogramBucket{
+				s_stats.HistogramBucket{LowBound: 0, Count: 1},
+				s_stats.HistogramBucket{LowBound: 1, Count: 2},
+				s_stats.HistogramBucket{LowBound: 3, Count: 4},
+				s_stats.HistogramBucket{LowBound: 7, Count: 3},
+				s_stats.HistogramBucket{LowBound: 15, Count: 0},
 			},
 		})
 		if !vdl.EqualValue(value, want) {
diff --git a/services/mgmt/logreader/impl/v23_internal_test.go b/services/stats/statslib/v23_internal_test.go
similarity index 95%
copy from services/mgmt/logreader/impl/v23_internal_test.go
copy to services/stats/statslib/v23_internal_test.go
index f3c1179..8f6c7c9 100644
--- a/services/mgmt/logreader/impl/v23_internal_test.go
+++ b/services/stats/statslib/v23_internal_test.go
@@ -4,7 +4,7 @@
 
 // This file was auto-generated via go generate.
 // DO NOT UPDATE MANUALLY
-package impl
+package statslib
 
 import "testing"
 import "os"
diff --git a/services/mgmt/stats/types.go b/services/stats/types.go
similarity index 100%
rename from services/mgmt/stats/types.go
rename to services/stats/types.go
diff --git a/services/mgmt/stats/types.vdl b/services/stats/types.vdl
similarity index 100%
rename from services/mgmt/stats/types.vdl
rename to services/stats/types.vdl
diff --git a/services/mgmt/stats/types.vdl.go b/services/stats/types.vdl.go
similarity index 90%
rename from services/mgmt/stats/types.vdl.go
rename to services/stats/types.vdl.go
index 65f779d..8d54f98 100644
--- a/services/mgmt/stats/types.vdl.go
+++ b/services/stats/types.vdl.go
@@ -28,7 +28,7 @@
 }
 
 func (HistogramValue) __VDLReflect(struct {
-	Name string "v.io/x/ref/services/mgmt/stats.HistogramValue"
+	Name string "v.io/x/ref/services/stats.HistogramValue"
 }) {
 }
 
@@ -41,7 +41,7 @@
 }
 
 func (HistogramBucket) __VDLReflect(struct {
-	Name string "v.io/x/ref/services/mgmt/stats.HistogramBucket"
+	Name string "v.io/x/ref/services/stats.HistogramBucket"
 }) {
 }
 
diff --git a/services/mgmt/logreader/impl/v23_internal_test.go b/services/vtrace/vtracelib/v23_internal_test.go
similarity index 94%
copy from services/mgmt/logreader/impl/v23_internal_test.go
copy to services/vtrace/vtracelib/v23_internal_test.go
index f3c1179..386c81f 100644
--- a/services/mgmt/logreader/impl/v23_internal_test.go
+++ b/services/vtrace/vtracelib/v23_internal_test.go
@@ -4,7 +4,7 @@
 
 // This file was auto-generated via go generate.
 // DO NOT UPDATE MANUALLY
-package impl
+package vtracelib
 
 import "testing"
 import "os"
diff --git a/services/mgmt/vtrace/impl/vtrace.go b/services/vtrace/vtracelib/vtrace.go
similarity index 97%
rename from services/mgmt/vtrace/impl/vtrace.go
rename to services/vtrace/vtracelib/vtrace.go
index b9e54b5..9291406 100644
--- a/services/mgmt/vtrace/impl/vtrace.go
+++ b/services/vtrace/vtracelib/vtrace.go
@@ -2,7 +2,7 @@
 // Use of this source code is governed by a BSD-style
 // license that can be found in the LICENSE file.
 
-package impl
+package vtracelib
 
 import (
 	"v.io/v23/rpc"
diff --git a/services/mgmt/vtrace/impl/vtrace_test.go b/services/vtrace/vtracelib/vtrace_test.go
similarity index 93%
rename from services/mgmt/vtrace/impl/vtrace_test.go
rename to services/vtrace/vtracelib/vtrace_test.go
index 1134981..d509993 100644
--- a/services/mgmt/vtrace/impl/vtrace_test.go
+++ b/services/vtrace/vtracelib/vtrace_test.go
@@ -2,7 +2,7 @@
 // Use of this source code is governed by a BSD-style
 // license that can be found in the LICENSE file.
 
-package impl_test
+package vtracelib_test
 
 import (
 	"io"
@@ -13,7 +13,7 @@
 	"v.io/v23/vtrace"
 
 	_ "v.io/x/ref/profiles"
-	"v.io/x/ref/services/mgmt/vtrace/impl"
+	"v.io/x/ref/services/vtrace/vtracelib"
 	"v.io/x/ref/test"
 )
 
@@ -31,7 +31,7 @@
 	if err != nil {
 		t.Fatalf("Listen failed: %s", err)
 	}
-	if err := server.Serve("", impl.NewVtraceService(), nil); err != nil {
+	if err := server.Serve("", vtracelib.NewVtraceService(), nil); err != nil {
 		t.Fatalf("Serve failed: %s", err)
 	}