diff --git a/LICENSE b/LICENSE
new file mode 100644
--- /dev/null
+++ b/LICENSE
@@ -0,0 +1,7 @@
+Copyright (c) 2012 Alexey Kotlyarov
+
+Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
+
+The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
+
+THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
diff --git a/Setup.hs b/Setup.hs
new file mode 100644
--- /dev/null
+++ b/Setup.hs
@@ -0,0 +1,2 @@
+import Distribution.Simple
+main = defaultMain
diff --git a/labyrinth.cabal b/labyrinth.cabal
new file mode 100644
--- /dev/null
+++ b/labyrinth.cabal
@@ -0,0 +1,37 @@
+name:                labyrinth
+version:             0.1.0.0
+synopsis:            A complicated turn-based game
+description:         Players take turns in a labyrinth, competing with each
+                     other to pick a treasure and carry it out. They only know
+                     everyone's moves and responses, but do not see the map and
+                     must deduce it themselves.
+homepage:            https://github.com/koterpillar/labyrinth
+license:             MIT
+license-file:        LICENSE
+author:              Alexey Kotlyarov
+maintainer:          koterpillar@gmail.com
+-- copyright:           
+category:            Game
+build-type:          Simple
+cabal-version:       >=1.8
+
+source-repository head
+  type:                git
+  location:            git://github.com/koterpillar/labyrinth.git
+
+flag static
+  description:         Link the binary statically
+  default:             False
+
+executable labyrinth-server
+  main-is:             LabyrinthServer.hs
+  build-depends:       base ==4.5.*, mtl ==2.1.*, template-haskell ==2.7.*, acid-state ==0.8.*, happstack-server ==7.1.*, derive ==2.5.*, safecopy ==0.8.*, parsec ==3.1.*, containers ==0.4.*, random ==1.0.*, text ==0.11.*, transformers ==0.3.*, MonadRandom ==0.1.*
+  hs-source-dirs:      src
+  if (flag(static))
+    ghc-options:       -static -optl-pthread -optl-static
+
+Test-Suite tests
+  type:                exitcode-stdio-1.0
+  main-is:             Main.hs
+  build-depends:       base ==4.5.*, mtl ==2.1.*, template-haskell ==2.7.*, acid-state ==0.8.*, happstack-server ==7.1.*, derive ==2.5.*, safecopy ==0.8.*, parsec ==3.1.*, containers ==0.4.*, random ==1.0.*, text ==0.11.*, transformers ==0.3.*, MonadRandom ==0.1.*, HTF ==0.10.*, HUnit ==1.2.*
+  hs-source-dirs:      src, testsuite
diff --git a/src/LabyrinthServer.hs b/src/LabyrinthServer.hs
new file mode 100644
--- /dev/null
+++ b/src/LabyrinthServer.hs
@@ -0,0 +1,111 @@
+module Main where
+
+import Control.Exception (bracket)
+import Control.Monad
+import Control.Monad.IO.Class
+
+import Data.Acid (AcidState, openLocalState)
+import Data.Acid.Advanced (query', update')
+import Data.Acid.Local (createCheckpointAndClose)
+import Data.List
+import qualified Data.Map as M
+import Data.Maybe
+import qualified Data.Text as T
+
+import Happstack.Server hiding (result)
+
+import Peeker
+
+import System.Environment
+import System.Random
+
+import Labyrinth hiding (performMove)
+
+import LabyrinthServer.Data
+
+createLabyrinth :: (MonadIO m) => Int -> m Labyrinth
+createLabyrinth n = do
+    gen <- liftIO getStdGen
+    let (l, gen') = generateLabyrinth 5 6 n gen
+    liftIO $ setStdGen gen'
+    return l
+
+newId :: (MonadIO m) => m String
+newId = sequence $ take 32 $ repeat $ liftIO $ randomRIO ('a', 'z')
+
+getPort :: IO Int
+getPort = do
+    env <- getEnvironment
+    let envMap = M.fromList env
+    let port = M.lookup "PORT" envMap
+    let port' = fromMaybe "8000" port
+    return $ read port'
+
+main :: IO ()
+main = do
+    port <- getPort
+    let conf = nullConf { port = port }
+    bracket (openLocalState noGames)
+        (createCheckpointAndClose)
+        (simpleHTTP conf . myApp)
+
+myApp :: AcidState Games -> ServerPart Response
+myApp acid = msum (map ($ acid) actions) `mplus` fileServing
+    where actions = [ createGame
+                    , listGames
+                    ]
+                    ++ map gameAction gameActions
+          gameActions = [ makeMove
+                        , showLog
+                        , cheat
+                        ]
+
+bodyPolicy = defaultBodyPolicy "/tmp/" 0 1000 1000
+
+gameAction :: (AcidState Games -> GameId -> ServerPart Response) -> AcidState Games -> ServerPart Response
+gameAction act acid = path $ act acid
+
+fileServing :: ServerPart Response
+fileServing = serveDirectory DisableBrowsing ["index.html"] "public"
+
+createGame :: AcidState Games -> ServerPart Response
+createGame acid = dir "add" $ nullDir >> method POST >> do
+    nullDir
+    decodeBody bodyPolicy
+    pCount <- lookRead "players"
+    gameId <- newId
+    lab <- createLabyrinth pCount
+    res <- update' acid $ AddGame gameId lab
+    if res
+        then ok $ toResponse "ok"
+        else ok $ toResponse "bad game"
+
+listGames :: AcidState Games -> ServerPart Response
+listGames acid = dir "list" $ nullDir >> do
+    games <- query' acid $ GameList
+    ok $ toResponse $ intercalate ", " $ games
+
+cheat :: AcidState Games -> GameId -> ServerPart Response
+cheat acid gameId = dir "cheat" $ nullDir >> do
+    l <- query' acid $ ShowLabyrinth gameId
+    ok $ toResponse $ show l
+
+showLog :: AcidState Games -> GameId -> ServerPart Response
+showLog acid gameId = dir "log" $ nullDir >> do
+    l <- query' acid $ GameLog gameId
+    let str = intercalate "\n" $ map showMove l
+    ok $ toResponse str
+    where showMove m = "player " ++ show (getP rplayer m)
+                    ++ ": " ++ show (getP rmove m)
+                    ++ "\n" ++ show (getP rresult m)
+
+makeMove :: AcidState Games -> GameId -> ServerPart Response
+makeMove acid gameId = dir "move" $ nullDir >> method POST >> do
+    decodeBody bodyPolicy
+    moveStr <- look "move"
+    playerId <- lookRead "player"
+    case parseMove moveStr of
+        Left err   -> ok $ toResponse err
+        Right move -> do
+            res <- update' acid $ PerformMove gameId playerId move
+            ok $ toResponse $ show res
diff --git a/testsuite/Main.hs b/testsuite/Main.hs
new file mode 100644
--- /dev/null
+++ b/testsuite/Main.hs
@@ -0,0 +1,15 @@
+{-# OPTIONS_GHC -F -pgmF htfpp #-}
+
+import Test.Framework
+
+import {-@ HTF_TESTS @-} TestLabyrinth
+import {-@ HTF_TESTS @-} TestLabyrinth.Generate
+import {-@ HTF_TESTS @-} TestLabyrinth.Move.ChoosePosition
+import {-@ HTF_TESTS @-} TestLabyrinth.Move.Grenade
+import {-@ HTF_TESTS @-} TestLabyrinth.Move.Movement
+import {-@ HTF_TESTS @-} TestLabyrinth.Move.Shoot
+import {-@ HTF_TESTS @-} TestLabyrinth.ShowLabyrinth
+import {-@ HTF_TESTS @-} TestLabyrinth.ShowMove
+import {-@ HTF_TESTS @-} TestPeeker
+
+main = htfMain htf_importedTests
